Timed Menu Port

Do you have a question on how to do something.
Ask in here.
Post Reply
tyson_mitchell_88
Posts: 80
Joined: Thu Nov 05, 2015 2:45 pm
Location: Australia

Timed Menu Port

Post 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);
    } 
}
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Timed Menu Port

Post 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.
tyson_mitchell_88
Posts: 80
Joined: Thu Nov 05, 2015 2:45 pm
Location: Australia

Re: Timed Menu Port

Post by tyson_mitchell_88 »

Beautiful thanks Lee. I was close :). Appreciate the help
Image
tyson_mitchell_88
Posts: 80
Joined: Thu Nov 05, 2015 2:45 pm
Location: Australia

Re: Timed Menu Port

Post 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);
     
}
Image
tyson_mitchell_88
Posts: 80
Joined: Thu Nov 05, 2015 2:45 pm
Location: Australia

Re: Timed Menu Port

Post 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);   
}
Image
tyson_mitchell_88
Posts: 80
Joined: Thu Nov 05, 2015 2:45 pm
Location: Australia

Re: Timed Menu Port

Post 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?
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Timed Menu Port

Post by lnevo »

We have to add a line in the Menu Entry if the relay is on what to do.
tyson_mitchell_88
Posts: 80
Joined: Thu Nov 05, 2015 2:45 pm
Location: Australia

Re: Timed Menu Port

Post by tyson_mitchell_88 »

Is it possible to have more then 9 menu entries? Or a sub menu?
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Timed Menu Port

Post by rimai »

Only if you create your own code.
Roberto.
tyson_mitchell_88
Posts: 80
Joined: Thu Nov 05, 2015 2:45 pm
Location: Australia

Re: Timed Menu Port

Post by tyson_mitchell_88 »

I wouldn't no where to start, might not be worth the hassle. Thanks guys
Image
Post Reply