public SysFsDigitalOutputDevice(SysFsDeviceFactory deviceFactory, String key, PinInfo pinInfo, boolean initialValue) { super(key, deviceFactory); this.deviceFactory = deviceFactory; this.gpio = pinInfo.getSysFsNumber(); deviceFactory.export(pinInfo.getSysFsNumber(), DeviceMode.DIGITAL_OUTPUT); Path gpio_dir = deviceFactory.getGpioDirectoryPath(gpio); // TODO Set active_low value to 0 try { valueFile = new RandomAccessFile(gpio_dir.resolve(VALUE_FILE).toFile(), "rw"); } catch (IOException e) { throw new RuntimeIOException("Error opening value file for GPIO " + gpio, e); } setValue(initialValue); }
public SysFsDigitalInputOutputDevice(SysFsDeviceFactory deviceFactory, String key, PinInfo pinInfo, DeviceMode mode) { super(key, deviceFactory); this.deviceFactory = deviceFactory; this.gpio = pinInfo.getSysFsNumber(); Path gpio_dir = deviceFactory.getGpioDirectoryPath(gpio); setMode(mode); valuePath = gpio_dir.resolve(VALUE_FILE); try { valueFile = new RandomAccessFile(valuePath.toFile(), "rw"); } catch (IOException e) { throw new RuntimeIOException("Error opening value file '" + valuePath + "' for GPIO " + gpio, e); } }
public SysFsDigitalInputDevice(SysFsDeviceFactory deviceFactory, String key, PinInfo pinInfo, GpioEventTrigger trigger) { super(key, deviceFactory); this.deviceFactory = deviceFactory; this.gpio = pinInfo.getSysFsNumber(); deviceFactory.export(pinInfo.getSysFsNumber(), DeviceMode.DIGITAL_INPUT); Path gpio_dir = deviceFactory.getGpioDirectoryPath(gpio); try (FileWriter writer = new FileWriter(gpio_dir.resolve(EDGE_FILE).toFile())) { writer.write(trigger.name().toLowerCase()); } catch (IOException e) { Logger.warn(e, "Error writing to edge file for GPIO {}: {}", Integer.valueOf(gpio), e); } // Note: Not possible to set pull-up/down resistor configuration via /sys/class/gpio valuePath = gpio_dir.resolve(VALUE_FILE); try { valueFile = new RandomAccessFile(valuePath.toFile(), "r"); } catch (IOException e) { throw new RuntimeIOException("Error opening value file for GPIO " + gpio, e); } }