当前位置: 首页>>代码示例>>Java>>正文


Java GpioUtil.enableNonPrivilegedAccess方法代码示例

本文整理汇总了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();
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:13,代码来源:MCP23017Binding.java

示例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");
    }
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:75,代码来源:NonPrivilegedGpioExample.java

示例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();
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:7,代码来源:MCP3424Binding.java


注:本文中的com.pi4j.wiringpi.GpioUtil.enableNonPrivilegedAccess方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。