本文整理汇总了Java中com.pi4j.wiringpi.GpioUtil.isExported方法的典型用法代码示例。如果您正苦于以下问题:Java GpioUtil.isExported方法的具体用法?Java GpioUtil.isExported怎么用?Java GpioUtil.isExported使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.pi4j.wiringpi.GpioUtil
的用法示例。
在下文中一共展示了GpioUtil.isExported方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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;
}
}
示例3: 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);
}