Skip to content

Conversation

@nkaminski
Copy link

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

@peternewman peternewman self-assigned this Nov 5, 2019
@peternewman peternewman added this to the 0.11.0 milestone Nov 5, 2019
Copy link
Member

@peternewman peternewman left a 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.

@nkaminski
Copy link
Author

Thanks for the feedback, will refactor as requested and retest.

@peternewman
Copy link
Member

Thanks for the feedback, will refactor as requested and retest.

Hi @nkaminski ,

Did you get a chance to look at finishing this off thanks?

@nkaminski
Copy link
Author

nkaminski commented Jan 21, 2020 via email

@nkaminski nkaminski force-pushed the invertedlogic branch 3 times, most recently from 90a3150 to 196d8dc Compare January 28, 2020 05:10
@nkaminski
Copy link
Author

Requested changes implemented, will rebuild and retest tomorrow or Wednesday.

@peternewman
Copy link
Member

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:
#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?

@peternewman
Copy link
Member

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?

@peternewman peternewman assigned nkaminski and unassigned peternewman Apr 14, 2021
@nkaminski
Copy link
Author

nkaminski commented Apr 14, 2021 via email

@peternewman
Copy link
Member

peternewman commented Apr 15, 2021

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.

Awesome thanks @nkaminski , although no problem if you want to wait until your next spooktacular! 👻

@nkaminski nkaminski force-pushed the invertedlogic branch 2 times, most recently from 196d8dc to b59c4f2 Compare June 12, 2021 00:22
Copy link
Member

@peternewman peternewman left a 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

@nkaminski
Copy link
Author

nkaminski commented Jun 14, 2021 via email

@peternewman
Copy link
Member

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;

Brilliant, thanks for this.

therefore please consider this a work in progress at the moment.

Okay, noted. Looking forward to more good news at some point.

@nkaminski
Copy link
Author

nkaminski commented Oct 27, 2021

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.

Awesome thanks @nkaminski , although no problem if you want to wait until your next spooktacular! 👻

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 ?

@nkaminski
Copy link
Author

Rebased onto latest master as a result of test failures in unrelated plugins.

@nkaminski
Copy link
Author

@peternewman Ready for another review as well.

Copy link
Member

@peternewman peternewman left a 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;
Copy link
Member

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;
Copy link
Member

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.

Comment on lines +142 to +144
bool inverted = (find(m_options.gpio_inverted_pins.begin(),
m_options.gpio_inverted_pins.end(),
(*iter)) != m_options.gpio_inverted_pins.end());
Copy link
Member

Choose a reason for hiding this comment

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

<< " 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"
Copy link
Member

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()) {
Copy link
Member

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:

Suggested change
if (find(pin_list.begin(), pin_list.end(), (*iter)) == pin_list.end()) {
if (!STLContains(options.gpio_pins, pin)) {

@peternewman
Copy link
Member

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 ?

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:
https://en.cppreference.com/w/cpp/language/pimpl

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants