Skip to content

Better way to create objects #219

Answered by savageautomate
Brosbud asked this question in Q&A
Discussion options

You must be logged in to vote

@Brosbud

One of the Pi4J V2 goals was to have default providers based on the current "platform". However, this is not currently implemented. This would avoid having to explicitly specify which provider to use and could result in GPIO instance creation as simple as:

        var pin0 = pi4j.dout().create(0);
        var pin1 = pi4j.dout().create(1);
        var pin2 = pi4j.dout().create(2);
        var pin3 = pi4j.dout().create(3);

We are working on this "default" behaviour now.

Another option is to reuse the config object that you create overriding the 'address' (and 'id' if used) for each I/O instance:

        var config = DigitalOutput.newConfigBuilder(pi4j)
                .provider("…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@Brosbud
Comment options

Answer selected by savageautomate
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants