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

Can a flag be added to define the polarity of a digital output? #93

Closed
FDelporte opened this issue Apr 22, 2021 · 1 comment · Fixed by #146
Closed

Can a flag be added to define the polarity of a digital output? #93

FDelporte opened this issue Apr 22, 2021 · 1 comment · Fixed by #146
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@FDelporte
Copy link
Member

FDelporte commented Apr 22, 2021

In a project where a relay is used, the digital output must be used "inverted" to control the relay because "LOW" sets the relay and "HIGH" resets it. This results in this code:

image

Maybe it could be an idea to extend DigitalOutput in the library with an isInverted flag. But this would also mean all output methods have to take this flag into account.

@FDelporte FDelporte added the enhancement New feature or request label Apr 22, 2021
@FDelporte FDelporte changed the title Can a flag be added to define the polarity of a digital output Can a flag be added to define the polarity of a digital output? Apr 22, 2021
@savageautomate
Copy link
Member

savageautomate commented Oct 21, 2021

Yes, we really should add support for this. We added the methods on() and off() for convenience but in many cases on and off don't track with hi and low states.

In fact it looks like we have a comment in the source to revisit the on and off implementation.
https://github.com/Pi4J/pi4j-v2/search?q=%2F%2F+TODO+%3A%3A+REVISIT+STATE+VS+ON%2FOFF

If do think some form of inverted state configuration should be allowed that only applies to the on(), isOn(), off() and isOff() methods. The high and low states should always be explicit and concrete in meaning but on and off can be relative to the specific hardware implementation.

@FDelporte FDelporte self-assigned this Oct 21, 2021
@savageautomate savageautomate self-assigned this Oct 26, 2021
@savageautomate savageautomate added this to the v2.2 milestone Oct 26, 2021
@savageautomate savageautomate linked a pull request Oct 26, 2021 that will close this issue
FDelporte added a commit that referenced this issue Oct 31, 2021
Adding support for configurable ON/OFF states
MEBoo pushed a commit to MEBoo/pi4j-v2-issue26 that referenced this issue Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants