Display Wavemaker status on Main screen

Do you have a question on how to do something.
Ask in here.
Post Reply
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Display Wavemaker status on Main screen

Post by jsclownfish »

Hi,

It seems I'm having no end of fun with this controller. I find myself thinking of new things it could do all the time. Too bad I don't have an ounce of programming skills to back it up, but I'm trying. ;)
I started a custom main to do a couple simple things. First the colors of the data change from black to orange and then red if the data exceeds my targets for temp and pH. The second was to show the wavemakers on the main screen. I don't really understand the ReefAngel.Relay function and bit managment. Could someone help me to query whether port5 or port 6 is on so I can change the text with that status? (At some point it would be nice to show the actual timer as well. ) Here is the draft code and a picture of the screen.

Code: Select all

void DrawCustomMain()
{
// the graph is drawn/updated when we exit the main menu &
// when the parameters are saved
ReefAngel.LCD.DrawDate(6, 2);
ReefAngel.LCD.Clear(COLOR_BLACK, 1, 11, 132, 11);
pingSerial();
// Display the T1 temperature at 5,5
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,5,13,"TK:");
  if (ReefAngel.Params.Temp1>830) ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp1, COLOR_RED, 23, 13, 10); 
  else if (ReefAngel.Params.Temp1>810) ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp1, COLOR_ORANGE, 23, 13, 10); 
  else ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp1, COLOR_BLACK, 23, 13, 10);
// Display the T2 temperature at 5,5
ReefAngel.LCD.DrawText(T2TempColor,DefaultBGColor,5,23,"RM:");
ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp2, COLOR_BLACK, 23, 23, 10);
// Display the T3 temperature at 5,5
ReefAngel.LCD.DrawText(T3TempColor,DefaultBGColor,5,33,"SP:");
ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp3, COLOR_BLACK, 23, 33, 10);
// Display the PH at 20,5
ReefAngel.LCD.DrawText(PHColor,DefaultBGColor, 64, 13,"PH:");
   if (ReefAngel.Params.PH>8.3 || ReefAngel.Params.PH<8.0) ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.PH, COLOR_ORANGE, 82, 13, 100);
  else if (ReefAngel.Params.PH>8.4 || ReefAngel.Params.PH<7.9) ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.PH, COLOR_RED, 82, 13, 100);  
  else ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.PH, COLOR_BLACK, 82, 13, 100);
// Display the Actinic PWM channel at 30,5 used for Moonlight
ReefAngel.LCD.DrawText(DPColor,DefaultBGColor, 64, 23,"MN:");
ReefAngel.LCD.DrawText(DPColor,DefaultBGColor, 90, 23,"%");
ReefAngel.LCD.DrawSingleMonitor(ReefAngel.PWM.GetActinicValue(), COLOR_BLACK, 82, 23, 1);
//Arrows for Wavemaker
ReefAngel.LCD.DrawText(DPColor,DefaultBGColor, 64, 33,"WV:");
//  if (ReefAngel.Relay  xxxx) ReefAngel.LCD.DrawText(APColor,DefaultBGColor, 82, 33,"-->"); //port 5 on
//  else if (ReefAngel.Relay  xxxx) ReefAngel.LCD.DrawText(APColor,DefaultBGColor, 78, 33,"<--");  //port 6 on
//  else (ReefAngel.Relay  xxxx) ReefAngel.LCD.DrawText(APColor,DefaultBGColor, 78, 33," O "); //port5 and port 6 off, wavemaker delay
pingSerial();
byte TempRelay = ReefAngel.Relay.RelayData;
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
ReefAngel.LCD.DrawOutletBox(12, 43, TempRelay);
}
void DrawCustomGraph()
{
ReefAngel.LCD.DrawGraph(1, 75);
}
You do not have the required permissions to view the files attached to this post.
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Display Wavemaker status on Main screen

Post by binder »

Your PH will not work properly. PH is stored like the temperature, in a large value without any decimal points. So your code:

Code: Select all

// Display the PH at 20,5
ReefAngel.LCD.DrawText(PHColor,DefaultBGColor, 64, 13,"PH:");
   if (ReefAngel.Params.PH>8.3 || ReefAngel.Params.PH<8.0) ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.PH, COLOR_ORANGE, 82, 13, 100);
  else if (ReefAngel.Params.PH>8.4 || ReefAngel.Params.PH<7.9) ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.PH, COLOR_RED, 82, 13, 100);  
  else ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.PH, COLOR_BLACK, 82, 13, 100);
Will not work properly. In order for it to display the way you want, you must change the comparison values to be the whole number (8.30 is 830, 7.90 is 790, and so forth). Next, your logic will not work properly (I'm only looking at PH right now). Let's say that your PH is 7.80. The IF block will read the first expression and evaluate to true since 780 is less than 800. It will not evaluate the ELSE IF because the first condition is true. So you must reorder the IF checks for it to work properly. Start with the larger range checking first. If the value does not meet that criteria, then move to the smaller range next. Finally, if the smaller range doesn't fit, you move to the last condition.

Code: Select all

// Display the PH at 20,5
ReefAngel.LCD.DrawText(PHColor,DefaultBGColor, 64, 13,"PH:");
  if (ReefAngel.Params.PH>840 || ReefAngel.Params.PH<790) ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.PH, COLOR_RED, 82, 13, 100);
  else if (ReefAngel.Params.PH>830 || ReefAngel.Params.PH<800) ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.PH, COLOR_ORANGE, 82, 13, 100);
  else ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.PH, COLOR_BLACK, 82, 13, 100);
From the above code, it appears that you want the following:
PH Text
  • RED if PH above 8.40 or below 7.90
  • ORANGE if PH between 8.31 and 8.40 OR between 7.90 and 7.99
  • BLACK if PH between 8.00 and 8.30
That should get the PH working properly. I haven't looked at the others though.

Now, for the determination if Port5 or Port6 is on. You must use bitread to determine if the bit is set (value equals 1) or not set (value equals 0). Here is a way to check that:

Code: Select all

if (bitRead(ReefAngel.Relay.RelayData,Relay5)==1)
  // port 5 ON, do something here
else
  // port 5 OFF, do something here

if (bitRead(ReefAngel.Relay.RelayData,Relay6)==1)
  // port 6 ON, do something here
else
  // port 6 OFF, do something here
And that's all it takes. So you would add that code to your drawcustommain function to update the display accordingly for if port 5 is on/off and port 6 is on/off. That's the same concept that is used for displaying the outlet box (just coded in a slightly different way).

curt
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Display Wavemaker status on Main screen

Post by jsclownfish »

Thanks for the help! Do I have to define Relay5 and Relay6? I get an error:

Custom_Main6_Example.cpp: In function 'void DrawCustomMain()':
Custom_Main6_Example:50: error: 'Relay5' was not declared in this scope
Custom_Main6_Example:51: error: 'Relay6' was not declared in this scope

-Jon
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Display Wavemaker status on Main screen

Post by rimai »

Use Port5 or Port6 instead. They are already defined and will do the same thing
Roberto.
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Display Wavemaker status on Main screen

Post by binder »

oops. i goofed on the port names. good catch.

curt
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Display Wavemaker status on Main screen

Post by jsclownfish »

Thanks! I got it working pretty OK when it is just right or left side alternating, but for some reason I can't get it to work with a bit of logic for when neither powerhead is on (for the delays at night). Is there something in the logic of bitReads that this doesn't work? You'll also notice I added a piece that shows the timing of each 'wave' step which is handy.

Code: Select all

// Display arrows for Wavemaker
ReefAngel.LCD.DrawText(DPColor,DefaultBGColor, 64, 33,"WV:");
  if (bitRead(ReefAngel.Relay.RelayData,Port5)==1) ReefAngel.LCD.DrawText(APColor,DefaultBGColor, 82, 33,"-->"); //port 5 on
  else if (bitRead(ReefAngel.Relay.RelayData,Port6)==1) ReefAngel.LCD.DrawText(APColor,DefaultBGColor, 82, 33,"<--");  //port 6 on
  else ReefAngel.LCD.DrawText(APColor,DefaultBGColor, 82, 33," O "); //port5 and port 6 off, wavemaker delay
pingSerial();
byte TempRelay = ReefAngel.Relay.RelayData;
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
ReefAngel.LCD.DrawOutletBox(12, 45, TempRelay);
    int t=ReefAngel.Timer[1].Trigger-now();
    if (t>=0)
      ReefAngel.LCD.Clear(255,105,33,135,43);
      ReefAngel.LCD.DrawText(0, DefaultBGColor,105,33,t);
}
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Display Wavemaker status on Main screen

Post by rimai »

Sorry, I missed an important note.
When using bitRead(), you have to subtract the port you are using by 1.
The reason is that computers count from 0 and we start count on 1.
So, to the controller code, the port range is from 0 to 7 and we use from 1 to 8 just to make it easier to read.
Anyway, here is how you have to use your if statement:

Code: Select all

if (bitRead(ReefAngel.Relay.RelayData,Port5-1)==1) 
Let me know if it works.
Roberto.
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Display Wavemaker status on Main screen

Post by binder »

you are catching all of my mistakes. guess i better start reading it more closely. ;-)
Post Reply