本文整理汇总了Java中com.pi4j.wiringpi.GpioUtil.export方法的典型用法代码示例。如果您正苦于以下问题:Java GpioUtil.export方法的具体用法?Java GpioUtil.export怎么用?Java GpioUtil.export使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.pi4j.wiringpi.GpioUtil
的用法示例。
在下文中一共展示了GpioUtil.export方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.pi4j.wiringpi.GpioUtil; //导入方法依赖的package包/类
public static void main(String[] args) throws PlatformAlreadyAssignedException {
// Default platform is Raspberry -> Explicit assign the target platform
// TODO : Use PI4J_PLATFORM env variable ??
PlatformManager.setPlatform(Platform.ODROID);
// PI4J Init
if (Gpio.wiringPiSetup() == -1) {
log.error(" ==>> GPIO SETUP FAILED");
return;
}
// GPIO 1 init as Output
GpioUtil.export(1, GpioUtil.DIRECTION_OUT);
Gpio.pinMode (1, Gpio.OUTPUT) ;
// Force low state for GPIO 1
Gpio.digitalWrite(1, Gpio.LOW);
// Vertx event timer
Vertx.vertx().setPeriodic(1000, l -> {
// Blink led every seconds
if (Gpio.digitalRead(1) != Gpio.LOW) {
log.info("Switch off ...");
Gpio.digitalWrite(1, Gpio.LOW);
}
else {
log.info("Switch on ...");
Gpio.digitalWrite(1, Gpio.HIGH);
}
});
}
示例2: WiringPiDigitalOutputDevice
import com.pi4j.wiringpi.GpioUtil; //导入方法依赖的package包/类
WiringPiDigitalOutputDevice(String key, DeviceFactoryInterface deviceFactory, int gpio, boolean initialValue) throws RuntimeIOException {
super(key, deviceFactory);
this.gpio = gpio;
try {
if (GpioUtil.isExported(gpio)) {
GpioUtil.setDirection(gpio, initialValue ? GpioUtil.DIRECTION_HIGH : GpioUtil.DIRECTION_LOW);
} else {
GpioUtil.export(gpio, initialValue ? GpioUtil.DIRECTION_HIGH : GpioUtil.DIRECTION_LOW);
}
Gpio.pinMode(gpio, Gpio.OUTPUT);
} catch (RuntimeException re) {
throw new RuntimeIOException(re);
}
}
示例3: WiringPiPwmOutputDevice
import com.pi4j.wiringpi.GpioUtil; //导入方法依赖的package包/类
WiringPiPwmOutputDevice(String key, DeviceFactoryInterface deviceFactory, PwmType pwmType,
int range, int gpio, float initialValue) throws RuntimeIOException {
super(key, deviceFactory);
this.pwmType = pwmType;
this.gpio = gpio;
this.value = initialValue;
this.range = range;
switch (pwmType) {
case HARDWARE:
if (GpioUtil.isExported(gpio)) {
GpioUtil.setDirection(gpio, GpioUtil.DIRECTION_OUT);
} else {
GpioUtil.export(gpio, GpioUtil.DIRECTION_OUT);
}
Gpio.pinMode(gpio, Gpio.PWM_OUTPUT);
// Have to call this after setting the pin mode! Yuck
Gpio.pwmSetMode(Gpio.PWM_MODE_MS);
Gpio.pwmWrite(gpio, Math.round(initialValue * range));
break;
case SOFTWARE:
int status = SoftPwm.softPwmCreate(gpio, Math.round(initialValue * range), range);
if (status != 0) {
throw new RuntimeIOException("Error setting up software controlled PWM GPIO on BCM pin " +
gpio + ", status=" + status);
}
break;
}
}
示例4: main
import com.pi4j.wiringpi.GpioUtil; //导入方法依赖的package包/类
public static void main(String[] args) {
if (args.length < 1) {
System.out.println("Usage: " + WiringPiRawPerfTest.class.getName() + " <pin-number> [<iterations>]");
System.exit(1);
}
final int pin = Integer.parseInt(args[0]);
final int iterations = args.length > 1 ? Integer.parseInt(args[1]) : DEFAULT_ITERATIONS;
Gpio.wiringPiSetupGpio();
if (GpioUtil.isExported(pin)) {
GpioUtil.setDirection(pin, GpioUtil.DIRECTION_OUT);
} else {
GpioUtil.export(pin, GpioUtil.DIRECTION_OUT);
}
Gpio.pinMode(pin, Gpio.OUTPUT);
for (int j=0; j<5; j++) {
long start_nano = System.nanoTime();
for (int i=0; i<iterations; i++) {
Gpio.digitalWrite(pin, true);
Gpio.digitalWrite(pin, false);
}
long duration_ns = (System.nanoTime() - start_nano);
System.out.format("Duration for %d iterations: %.4fs%n",
Integer.valueOf(iterations), Float.valueOf(((float)duration_ns) / 1000 / 1000 / 1000));
}
GpioUtil.unexport(pin);
}
示例5: 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);
}
}
示例6: 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);
}
}
示例7: 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);
}
}
示例8: 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);
}
}