mysensors / NodeManager

Plugin for a rapid development of battery-powered sensors
130 stars 82 forks source link

SensorRelay fixes #536

Open nekromant opened 3 years ago

nekromant commented 3 years ago

This MR attempts to fix the problem of relays toggling on/off during initialisation, especially active-low relays. This can be a big problem if a board has some 8 relays toggling some serious loads.

nekromant commented 3 years ago

@user2684 There seems to be some CI problem that's definetely NOT related to this MR

 ls -l --recursive ./examples/RFM69/build/
ls: cannot access './examples/RFM69/build/': No such file or directory
user2684 commented 3 years ago

@nekromant Hi, sorry for reviewing this soooo late! A couple of random comments:

Thanks a lot!

nekromant commented 3 years ago

I see you call setStatus() before initializing the pin with pinMode(). Are you sure this is not creating issues?

Precisely! The spurious relay click happens between the moment we set the pin mode to output, and before we write the actual value to the pin. This way we have a value we want to use in the actual register before we change modes, thus avoiding the glitch. As a side effect, on avr this enables/disables the pull-up, but that should match the desired pin state later on.

As for the rest, I'll fix it ASAP.

user2684 commented 3 years ago

Interesting, thanks, never had the chance to notice it!