Page 1 of 1

Locking ports

Posted: Wed Apr 10, 2013 5:46 am
by lnevo
Inspired by binder's port locking within the android app, I wanted to code something tin the ino to make sure some ports (dosers) don't get overridden by mistake. The problem is I can reset th masks as a last step in the loop, but ShowInterface calls Refresh which gets e wifi data and also does the Relay.write. So there would always be a split second where the port was on. Any thoughts or suggestions?

Re: Locking ports

Posted: Wed Apr 10, 2013 6:11 am
by binder
I think Roberto has a new override feature that will help address this issue, but I am not 100% positive.

Re: Locking ports

Posted: Wed Apr 10, 2013 7:47 am
by rimai
The new override is for PWM signals....
Maybe create an array of ports that are locked?
Just like what we have for FeedingModePorts, WaterChangePorts and others?

Re: Locking ports

Posted: Wed Apr 10, 2013 7:49 am
by lnevo
Yeah, another array is fine. Just want to make sure the masks are cleared for anything that should not get masked :)

Re: Locking ports

Posted: Wed Apr 10, 2013 8:41 am
by rimai
Cool!!!
Send me another pull request.
Just to make sure that this is not going to increase size on the preloaded code, this feature needs to within a define too, just like you did the other one. :)

Locking ports

Posted: Wed Apr 10, 2013 10:39 am
by lnevo
Uhm...not sure how to do the bitwise operations for that...

Re: Locking ports

Posted: Wed Apr 10, 2013 1:54 pm
by binder
lnevo wrote:Uhm...not sure how to do the bitwise operations for that...
Just use the FeedingPorts or WaterChangePorts as examples. It's pretty straight forward.

Locking ports

Posted: Wed Apr 10, 2013 3:42 pm
by lnevo
Ok need a check on my binary math..I have everything in place just need to verify the following..

OverridePorts = B00110010

RelayMaskOff |= OverridePorts;
RelayMaskOn &= ~OverridePorts;

I think that should do it...

Thanks for the review :)

Locking ports

Posted: Wed Apr 10, 2013 4:56 pm
by lnevo
This was my test calculations..

/* put code here
override 00000011
|MaskOff 11110010
result 11110011

~override 11111100
&MaskOn 00011001
result 00011000
*/

Locking ports

Posted: Wed Apr 10, 2013 5:05 pm
by lnevo
Ok the code is ready to go, just need to try and compile it later...

Usage would look like this:

ReefAngel.AddPortOverrides();
ReefAngel.OverridePorts = B00011001; // Ports 1, 4, and 5
ReefAngel.OverridePortsE[0] = Port1bit | Port2Bit;

Now those ports will only work with On(); Off;

Any relay mask applied would be ignore (but still in place...)

Also if you set the variable within the loop() function, you could use a memory flag to enable/disable the lock by changing the variable :)

I'll work on the pull request soon :) and change my ino to use this :)

Re: Locking ports

Posted: Thu Apr 11, 2013 4:36 am
by lnevo
Pull request created.. I hate git.

Re: Locking ports

Posted: Thu Apr 11, 2013 5:40 am
by lnevo
lnevo wrote:Ok need a check on my binary math..I have everything in place just need to verify the following..

OverridePorts = B00110010

RelayMaskOff |= OverridePorts;
RelayMaskOn &= ~OverridePorts;

I think that should do it...

Thanks for the review :)
bump

Re: Locking ports

Posted: Thu Apr 11, 2013 6:13 am
by binder
I see you used "OverridePorts" as the variable name. This to me sounds like the ports that you can override. I'm thinking this is the opposite of what you were intending. The ports you specify are the ones that are Locked and not able to be overridden, correct? Or do I have this backwards?

Re: Locking ports

Posted: Thu Apr 11, 2013 6:35 am
by lnevo
The principle was that if you Override the ports they can not be masked... the override will block the relaymask.

The idea was to override the user input and only allow the programming of the ports via on/off.

Sorry for the confusing naming... the pull request is already put in and the whole process confuses the hell out of me. Feel free to change the names, functions, whatever.

Re: Locking ports

Posted: Thu Apr 11, 2013 7:03 am
by lnevo
How about the math? :)

Re: Locking ports

Posted: Thu Apr 11, 2013 12:31 pm
by binder
lnevo wrote:How about the math? :)
I "think" it looks correct but Roberto should be able to confirm. I always get confused when looking at the relayon/off masks for some reason.

Re: Locking ports

Posted: Thu Apr 11, 2013 1:31 pm
by rimai
Looks good to me.
Have you tested?

Re: Locking ports

Posted: Thu Apr 11, 2013 1:59 pm
by lnevo
Nope :) I can't load my code until I get some additional hardware because I've mode a hundred million changes :) But I put the changes right before the Relay.Write and it all compiles. I'm pretty confident :)

Re: Locking ports

Posted: Mon Apr 29, 2013 4:00 pm
by lnevo
Tested. Working :) Sending you a diff patch because me and git have issues!

Posted: Tue Apr 30, 2013 3:15 pm
by binder
lnevo wrote:Tested. Working :) Sending you a diff patch because me and git have issues!
nice. way to improvise. :mrgreen:

Re: Locking ports

Posted: Tue Apr 30, 2013 3:43 pm
by enigma32
<aside>You're not alone... using git is like having my teeth pulled</aside> ;)