这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on May 17, 2021. It is now read-only.
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions bundles/binding/org.openhab.binding.gpio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,26 @@ _NOTE: These options are optional, in most circumstances you don't have to speci
Allowed item types are `Contact` and `Switch`. Type `Contact` is used for input pins, `Switch` - for output pins. The configuration string is following:

```
gpio="pin:PIN_NUMBER [debounce:DEBOUNCE_INTERVAL] [activelow:yes|no] [force:yes|no]"
gpio="pin:PIN_NUMBER [debounce:DEBOUNCE_INTERVAL] [activelow:yes|no] [force:yes|no] [initialValue:high|low]"
```

Key-value pairs are separated by space; their order isn't important. Character's case is also insignificant. Key-value pair `pin` is mandatory, `debounce` and `activelow` are optional. If omitted `activelow` is set to `no`, `debounce` - to global option in configuration file (`debounce`) or 0 (zero) if neither is specified.
Key-value pairs are separated by space; their order isn't important. Character's case is also insignificant. Key-value pair `pin` is mandatory, `debounce`, `activelow` and `initialValue` are optional. If omitted `activelow` is set to `no`, `debounce` - to global option in configuration file (`debounce`) or 0 (zero) if neither is specified, initialValue is set to LOW.

`PIN_NUMBER` is the number of the GPIO pin as seen by the kernel (not necessarily the same as the physical pin number).

`DEBOUNCE_INTERVAL` is the time interval in milliseconds in which pin interrupts for input pins will be ignored to prevent bounce effect seen mainly on buttons. Note that underlying OS isn't real time nor the application is, so debounce implementation isn't something on which you can rely on 100%, you may need to experiment with this value.

When `activelow` is set to `no` (or omitted) the pins behaves normally: output pins will be set `high` on `ON` command and `low` on `OFF`, input pins will generate `OPEN` event when they are `high` and `CLOSED` when are `low`. However, if `activelow` is set to `yes` the logic is inverted: when `ON` command is sent to output pin it will be set to `low`, on `OFF` command - to `high`. Input pins will generate `OPEN` event when they are `low` and `CLOSED` event on `high`.

`initialValue` is the state of the pin which is set during initialization. It is applicable only for oputput pins (item Switch) and can be HIGH or LOW.

The "force" option can be used to forcefully get hold of the configured pin even if it is currently in use, so it automatically gets unexported and exported again.

Examples:

```
Switch LED "LED" { gpio="pin:1" }
Switch NormallyClosedRelay "Normally Closed Relay" { gpio="pin:2 activelow:yes" }
Switch NormallyClosedRelay "Normally Closed Relay" { gpio="pin:2 activelow:yes initialValue:high" }
Contact NormallyOpenPushButton "Normally Open Push Button" { gpio="pin:3 debounce:10" }
Contact PIR "PIR" { gpio="pin:4 activelow:yes" }
Contact NormallyClosedPushButton "Normally Closed Push Button" { gpio="pin:5 debounce:10 activelow:yes" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
* <p>
* Allowed item types in the configuration are "Switch" and "Contact".
* "Switch" is used for output pins, "Contact" - input pins.
*
* </p>
*
* <p>
* Allowed item configuration string is following:
* </p>
* <p>
* <code>
* gpio="pin:PIN_NUMBER [debounce:DEBOUNCE_INTERVAL] [activelow:yes|no] [force:yes|no]"
* gpio="pin:PIN_NUMBER [debounce:DEBOUNCE_INTERVAL] [activelow:yes|no] [force:yes|no] [initialValue:high|low]"
* </code>
* </p>
* <p>
Expand All @@ -45,11 +46,12 @@
* <br>
* order of pairs isn't important, the same is valid for character's case
* <br>
* key "pin" is mandatory, "debounce", "activelow" and "force" are optional. If omitted
* key "pin" is mandatory, "debounce", "activelow", "force" and "initialValue" are optional. If omitted
* "activelow" is set to "no", "debounce" - to global option in openHAB,
* configuration file (gpio:debounce) or 0 (zero) if neither is specified
* "force" - to global option in openHAB,
* configuration file (gpio:force) or "no" if neither is specified
* "initialValue" - to LOW level
* <br>
* PIN_NUMBER is the number of the pin as seen by the kernel
* <br>
Expand All @@ -68,7 +70,7 @@
* gpio="pin:49"<br>
* gpio="pin:49 debounce:10"<br>
* gpio="pin:49 activelow:yes"<br>
* gpio="pin:49 force:yes"<br>
* gpio="pin:49 force:yes initialValue:high"<br>
* gpio="pin:49 debounce:10 activelow:yes"</code>
* </p>
*
Expand Down Expand Up @@ -176,6 +178,17 @@ public void processBindingConfiguration(String context, Item item, String bindin
throw new BindingConfigParseException("Unsupported value for activelow (" + value
+ ") in configuration string '" + bindingConfig + "'");
}
} else if (key.compareToIgnoreCase("initialValue") == 0) {
if (value.compareToIgnoreCase("high") == 0) {
config.direction = GPIOPin.DIRECTION_OUT_HIGH;
} else if (value.compareToIgnoreCase("low") == 0) {
config.direction = GPIOPin.DIRECTION_OUT_LOW;
} else {
logger.error("Unsupported value for initialValue (" + value + ") in configuration string '"
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to use parameterized logging instead of string concatenation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to make changes with minimal modifications. I just copied logging from other parameters and didn't change the way it is used. If it is necessary I'll do this but then only this modification will be with parameterized logging and will differ from the other places in this class.

+ bindingConfig + "'");
throw new BindingConfigParseException("Unsupported value for initialValue (" + value
+ ") in configuration string '" + bindingConfig + "'");
}
} else {
logger.error("Unsupported key (" + key + ") in configuration string '" + bindingConfig + "'");
throw new BindingConfigParseException(
Expand All @@ -192,9 +205,6 @@ public void processBindingConfiguration(String context, Item item, String bindin

if (item instanceof ContactItem) {
config.direction = GPIOPin.DIRECTION_IN;
} else {
/* Item type 'Switch' */
config.direction = GPIOPin.DIRECTION_OUT;
}

addBindingConfig(item, config);
Expand Down Expand Up @@ -293,6 +303,6 @@ public class GPIOPinBindingConfig implements BindingConfig {
* Pin direction. If item type is <code>Switch</code> the pin
* direction is out, if <code>Contact</code> - in
*/
public int direction;
public int direction = GPIOPin.DIRECTION_OUT_LOW;
}
}