Page 1 of 1
Timed Menu Port
Posted: Thu Mar 03, 2016 4:56 pm
by tyson_mitchell_88
Hi all
I am wondering if it is possible to have a menu option that turned a port off and triggered a timer to turn to port back on.
Using this
Code: Select all
void MenuEntry4()
{
ReefAngel.Relay.Override(DisplayIn, ReefAngel.Relay.Status(DisplayIn)-1);
ReefAngel.DisplayedMenu = RETURN_MAIN_MODE;
And this for timing
Code: Select all
void DisplayOff()
{
static time_t DisplayTime;
if (ReefAngel.Relay.isMaskOff(DisplayIn))
{
DisplayTime=now();
}
if (now()-DisplayTime<30){
ReefAngel.Relay.Off(DisplayIn);
} else {
ReefAngel.Relay.Auto(DisplayIn);
}
}
Re: Timed Menu Port
Posted: Thu Mar 03, 2016 10:10 pm
by lnevo
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.
Re: Timed Menu Port
Posted: Thu Mar 03, 2016 10:41 pm
by tyson_mitchell_88
Beautiful thanks Lee. I was close

. Appreciate the help
Re: Timed Menu Port
Posted: Fri Mar 04, 2016 6:48 pm
by tyson_mitchell_88
Ok I have a small problem, this code is not letting my Feedmode work.
Using the below code DisplayIn will not turn off from the menu.
Code: Select all
void DisplayOff()
{
static time_t DisplayTime;
static time_t FeedModeTime;
if (ReefAngel.DisplayedMenu==FEEDING_MODE && ReefAngel.Relay.isMaskOff(DisplayIn))
FeedModeTime=now();
ReefAngel.Relay.Auto(DisplayIn);
if (now()-FeedModeTime<30){
ReefAngel.Relay.Off(DisplayIn);
} else {
ReefAngel.Relay.On(DisplayIn);
ReefAngel.Relay.Auto(DisplayIn);}
if (ReefAngel.Relay.isMaskOff(DisplayIn))
DisplayTime=now();
ReefAngel.Relay.Auto(DisplayIn);
if (now()-DisplayTime<3600)
ReefAngel.Relay.Off(DisplayIn);
}
Re: Timed Menu Port
Posted: Sat Mar 05, 2016 1:56 am
by tyson_mitchell_88
Seems to be sorted with this
Code: Select all
void DisplayOff()
{
static time_t DisplayTime;
static time_t DisplayFeedModeTime;
if (ReefAngel.Relay.isMaskOff(DisplayIn))
{
ReefAngel.Relay.Auto(DisplayIn);
if (ReefAngel.DisplayedMenu==FEEDING_MODE){
DisplayFeedModeTime=now();
} else {
DisplayTime=now();
}}
if (now()-DisplayFeedModeTime<30)
ReefAngel.Relay.Off(DisplayIn);
if (now()-DisplayTime<45)
ReefAngel.Relay.Off(DisplayIn);
}
Re: Timed Menu Port
Posted: Sat Mar 05, 2016 2:23 am
by tyson_mitchell_88
Are we able to add a function so if the joystick is pressed while in DisplayTime or DisplayFeedModeTime countdown DisplayIn is returned to auto?
Re: Timed Menu Port
Posted: Sat Mar 05, 2016 4:48 pm
by lnevo
We have to add a line in the Menu Entry if the relay is on what to do.
Re: Timed Menu Port
Posted: Sat Mar 05, 2016 5:05 pm
by tyson_mitchell_88
Is it possible to have more then 9 menu entries? Or a sub menu?
Re: Timed Menu Port
Posted: Sat Mar 05, 2016 5:17 pm
by rimai
Only if you create your own code.
Re: Timed Menu Port
Posted: Sat Mar 05, 2016 6:35 pm
by tyson_mitchell_88
I wouldn't no where to start, might not be worth the hassle. Thanks guys