So for having the menu entry toggle the DisplayIn, here's the code I use to toggle my refugium light which I use to light up the cabinet.
Code: Select all
ReefAngel.Relay.Override(Refugium, ReefAngel.Relay.Status(Refugium)+1);
Now you need the +1, because the override works like this 0=off, 1=on, 2=auto
So if the relay is already on it goes to auto which is on
If the relay is already off it goes to on.
So for you, if the relay is on and you do the menu entry it will be Off, but what happens if it gets toggled off again? Then there is a possibility of sending a -1 to ReefAngel.Relay.Set().. which is non-zero which means true which would then turn the port on again. Which then get's complicated because I don't know what else the code is doing...
So how about this :
Code: Select all
ReefAngel.Relay.Override(DisplayIn, ReefAngel.Relay.Status(DisplayIn)==1 ? 0 : 2); // If port is on turn it off else return to auto
Now for your timer code, the issue is that you don't reset your Override meaning, every loop DisplayTime will constantly be set to now() which means it will stay off infinitely. Having it reset here also eliminates the issue with the code above that we just solved too. Meaning we could have left it -1 because we would have detected the MaskOff and if we reset the port it would go back to Auto and we'd trigger our timer. Anyway, we can leave the fix above and do the following to fix the DisplayOff function
Code: Select all
void DisplayOff()
{
static time_t DisplayTime;
if (ReefAngel.Relay.isMaskOff(DisplayIn))
{
DisplayTime=now();
ReefAngel.Relay.Auto(DisplayIn);
}
if (now()-DisplayTime<30){
ReefAngel.Relay.Off(DisplayIn);
}
}
I think the only thing that would have stopped this code working is the Auto function you had and I think it was just misplaced because it needs to get unticked when we first activate the timer. Also make sure that the code that turns DisplayIn on in the first places comes before this function gets called.