[gpio] Added parameter for pull up/down resistor and other improvements (#10782)

This commit is contained in:
Martin Dagarin
2021-06-07 20:57:08 +02:00
committed by GitHub
parent c97f2ac2fa
commit d9841ef0de
5 changed files with 26 additions and 4 deletions

View File

@@ -25,4 +25,10 @@ public class GPIOInputConfiguration extends GPIOConfiguration {
* Time in ms to double check if value hasn't changed
*/
public int debouncingTime = 10;
/**
* Setup a pullup resistor on the GPIO pin
* 0 = PI_PUD_OFF, 1 = PI_PUD_DOWN, 2 = PI_PUD_UP
*/
public int pullupdown = 0;
}

View File

@@ -56,12 +56,14 @@ public class PigpioDigitalInputHandler implements ChannelHandler {
if (gpioId == null) {
throw new NoGpioIdException();
}
gpio = new GPIO(jPigpio, gpioId, 1);
gpio = new GPIO(jPigpio, gpioId, JPigpio.PI_INPUT);
jPigpio.gpioSetAlertFunc(gpio.getPin(), (gpio, level, tick) -> {
lastChanged = new Date();
Date thisChange = new Date();
scheduler.schedule(() -> afterDebounce(thisChange), configuration.debouncingTime, TimeUnit.MILLISECONDS);
});
Integer pullupdown = configuration.pullupdown;
jPigpio.gpioSetPullUpDown(gpio.getPin(), pullupdown);
}
private void afterDebounce(Date thisChange) {

View File

@@ -62,7 +62,7 @@ public class PigpioDigitalOutputHandler implements ChannelHandler {
if (gpioId == null) {
throw new NoGpioIdException();
}
this.gpio = new GPIO(jPigpio, gpioId, 0);
this.gpio = new GPIO(jPigpio, gpioId, JPigpio.PI_OUTPUT);
}
@Override

View File

@@ -50,6 +50,17 @@
<default>10</default>
<advanced>true</advanced>
</parameter>
<parameter name="pullupdown" type="integer" min="0" max="2">
<label>Pull Up/Down Resistor</label>
<description>Configure Pull Up/Down Resistor of GPIO pin</description>
<options>
<option value="0">Off</option>
<option value="1">Pull Down</option>
<option value="2">Pull Up</option>
</options>
<limitToOptions>true</limitToOptions>
<default>0</default>
</parameter>
</config-description>
</channel-type>