Dan-in-CA / SIP

A highly customizable DIY irrigation/sprinkler controller based on Raspberry Pi
357 stars 156 forks source link

No initial reset of shift registers #102

Closed mihugo closed 9 years ago

mihugo commented 9 years ago

I noticed tonight as I was hacking the code to support an old pcduino that I had lying around that there is no initial reset of the shift registers. If the program should crash while the sprinklers are on and the system gets rebooted via watchdog--or whatever--the sprinklers will stay on until the next automatic cycle.

My suggestion is to add one line to ospi.py to do an initial reset of the shift registers at line 20 right after the first import of set_output. I don't know the code all that well so perhaps there is a more obvious place to stick it.

ospi.py
 -    from gpio_pins import set_output
 >   set_output()
Dan-in-CA commented 9 years ago

An excellent suggestion!

There is a bit of a complication however. There is a flag that can be set by a plugin (like the relay_board plugin) when it is loaded that prevents the shift register related GPIO pins from being set up. This allows the plugin to use those pins for other purposes. if we call 'set_output()' before the plugins are loaded it will cause those pins to be set up and prevent the plugin from working properly.

Let me look into it. There should be an easy solution.

Dan-in-CA commented 9 years ago

Hmm... Looks like adding:

if gv.use_gpio_pins:
    set_output()

at line 234 of ospi.py should do it without problems.

mihugo commented 9 years ago

Thanks for the quick response. I had a feeling it was too simple to stick a line of code where I did. I tried to confirm your fix worked tonight but ospy.py only has 204 lines of code in the main branch.

Dan-in-CA commented 9 years ago

Yes, it looks like it was line ~201 for the new code. I tested the update with the relay_board plugin and there were no problems so I updated the file in the repo. Thanks for the input.