What is mean of provider?

30 views
Skip to first unread message

lul...@163.com

unread,
Jul 4, 2016, 9:18:26 AM7/4/16
to Pi4J
I dive into the source code and try to digest it.I find many interface  in com.pi4j.io.gpio package , they define the GpioPin what mothod they can have.and their method was enriched by extends interface by interface . However , who implements their mothod ? the provider?  where is it?

In addition,I saw a comment somewhere said:
"we should ues only one provider object  in pi4j project" .   but why I saw some provison like this
gpioController.provisionPwmOutputPin(provider, pin);

in which condition we need to provide the argument of  Provider?

I just can not understand the concept of Provider.Help me plz    : )

Robert Savage

unread,
Jul 25, 2016, 3:34:13 PM7/25/16
to Pi4J
The Provider interface allows for multiple "board" or "chipsets" to provide GPIO services to the API.  
(Because you may want to access GPIO functionality on an auxiliary expansion board or chipset)

The Pi4J library includes a default provider (https://github.com/Pi4J/pi4j/blob/master/pi4j-core/src/main/java/com/pi4j/io/gpio/GpioFactory.java#L103) which is the Raspberry Pi itself.  So if you are accessing the GPIO pin on the RPI board, then there is no need to include a provider in these API calls.  The provider argument should be optional for most of these methods.

However, if you use an expansion board or chip with the RPi and wish to access it's GPIO you may need to instantiate a custom GPIO provider like in this example:

The Pi4J project includes support for a number of expansion boards/chips or you can implement your own custom Provider if needed.

Thanks, Robert
Reply all
Reply to author
Forward
0 new messages