本文整理汇总了Java中com.pi4j.wiringpi.GpioUtil.setEdgeDetection方法的典型用法代码示例。如果您正苦于以下问题:Java GpioUtil.setEdgeDetection方法的具体用法?Java GpioUtil.setEdgeDetection怎么用?Java GpioUtil.setEdgeDetection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.pi4j.wiringpi.GpioUtil
的用法示例。
在下文中一共展示了GpioUtil.setEdgeDetection方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import com.pi4j.wiringpi.GpioUtil; //导入方法依赖的package包/类
public void test(int gpio) {
GpioFactory.setDefaultProvider(new RaspiGpioProvider(RaspiPinNumberingScheme.BROADCOM_PIN_NUMBERING));
GpioController gpio_controller = GpioFactory.getInstance();
Pin pin = RaspiBcmPin.getPinByAddress(gpio);
GpioPinDigitalInput digitalInputPin = gpio_controller.provisionDigitalInputPin(pin,
"Digital Input for BCM GPIO " + gpio, PinPullResistance.PULL_UP);
GpioUtil.setEdgeDetection(pin.getAddress(), PinEdge.BOTH.getValue());
digitalInputPin.addListener(this);
System.out.println("Waiting 20s for events..., thread name=" + Thread.currentThread().getName());
SleepUtil.sleepSeconds(20);
gpio_controller.unprovisionPin(digitalInputPin);
gpio_controller.shutdown();
}
示例2: main
import com.pi4j.wiringpi.GpioUtil; //导入方法依赖的package包/类
public static void main(String args[]) throws InterruptedException {
int pin;
int dataPtr;
int l, s, d;
System.out.println("<--Pi4J--> GPIO test program");
// setup wiringPi
if (Gpio.wiringPiSetup() == -1) {
System.out.println(" ==>> GPIO SETUP FAILED");
return;
}
// set GPIO 4 as the input trigger
GpioUtil.export(7, GpioUtil.DIRECTION_IN);
GpioUtil.setEdgeDetection(7, GpioUtil.EDGE_BOTH);
Gpio.pinMode (7, Gpio.INPUT) ;
Gpio.pullUpDnControl(7, Gpio.PUD_DOWN);
// set all other GPIO as outputs
for (pin = 0; pin < 7; ++pin) {
// export all the GPIO pins that we will be using
GpioUtil.export(pin, GpioUtil.DIRECTION_OUT);
Gpio.pinMode(pin, Gpio.OUTPUT);
}
dataPtr = 0;
while (true) {
l = data[dataPtr++]; // LED
s = data[dataPtr++]; // State
d = data[dataPtr++]; // Duration (10ths)
if ((l + s + d) == 27) {
dataPtr = 0;
continue;
}
Gpio.digitalWrite(l, s);
if (Gpio.digitalRead(7) == 1) // Pressed as our switch shorts to ground
Gpio.delay(d * 10); // Faster!
else
Gpio.delay(d * 100);
}
}
示例3: main
import com.pi4j.wiringpi.GpioUtil; //导入方法依赖的package包/类
public static void main(String args[]) throws InterruptedException {
System.out.println("<--Pi4J--> GPIO INTERRUPT test program");
// create and add GPIO listener
GpioInterrupt.addListener(new GpioInterruptListener() {
@Override
public void pinStateChange(GpioInterruptEvent event) {
System.out.println("Raspberry Pi PIN [" + event.getPin() +"] is in STATE [" + event.getState() + "]");
if(event.getPin() == 7) {
Gpio.digitalWrite(6, event.getStateValue());
}
if(event.getPin() == 0) {
Gpio.digitalWrite(5, event.getStateValue());
}
}
});
// setup wiring pi
if (Gpio.wiringPiSetup() == -1) {
System.out.println(" ==>> GPIO SETUP FAILED");
return;
}
// export all the GPIO pins that we will be using
GpioUtil.export(0, GpioUtil.DIRECTION_IN);
GpioUtil.export(7, GpioUtil.DIRECTION_IN);
GpioUtil.export(5, GpioUtil.DIRECTION_OUT);
GpioUtil.export(6, GpioUtil.DIRECTION_OUT);
// set the edge state on the pins we will be listening for
GpioUtil.setEdgeDetection(0, GpioUtil.EDGE_BOTH);
GpioUtil.setEdgeDetection(7, GpioUtil.EDGE_BOTH);
// configure GPIO pins 5, 6 as an OUTPUT;
Gpio.pinMode(5, Gpio.OUTPUT);
Gpio.pinMode(6, Gpio.OUTPUT);
// configure GPIO 0 as an INPUT pin; enable it for callbacks
Gpio.pinMode(0, Gpio.INPUT);
Gpio.pullUpDnControl(0, Gpio.PUD_DOWN);
GpioInterrupt.enablePinStateChangeCallback(0);
// configure GPIO 7 as an INPUT pin; enable it for callbacks
Gpio.pinMode(7, Gpio.INPUT);
Gpio.pullUpDnControl(7, Gpio.PUD_DOWN);
GpioInterrupt.enablePinStateChangeCallback(7);
// continuously loop to prevent program from exiting
while (true) {
Thread.sleep(5000);
}
}
示例4: WiringPiDigitalInputDevice
import com.pi4j.wiringpi.GpioUtil; //导入方法依赖的package包/类
public WiringPiDigitalInputDevice(String key, DeviceFactoryInterface deviceFactory, int gpio,
GpioPullUpDown pud, GpioEventTrigger trigger) throws RuntimeIOException {
super(key, deviceFactory);
this.gpio = gpio;
switch (trigger) {
case RISING:
edge = Gpio.INT_EDGE_RISING;
break;
case FALLING:
edge = Gpio.INT_EDGE_FALLING;
break;
case BOTH:
default:
edge = Gpio.INT_EDGE_BOTH;
break;
}
try {
// Note calling this method will automatically export the pin and set the pin direction to INPUT
if (!GpioUtil.setEdgeDetection(gpio, edge)) {
throw new RuntimeIOException("Error setting edge detection (" + edge + ") for pin " + gpio);
}
} catch (RuntimeException re) {
throw new RuntimeIOException(re);
}
int wpi_pud;
switch (pud) {
case PULL_DOWN:
wpi_pud = Gpio.PUD_DOWN;
break;
case PULL_UP:
wpi_pud = Gpio.PUD_UP;
break;
case NONE:
default:
wpi_pud = Gpio.PUD_OFF;
break;
}
Gpio.pullUpDnControl(gpio, wpi_pud);
}
示例5: Pi4jDigitalInputDevice
import com.pi4j.wiringpi.GpioUtil; //导入方法依赖的package包/类
Pi4jDigitalInputDevice(String key, DeviceFactoryInterface deviceFactory, GpioController gpioController,
int gpio, GpioPullUpDown pud, GpioEventTrigger trigger) {
super(key, deviceFactory);
Pin pin = RaspiBcmPin.getPinByAddress(gpio);
if (pin == null) {
throw new IllegalArgumentException("Illegal GPIO number: " + gpio);
}
this.gpio = gpio;
PinPullResistance ppr;
switch (pud) {
case PULL_DOWN:
ppr = PinPullResistance.PULL_DOWN;
break;
case PULL_UP:
ppr = PinPullResistance.PULL_UP;
break;
case NONE:
default:
ppr = PinPullResistance.OFF;
}
/*
PinEdge edge;
switch (trigger) {
case FALLING:
edge = PinEdge.FALLING;
break;
case RISING:
edge = PinEdge.RISING;
break;
case NONE:
edge = PinEdge.NONE;
break;
case BOTH:
default:
edge = PinEdge.BOTH;
break;
}
*/
// Note configuring GPIO event trigger values (rising / falling / both) via the provision APIs isn't possible in Pi4j
digitalInputPin = gpioController.provisionDigitalInputPin(
pin, "Digital Input for BCM GPIO " + gpio, ppr);
// RaspiGpioProvider.export() calls this for all input pins:
if (! GpioUtil.setEdgeDetection(pin.getAddress(), PinEdge.BOTH.getValue())) {
throw new RuntimeIOException("Error setting edge detection");
}
//GpioUtil.setEdgeDetection(pin.getAddress(), edge.getValue());
}
示例6: main
import com.pi4j.wiringpi.GpioUtil; //导入方法依赖的package包/类
public static void main(String args[]) throws InterruptedException {
int pin;
int dataPtr;
int l, s, d;
System.out.println("<--Pi4J--> GPIO test program");
// setup wiringPi
if (Gpio.wiringPiSetup() == -1) {
System.out.println(" ==>> GPIO SETUP FAILED");
return;
}
// set GPIO 4 as the input trigger
GpioUtil.export(7, GpioUtil.DIRECTION_IN);
GpioUtil.setEdgeDetection(7, GpioUtil.EDGE_BOTH);
Gpio.pinMode (7, Gpio.INPUT) ;
Gpio.pullUpDnControl(7, Gpio.PUD_DOWN);
// set all other GPIO as outputs
for (pin = 0; pin < 7; ++pin) {
// export all the GPIO pins that we will be using
GpioUtil.export(pin, GpioUtil.DIRECTION_OUT);
Gpio.pinMode(pin, Gpio.OUTPUT);
}
dataPtr = 0;
for (;;) {
l = data[dataPtr++]; // LED
s = data[dataPtr++]; // State
d = data[dataPtr++]; // Duration (10ths)
if ((l + s + d) == 27) {
dataPtr = 0;
continue;
}
Gpio.digitalWrite(l, s);
if (Gpio.digitalRead(7) == 1) // Pressed as our switch shorts to ground
Gpio.delay(d * 10); // Faster!
else
Gpio.delay(d * 100);
}
}
示例7: main
import com.pi4j.wiringpi.GpioUtil; //导入方法依赖的package包/类
public static void main(String args[]) throws InterruptedException {
System.out.println("<--Pi4J--> GPIO INTERRUPT test program");
// create and add GPIO listener
GpioInterrupt.addListener(new GpioInterruptListener() {
@Override
public void pinStateChange(GpioInterruptEvent event) {
System.out.println("Raspberry Pi PIN [" + event.getPin() +"] is in STATE [" + event.getState() + "]");
if(event.getPin() == 7) {
Gpio.digitalWrite(6, event.getStateValue());
}
if(event.getPin() == 0) {
Gpio.digitalWrite(5, event.getStateValue());
}
}
});
// setup wiring pi
if (Gpio.wiringPiSetup() == -1) {
System.out.println(" ==>> GPIO SETUP FAILED");
return;
}
// export all the GPIO pins that we will be using
GpioUtil.export(0, GpioUtil.DIRECTION_IN);
GpioUtil.export(7, GpioUtil.DIRECTION_IN);
GpioUtil.export(5, GpioUtil.DIRECTION_OUT);
GpioUtil.export(6, GpioUtil.DIRECTION_OUT);
// set the edge state on the pins we will be listening for
GpioUtil.setEdgeDetection(0, GpioUtil.EDGE_BOTH);
GpioUtil.setEdgeDetection(7, GpioUtil.EDGE_BOTH);
// configure GPIO pins 5, 6 as an OUTPUT;
Gpio.pinMode(5, Gpio.OUTPUT);
Gpio.pinMode(6, Gpio.OUTPUT);
// configure GPIO 0 as an INPUT pin; enable it for callbacks
Gpio.pinMode(0, Gpio.INPUT);
Gpio.pullUpDnControl(0, Gpio.PUD_DOWN);
GpioInterrupt.enablePinStateChangeCallback(0);
// configure GPIO 7 as an INPUT pin; enable it for callbacks
Gpio.pinMode(7, Gpio.INPUT);
Gpio.pullUpDnControl(7, Gpio.PUD_DOWN);
GpioInterrupt.enablePinStateChangeCallback(7);
// continuously loop to prevent program from exiting
for (;;) {
Thread.sleep(5000);
}
}