Page 1 of 1

Turn on devices during modes

Posted: Thu Aug 30, 2012 6:53 am
by lnevo
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

Re: Turn on devices during modes

Posted: Thu Aug 30, 2012 7:45 am
by rimai
Try this:

Code: Select all

  if (ReefAngel.DisplayedMenu==WATERCHANGE_MODE) ReefAngel.Relay.On(Port1);

Re: Turn on devices during modes

Posted: Thu Aug 30, 2012 8:30 am
by lnevo
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

Re: Turn on devices during modes

Posted: Thu Aug 30, 2012 8:34 am
by rimai
you can use relay masks to you if you want

Sent from my SPH-D700 using Tapatalk 2

Turn on devices during modes

Posted: Thu Aug 30, 2012 9:46 am
by lnevo
rimai wrote:you can use relay masks to you if you want

Sent from my SPH-D700 using Tapatalk 2
How? :)

Re: Turn on devices during modes

Posted: Thu Aug 30, 2012 10:03 am
by rimai

Code: Select all

if (ReefAngel.DisplayedMenu==WATERCHANGE_MODE) ReefAngel.Relay.RelayMaskOn|=Port1Bit;
Then you need to come up with a logic to revert back the mask on when you are out of feeding mode.
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.

Re: Turn on devices during modes

Posted: Thu Aug 30, 2012 11:03 am
by lnevo
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...

Re: Turn on devices during modes

Posted: Thu Aug 30, 2012 11:08 am
by rimai
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

Re: Turn on devices during modes

Posted: Sun Sep 23, 2012 7:00 am
by lnevo
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.

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;
}

Re: Turn on devices during modes

Posted: Sun Sep 23, 2012 8:19 am
by rimai
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

Turn on devices during modes

Posted: Sun Sep 23, 2012 11:41 am
by lnevo
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

Re: Turn on devices during modes

Posted: Sun Sep 23, 2012 12:22 pm
by rimai
Try this:

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;
}
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.

Turn on devices during modes

Posted: Sun Sep 23, 2012 2:10 pm
by lnevo
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!!

Re: Turn on devices during modes

Posted: Sun Sep 23, 2012 3:10 pm
by lnevo
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;
}