]> git.basschouten.com Git - openhab-addons.git/commitdiff
[gpio] Added parameter for pull up/down resistor and other improvements (#10782)
authorMartin Dagarin <martin.dagarin@gmail.com>
Mon, 7 Jun 2021 18:57:08 +0000 (20:57 +0200)
committerGitHub <noreply@github.com>
Mon, 7 Jun 2021 18:57:08 +0000 (20:57 +0200)
bundles/org.openhab.binding.gpio/README.md
bundles/org.openhab.binding.gpio/src/main/java/org/openhab/binding/gpio/internal/configuration/GPIOInputConfiguration.java
bundles/org.openhab.binding.gpio/src/main/java/org/openhab/binding/gpio/internal/handler/PigpioDigitalInputHandler.java
bundles/org.openhab.binding.gpio/src/main/java/org/openhab/binding/gpio/internal/handler/PigpioDigitalOutputHandler.java
bundles/org.openhab.binding.gpio/src/main/resources/OH-INF/thing/pigpio-remote.xml

index 622cf483582bd92abe3aa4145c17d2444d4405bf..84020f5938c7969369a16a86c5f75bef098edefa 100644 (file)
@@ -34,7 +34,7 @@ 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
@@ -42,6 +42,8 @@ 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
@@ -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
 
@@ -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]
         Type pigpio-digital-output : sample-output-2 [ gpioId=4, invert=true]
 }
 ```
index ef1a91153811cd98ca7195e6d70f8da99ff0602f..4abad17bd41b2b2be2b18623369d4abe54a96a22 100644 (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;
 }
index 06abc8fbabb0aa65c12f2938049b88224554ecfb..dfd8dfa7200f3993c170828b765db36ccbe5b3dc 100644 (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) {
index d0ef7993c35fd01ccad6867328dd3cf6132fd8bb..97c5d3d1e87081fce9d3de79e4577b866e9a9254 100644 (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
index 3dbda62f10642f4b42b590be31621d80bfdef076..402082225c3a16acb0b829800685fb46533f68a4 100644 (file)
                                <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>