Turn on devices during modes
- lnevo
- Posts: 5422
- Joined: Fri Jul 20, 2012 9:42 am
Turn on devices during modes
Ok, I think I've seen this answered before, but couldn't find doing a search...
If I want my refugium light to turn on when I'm doing a water change, what would be the code I'd need...
Currently have this to turn off skimmer and return. But if it's a "toggle" my refugium light may already be on...
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port1Bit | Port2Bit;
Thanks,
Lee
If I want my refugium light to turn on when I'm doing a water change, what would be the code I'd need...
Currently have this to turn off skimmer and return. But if it's a "toggle" my refugium light may already be on...
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port1Bit | Port2Bit;
Thanks,
Lee
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
Re: Turn on devices during modes
Try this:
Code: Select all
if (ReefAngel.DisplayedMenu==WATERCHANGE_MODE) ReefAngel.Relay.On(Port1);
Roberto.
- lnevo
- Posts: 5422
- Joined: Fri Jul 20, 2012 9:42 am
Re: Turn on devices during modes
Cool. Wasn't sure if there was a relaymask or something that would have been cooler. That's pretty straigth forward though 
Hopefully I can get some more work done this weekend, been out for the count this past week...
Thanks,
Lee
Hopefully I can get some more work done this weekend, been out for the count this past week...
Thanks,
Lee
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
Re: Turn on devices during modes
you can use relay masks to you if you want
Sent from my SPH-D700 using Tapatalk 2
Sent from my SPH-D700 using Tapatalk 2
Roberto.
- lnevo
- Posts: 5422
- Joined: Fri Jul 20, 2012 9:42 am
Turn on devices during modes
How?rimai wrote:you can use relay masks to you if you want
Sent from my SPH-D700 using Tapatalk 2
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
Re: Turn on devices during modes
Code: Select all
if (ReefAngel.DisplayedMenu==WATERCHANGE_MODE) ReefAngel.Relay.RelayMaskOn|=Port1Bit;
One thing you could do is to store the last ReefAngel.DisplayedMenu value.
Then if the value has changed from WATERCHANGE_MODE to DEFAULT_MENU, you know the water change mode has terminated and you can remove the mask.
Roberto.
- lnevo
- Posts: 5422
- Joined: Fri Jul 20, 2012 9:42 am
Re: Turn on devices during modes
Nah, if that's the case, I'll stick with the first example...
I thought something interersting could be done with the ReefAngel.WaterChangePorts variable so I wouldn't have to track and revert etc. I guess I'll still need to put some logic in with the first example...unless you have something better...
I thought something interersting could be done with the ReefAngel.WaterChangePorts variable so I wouldn't have to track and revert etc. I guess I'll still need to put some logic in with the first example...unless you have something better...
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
Re: Turn on devices during modes
The first example should work for as it is.
Mask off is different than mask on. They are two different masks.
Sent from my SPH-D700 using Tapatalk 2
Mask off is different than mask on. They are two different masks.
Sent from my SPH-D700 using Tapatalk 2
Roberto.
- lnevo
- Posts: 5422
- Joined: Fri Jul 20, 2012 9:42 am
Re: Turn on devices during modes
Ok, Trying to add a menu item to enable/disable the Refugium light if I don't have my phone handy...having trouble here, the logic for enable/disable is all working, but the mask doesn't seem to be changing right and definitely not following the behavior I would expect after trying a few different methods with adjusting the mask. I guess I just need a little lesson on using the RelayMasks...
here's the current code I'm trying.
here's the current code I'm trying.
Code: Select all
void MenuEntry4()
{
if (rlOverride) {
Serial.println("Disabling rlOverride");
rlOverride=false;
ReefAngel.Relay.RelayMaskOn=saveRelayMaskOn;
ReefAngel.Relay.RelayMaskOff=saveRelayMaskOff;
} else {
Serial.println("Enabling rlOverride");
rlOverride=true;
saveRelayMaskOn=ReefAngel.Relay.RelayMaskOn;
saveRelayMaskOff=ReefAngel.Relay.RelayMaskOff;
Serial.println(saveRelayMaskOn);
Serial.println(saveRelayMaskOff);
if (isNight) {
ReefAngel.Relay.RelayMaskOn&=Port7Bit;
} else {
ReefAngel.Relay.RelayMaskOn|=Port7Bit;
}
Serial.println("After");
Serial.println(saveRelayMaskOn);
Serial.println(saveRelayMaskOff);
}
ReefAngel.DisplayedMenu = RETURN_MAIN_MODE;
}-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
Re: Turn on devices during modes
If you want to override it on, you don't need the RelayMaskOff.
RelayMaskOn is an "OR" mask and appiles to RelayData.
RelayData is the "auto" mode status.
If you set RelayMaskOn=B01000000, which is the port 7 bit, you are turning that port 7 to always on. Clearing that bit makes it go auto mode again.
RelayMaskOff is an "AND" mask and appiles to the result of RelayData OR RelayMaskOn
If you clear RelayMaskOff=B10111111, which is the port 7 bit, you are turning that port 7 to always off. Setting that bit makes it go auto mode again.
The default values for RelayMaskOn is 0 and RelayMaskOff is 255
RelayMaskOn is an "OR" mask and appiles to RelayData.
RelayData is the "auto" mode status.
If you set RelayMaskOn=B01000000, which is the port 7 bit, you are turning that port 7 to always on. Clearing that bit makes it go auto mode again.
RelayMaskOff is an "AND" mask and appiles to the result of RelayData OR RelayMaskOn
If you clear RelayMaskOff=B10111111, which is the port 7 bit, you are turning that port 7 to always off. Setting that bit makes it go auto mode again.
The default values for RelayMaskOn is 0 and RelayMaskOff is 255
Roberto.
- lnevo
- Posts: 5422
- Joined: Fri Jul 20, 2012 9:42 am
Turn on devices during modes
Well i am trying to turn lights on during the day and off during the night, but i want to toggle so i am saving the previous state...the masks don't seem to change when I do the or...or it wasn't applying right. Can you take a peek at the code?
Lee
Lee
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
Re: Turn on devices during modes
Try this:
There is no need to save state.
Like I said, the ReefAngel.Relay.RelayData already keeps the auto mode state.
All you are trying to do is override one port on and the cancelling the override.
The 6 is because the bit count starts at 0, so Port7 is bit #6.
Code: Select all
void MenuEntry4()
{
if (bitRead(ReefAngel.Relay.RelayMaskOn,6)==1
bitClear(ReefAngel.Relay.RelayMaskOn,6)
else
bitSet(ReefAngel.Relay.RelayMaskOn,6)
ReefAngel.DisplayedMenu = RETURN_MAIN_MODE;
}
Like I said, the ReefAngel.Relay.RelayData already keeps the auto mode state.
All you are trying to do is override one port on and the cancelling the override.
The 6 is because the bit count starts at 0, so Port7 is bit #6.
Roberto.
- lnevo
- Posts: 5422
- Joined: Fri Jul 20, 2012 9:42 am
Turn on devices during modes
I was trying to save it in case other things were masked...but setting individual bit like that looks like i can ignore the rest 
I think i still need to use the off mask though so during night mode if i want to turn it off for some reason...
Anyway i will try this out and go from there!
Thanks!!
I think i still need to use the off mask though so during night mode if i want to turn it off for some reason...
Anyway i will try this out and go from there!
Thanks!!
- lnevo
- Posts: 5422
- Joined: Fri Jul 20, 2012 9:42 am
Re: Turn on devices during modes
Great. worked well. Here's the code block that I'm using. I needed this to do the opposite so I did need the RelayMaskOff for during the night if I need the switch menu to override the light when it's already on. Don't know when I'd use that, but it's there for my sanity. Anyway, for those that are looking to do similar, here it is!
Code: Select all
void MenuEntry4()
{
if (isNight) {
if (bitRead(ReefAngel.Relay.RelayMaskOff,6)==1) {
bitClear(ReefAngel.Relay.RelayMaskOff,6);
} else {
bitSet(ReefAngel.Relay.RelayMaskOff,6);
}
} else {
if (bitRead(ReefAngel.Relay.RelayMaskOn,6)==1) {
bitClear(ReefAngel.Relay.RelayMaskOn,6);
} else {
bitSet(ReefAngel.Relay.RelayMaskOn,6);
}
}
ReefAngel.DisplayedMenu = RETURN_MAIN_MODE;
}