The class DeviceFactoryHelper encapsulates the logic for accessing the configured service provider. Interfaces for implementing a new service provider are in the com.diozero.internal.provider package. Developing a new service provider is relatively straightforward given the provided APIs and base classes.
In theory the OpenJDK Device I/O service provider should provide the best platform support, however, the JDK Device I/O library doesn't support PWM.
The device native service provider library is defined in the following order:
- System property com.diozero.devicefactory, e.g.
- Service definition file on the classpath, file:
/META-INF/services/com.diozero.internal.provider.NativeDeviceFactoryInterface. For example the one for pi4j
Currently implemented service providers:
- JDK Device I/O - versions 1.0 and 1.1
- pigpio via my JNI wrapper library
- wiringPi via the Pi4j JNI wrapper classes
See below for provider specific details.
TODO Describe steps for creating a new provider.
JDK Device I/O
This library has device providers for JDK Device I/O v1.0 (in Mercurial master repository) and v1.1 Mercurial (in dev repository). Unfortunately these libraries aren't in Maven repositories; to build the JDK Device I/O v1.0 library on the Raspberry Pi:
sudo apt-get install mercurial mkdir deviceio cd deviceio hg clone http://hg.openjdk.java.net/dio/master cd master export JAVA_HOME=/usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt export PATH=$JAVA_HOME/bin:$PATH export PI_TOOLS=/usr make bundle PI_TOOLS=$PI_TOOLS osgi cp build/deviceio/lib/ext/dio.jar dio-1.0.jar sudo cp build/deviceio/lib/ext/dio.jar $JAVA_HOME/jre/lib/ext/. sudo cp build/deviceio/lib/arm/libdio.so $JAVA_HOME/jre/lib/arm/.
To add Java Device I/O JAR to your local Maven repository (on your development machine) run:
mvn install:install-file -Dfile=dio-1.0.jar -DgroupId=jdk.dio -DartifactId=device-io -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true
Similar instructions should be followed for installing v1.1, the only difference being how it is built:
hg clone http://hg.openjdk.java.net/dio/dev cd dev export JAVA_HOME=/usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt export PATH=$JAVA_HOME/bin:$PATH export PI_TOOLS=/usr make osgi
wiringPi & Pi4j
Make sure you have wiringPi installed (
sudo apt-get update && sudo apt-get install wiringpi). I recommend using the latest Pi4j 1.1 snapshot build.