-
Notifications
You must be signed in to change notification settings - Fork 221
Add support for inverted (active low) logic in GPIO plugin #1587
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
base: master
Are you sure you want to change the base?
Conversation
peternewman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this @nkaminski .
I've got a few comments if you wouldn't mind looking at them please. They're mostly just style things.
|
Thanks for the feedback, will refactor as requested and retest. |
Hi @nkaminski , Did you get a chance to look at finishing this off thanks? |
|
Will aim to do so within the next week or so.On Jan 21, 2020 2:52 AM, Peter Newman <[email protected]> wrote:
Thanks for the feedback, will refactor as requested and retest.
Hi @nkaminski ,
Did you get a chance to look at finishing this off thanks?
—You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub, or unsubscribe.
|
90a3150 to
196d8dc
Compare
|
Requested changes implemented, will rebuild and retest tomorrow or Wednesday. |
Sorry @nkaminski , it looks like I missed your comment. I think this is still outstanding: Other than that, and some lint errors ( https://travis-ci.org/github/OpenLightingProject/ola/jobs/642732720#L1600-L1607 ): This is hopefully good to go if you retested? |
|
Hi @nkaminski , Hope you are well. Are you still interested in spending a tiny bit of time to get this merged? There are just some fairly minor tweaks to be resolved I think:
|
|
Apologies, I just lost sight of this as I tend to use OLA rather seasonally (around Halloween in particular).Will set up another dev env on a Pi4 and test this within the next week or so.On Apr 13, 2021 8:24 PM, Peter Newman ***@***.***> wrote:
Hi @nkaminski ,
Hope you are well. Are you still interested in spending a tiny bit of time to get this merged? There are just some fairly minor tweaks to be resolved I think:
I think this is still outstanding:
#1587 (comment)
Other than that, and some lint errors ( https://travis-ci.org/github/OpenLightingProject/ola/jobs/642732720#L1600-L1607 ):
./plugins/gpio/GPIODriver.cpp:159: Tab found; better to use spaces [whitespace/tab] [1]
./plugins/gpio/GPIODriver.cpp:163: Tab found; better to use spaces [whitespace/tab] [1]
./plugins/gpio/GPIODriver.cpp:163: Extra space after ( [whitespace/parens] [2]
./plugins/gpio/GPIODriver.cpp:163: Extra space before ) [whitespace/parens] [2]
./plugins/gpio/GPIODriver.cpp:166: Tab found; better to use spaces [whitespace/tab] [1]
./plugins/gpio/GPIODriver.cpp:166: Extra space after ( [whitespace/parens] [2]
./plugins/gpio/GPIODriver.cpp:166: Extra space before ) [whitespace/parens] [2]
./plugins/gpio/GPIODriver.cpp:167: Tab found; better to use spaces [whitespace/tab] [1]
This is hopefully good to go if you retested?
—You are receiving this because you were assigned.Reply to this email directly, view it on GitHub, or unsubscribe.
|
Awesome thanks @nkaminski , although no problem if you want to wait until your next spooktacular! 👻 |
196d8dc to
b59c4f2
Compare
peternewman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the suggestion to fix the lint issues
|
Thanks for the suggestions. I just rebased and made sure everything built correctly on a newly configured Pi 4 (which it did) before making changes; therefore please consider this a work in progress at the moment.
|
Brilliant, thanks for this.
Okay, noted. Looking forward to more good news at some point. |
Alright, I went ahead and installed the new OLA package with updated GPIO plugin on my Halloween prop controller with a whole bunch of both standard and inverted logic outputs and caught one functional bug that I addressed in commit 4f54e46 ( 1c23794 post-rebase ) where I was inverting the output twice. After this change, I can confirm both standard and inverted/active low outputs both initialize correctly to the "off" state as well as function correctly at runtime. As a final note, as the upstream Linux Kernel is deprecating the sysfs interface for GPIO, would you be open to a future change to port this driver to use libgpiod and the new GPIO API documented at https://www.kernel.org/doc/html/latest/driver-api/gpio/using-gpio.html ? |
4f54e46 to
0eee34f
Compare
0eee34f to
1c23794
Compare
|
Rebased onto latest master as a result of test failures in unrelated plugins. |
|
@peternewman Ready for another review as well. |
peternewman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few, mostly minor comments @nkaminski .
| /** | ||
| * @brief A list of gpio_pins which use inverted logic. | ||
| */ | ||
| std::vector<uint16_t> gpio_inverted_pins; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make the variable name match the config name please, just to simplify things.
| const string direction("out"); | ||
| const string normal_direction("low"); | ||
| const string inverted_direction("high"); | ||
| const string* direction = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be const as we're changing it.
| bool inverted = (find(m_options.gpio_inverted_pins.begin(), | ||
| m_options.gpio_inverted_pins.end(), | ||
| (*iter)) != m_options.gpio_inverted_pins.end()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you use our STLContains function?
http://docs.openlighting.org/ola/doc/latest/group__stl.html#ga6bc94dfb62cab831bfa2f0fc7e4daa04
| << " with " << (inverted ? "inverted" : "normal") << " logic"; | ||
| if (write(fd, direction->c_str(), direction->size()) < 0) { | ||
| OLA_WARN << "Failed to enable output on " << str.str() | ||
| << " with " << (inverted ? "inverted" : "normal") << " logic" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given this is showing the full path to the pin, perhaps also show the direction string here, rather than the friendly inverted/normal output.
Or turn it on it's head and put that in the DEBUG now we've added it and just make the WARN more user friendly "Failed to enable output on pin n as high/low".
| return false; | ||
| } | ||
|
|
||
| if (find(pin_list.begin(), pin_list.end(), (*iter)) == pin_list.end()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping @nkaminski , still this please...
Also you can use our STLContains again I think:
| if (find(pin_list.begin(), pin_list.end(), (*iter)) == pin_list.end()) { | |
| if (!STLContains(options.gpio_pins, pin)) { |
I feel like I replied to this elsewhere on an issue or something? These two are relevant anyway ( #1385 and #1707 ). In summary though, yes please, but ideally in such a way that it will detect what's available and use libgpiod if present and fall back to other stuff if not. Probably PIMPL style: See our network stuff for an example of this style. Otherwise some ifdef stuff would work too, but might get messier/more complicated for some use cases. |
This changeset adds support for inverted/complimentary logic in the GPIO plugin.
Inverted logic is commonly used with optically isolated relay boards such as https://www.sainsmart.com/products/8-channel-5v-relay-module