Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions bundles/org.openhab.binding.gpio/README.md
Expand Up @@ -34,14 +34,16 @@ sudo nano /etc/systemd/system/pigpiod.service.d/public.conf
```
sudo systemctl daemon-reload
```
Now that Remote GPIO is enabled, get the daemon going:
Now that Remote GPIO is enabled, get the daemon going (even if installed with apt-get):
```
sudo systemctl enable pigpiod
sudo systemctl start pigpiod
```

In openHAB, set `host` to the address of the pi and the `port` to the port of pigpio (default: 8888).

Note: If you are running Pigpio on same host as openHAB, then set host to **::1**.

## Channels

### Pigpio Remote
Expand All @@ -56,6 +58,7 @@ In openHAB, set `host` to the address of the pi and the `port` to the port of pi
Set the number of the pin in `gpioId`.
If you want to invert the value, set `invert` to true.
To prevent incorrect change events, you can adjust the `debouncingTime`.
Using `pullupdown` you can enable pull up or pull down resistor (0 = Off, 1 = Pull Down, 2 = Pull Up).

### GPIO digital output channel

Expand All @@ -78,7 +81,7 @@ Thing gpio:pigpio-remote:sample-pi-1 "Sample-Pi 1" [host="192.168.2.36", port=88
Thing gpio:pigpio-remote:sample-pi-2 "Sample-Pi 2" [host="192.168.2.37", port=8888] {
Channels:
Type pigpio-digital-input : sample-input-3 [ gpioId=16, debouncingTime=20]
Type pigpio-digital-input : sample-input-4 [ gpioId=17, invert=true, debouncingTime=5]
Type pigpio-digital-input : sample-input-4 [ gpioId=17, invert=true, debouncingTime=5, pullupdown=2]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like a very direct way, would it make sense to expose a bit less direct, or not. I'm in doubt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you got any suggestion for improvement ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean like pullupdown=OFF, pullupdown=UP, pullupdown=DOWN? Would be better from the usability perspective, IMHO. But I won't insist on changing it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge it then

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, @SloCompTech feel free to file a follow-up PR if you agree on these thoughts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will do, so I need to change parameter type to string or is there another more suitable type like a constant ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no enum type or so. You need to make it text. See https://www.openhab.org/docs/developer/bindings/config-xml.html#xml-structure-for-configuration-descriptions for the available types.

Type pigpio-digital-output : sample-output-2 [ gpioId=4, invert=true]
}
```
Expand Down
Expand Up @@ -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;
}
Expand Up @@ -56,12 +56,14 @@ public PigpioDigitalInputHandler(GPIOInputConfiguration configuration, JPigpio j
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) {
Expand Down
Expand Up @@ -62,7 +62,7 @@ public PigpioDigitalOutputHandler(GPIOOutputConfiguration configuration, JPigpio
if (gpioId == null) {
throw new NoGpioIdException();
}
this.gpio = new GPIO(jPigpio, gpioId, 0);
this.gpio = new GPIO(jPigpio, gpioId, JPigpio.PI_OUTPUT);
}

@Override
Expand Down
Expand Up @@ -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>

Expand Down