本文整理汇总了Java中com.pi4j.wiringpi.GpioUtil.enableNonPrivilegedAccess方法的典型用法代码示例。如果您正苦于以下问题:Java GpioUtil.enableNonPrivilegedAccess方法的具体用法?Java GpioUtil.enableNonPrivilegedAccess怎么用?Java GpioUtil.enableNonPrivilegedAccess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.pi4j.wiringpi.GpioUtil
的用法示例。
在下文中一共展示了GpioUtil.enableNonPrivilegedAccess方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MCP23017Binding
import com.pi4j.wiringpi.GpioUtil; //导入方法依赖的package包/类
public MCP23017Binding() {
try {
// ask for non privileged access (run without root)
GpioUtil.enableNonPrivilegedAccess();
} catch (UnsatisfiedLinkError e) {
logger.error("MCP23017 Binding needs to be run a Raspberry Pi - deactivating it here.");
gpio = null;
return;
}
// now create a controller
gpio = GpioFactory.getInstance();
}
示例2: main
import com.pi4j.wiringpi.GpioUtil; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
System.out.println("<--Pi4J--> Non-Privileged GPIO Example ... started.");
// we can use this utility method to pre-check to determine if
// privileged access is required on the running system
if(GpioUtil.isPrivilegedAccessRequired()){
System.err.println("*****************************************************************");
System.err.println("Privileged access is required on this system to access GPIO pins!");
System.err.println("*****************************************************************");
return;
}
// ----------------------
// ATTENTION
// ----------------------
// YOU CANNOT USE ANY HARDWARE PWM OR CLOCK FUNCTIONS WHILE ACCESSING NON-PRIVILEGED GPIO.
// THIS METHOD MUST BE INVOKED BEFORE CREATING A GPIO CONTROLLER INSTANCE.
GpioUtil.enableNonPrivilegedAccess();
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// ------------
// OUTPUT PIN
// ------------
// provision gpio pin #01 as an output pin and blink it
final GpioPinDigitalOutput output = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01);
// set shutdown state for the output pin (and un-export the pin)
output.setShutdownOptions(true, PinState.LOW);
// blink output pin every one second
output.blink(1000);
// display info to user
System.out.println("Pin [" + output.getName() + "] should be blinking/toggling every 1 second.");
// ------------
// INPUT PIN
// ------------
// provision gpio pin #02 as an input pin with its internal pull down resistor enabled
final GpioPinDigitalInput input = gpio.provisionDigitalInputPin(RaspiPin.GPIO_02, PinPullResistance.PULL_DOWN);
// set shutdown state for the input pin (and un-export the pin)
input.setShutdownOptions(true);
// create and register gpio pin listener
input.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
// display pin state on console
System.out.println(" --> GPIO PIN STATE CHANGE: " + event.getPin() + " = " + event.getState());
}
});
// display info to user
System.out.println("You can connect pin [" + input.getName() + "] to +3VDC to capture input state changes.");
// ----------------
// WAIT & SHUTDOWN
// ----------------
// sleep for 1 minute, then shutdown
Thread.sleep(60000);
// stop all GPIO activity/threads by shutting down the GPIO controller
// (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks)
gpio.shutdown();
System.out.println("Exiting NonPrivilegedGpioExample");
}
示例3: MCP3424Binding
import com.pi4j.wiringpi.GpioUtil; //导入方法依赖的package包/类
public MCP3424Binding() {
// ask for non privileged access (run without root)
GpioUtil.enableNonPrivilegedAccess();
// now create a controller
gpio = GpioFactory.getInstance();
}