本文整理汇总了Java中com.pi4j.wiringpi.Gpio.wiringPiISR方法的典型用法代码示例。如果您正苦于以下问题:Java Gpio.wiringPiISR方法的具体用法?Java Gpio.wiringPiISR怎么用?Java Gpio.wiringPiISR使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.pi4j.wiringpi.Gpio
的用法示例。
在下文中一共展示了Gpio.wiringPiISR方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public void test(int gpio) {
int status = Gpio.wiringPiSetupGpio();
if (status != 0) {
throw new RuntimeException("Error initialising wiringPi: " + status);
}
Gpio.pinMode(gpio, Gpio.INPUT);
Gpio.pullUpDnControl(gpio, Gpio.PUD_UP);
int delay = 20;
System.out.println("Waiting " + delay + "s for events..., thread name=" + Thread.currentThread().getName());
if (Gpio.wiringPiISR(gpio, Gpio.INT_EDGE_BOTH, this) != 1) {
System.out.println("Error in wiringPiISR");
} else {
System.out.println("Sleeping for " + delay + "s");
SleepUtil.sleepSeconds(delay);
}
GpioUtil.unexport(gpio);
}
示例2: gpioIsrSetup
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
private static void gpioIsrSetup() {
wiringPiSetup();
Gpio.pinMode(btnPin, Gpio.INPUT);
Gpio.pullUpDnControl(btnPin, Gpio.PUD_UP);
Gpio.pinMode(ledPin, Gpio.OUTPUT);
Gpio.pullUpDnControl(ledPin, Gpio.PUD_DOWN);
Gpio.digitalWrite(ledPin, false);
Gpio.wiringPiISR(btnPin, Gpio.INT_EDGE_FALLING, new GpioInterruptCallback() {
private final long debounceTime = 200;
@Override
public void callback(int pin) {
Gpio.delay(10);
long currentTime = System.currentTimeMillis();
if(currentTime > lastTime+debounceTime){
Gpio.digitalWrite(ledPin, Gpio.digitalRead(ledPin)==0?1:0);
logger.debug("GPIO PIN 0 detected. Led state: "+Gpio.digitalRead(ledPin));
}else{
logger.debug("Discard event "+currentTime);
}
lastTime=currentTime;
}
});
}
示例3: enableListener
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
@Override
public void enableListener() {
// TODO Validate that wiringPi actually works this way, i.e. supports separate callbacks for rising and falling
// Note it looks easier to use GpioInterrupt but this will be less efficient
// due to its use of Vectors to support multiple listeners and cloning on every event
Gpio.wiringPiISR(gpio, edge, this);
}
示例4: setup
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
@Override
protected void setup(String[] args) {
wiringPiSetup();
if(Gpio.wiringPiISR(isrPin, Gpio.INT_EDGE_FALLING, new MyISR()) == -1){
logger.error("Setup ISR failed !");
throw new ExceptionInInitializerError("Setup ISR failed !");
}
logger.debug("Infrared receiver sensor ready!");
}
示例5: disableListener
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
@Override
public void disableListener() {
// TODO Is this correct?
Gpio.wiringPiISR(gpio, edge, null);
}