genielabs / HomeGenie

HomeGenie, the programmable automation intelligence
https://homegenie.it
GNU General Public License v3.0
402 stars 157 forks source link

Added feature to invert GPIO #99

Closed gitbjo closed 9 years ago

gitbjo commented 9 years ago

I have to control an 8 Relay Module, but the relay switches to On with a GPIO pin to LOW. The Raspberry Pi GPIO Library supports that, so I made use of it. The Automation can now have an additional syntax !OUT, meaning we want a LOW when On. I hope you agree to take it over in your repository. Thanks, gitbjo.

genemars commented 9 years ago

this code will affect "pullup" "pulldown" resistor modes that is done by adding a "+" or "-" to the end of a OUT/IN value. Did you try configuring as "OUT-" instead of just "OUT" (or "OUT+" not sure which one to use in your case)?

gitbjo commented 9 years ago

Hi Gene,

As per the code and the description, pull-up and pull-down are only used by IN doing IN+ and IN-. For OUT there was nothing, so for sake of clarity, I used the "!OUT" to say NOT OUT (inverted logic). so any IN+ and IN- should not be affected by this change. I tested it with my relay board and it works perfectly as expected. Challenge testing is also done, as after the change, compile & run, to "OUT" config was still active and my relay were switched on. When I changed the config to "!OUT", my relays switched to off, when the switch was off. Switching on and off works now as expected. Best Regards, gitbjo

genemars commented 9 years ago

Right I got confused sorry with IN/OUT =) I will manually add your code since including/replacing a program in HG involves few steps as copying the new generated dll and replace the new files in the homegenie_factory_config.zip as well.

genemars commented 9 years ago

@gitbjo I was going to add your code but I don't see where is the Reversed field used to invert the Status.Level logic. Shouldn't the pinChanged and the WebService Control.On/Off/Toggle use it?

gitbjo commented 9 years ago

Hi, It is done through the GPIO library, no need to have application logic doing this. Configured in line 3127: ((OutputPinConfiguration)configuration[p]).Reversed = pc.Reversed; Is the setting as documented here: PinConfiguration/Revert Best Regards, gitbjo

genemars commented 9 years ago

ok, thanks for clarification. Next commit/update will contain this improvement. Cheers, g.