Flags - will new libraries break something?

Do you have a question on how to do something.
Ask in here.
Post Reply
btorrenga
Posts: 100
Joined: Mon Apr 16, 2012 10:22 pm

Flags - will new libraries break something?

Post by btorrenga »

Hello,

I noticed in the library change log that old flags have been deprecated. I tried to follow the other discussions about flags, but cannot tell if it will affect me at all. I wanted to change some of my ATO code, and noticed the new libraries will be installed when I upload the new code.

Before I try modifying my code, could someone look at its current state and comment whether or not I need to change something concerning flags in order for it to be compatible with the new libraries? Here is my current code:

Code: Select all

/* The following features are enabled for this File: 
#define SALINITYEXPANSION
#define DisplayImages
#define SetupExtras
#define OverheatSetup
#define DateTimeSetup
#define VersionMenu
#define wifi
#define SaveRelayState
#define RelayExp
#define InstalledRelayExpansionModules 1
#define DosingPumpIntervalSetup
#define WDT
#define CUSTOM_MENU
#define CUSTOM_MENU_ENTRIES 9
#define CUSTOM_MAIN
#define COLORS_PDE
#define ENABLE_ATO_LOGGING
#define ENABLE_EXCEED_FLAGS
#define IOEXPANSION
#define FONT_8x8
#define FONT_8x16
#define FONT_12x16
#define NUMBERS_8x8
#define NUMBERS_8x16
#define NUMBERS_12x16
#define NUMBERS_16x16
#define CUSTOM_VARIABLES

*/
//ReefAngel.Params.Salinity
#include <ReefAngel_Features.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_NokiaLCD.h>
#include <RA_ATO.h>
#include <RA_Joystick.h>
#include <LED.h>
#include <RA_TempSensor.h>
#include <Relay.h>
#include <Timer.h>
#include <Memory.h>
#include <IO.h>
#include <ReefAngel.h>
#include <RA_PWM.h>
#include <avr/pgmspace.h>
#include <Salinity.h>
////// Place global variable code below here
// Initialize Buzzer variables
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long buzzerinterval = 1000;           // interval at which to sound buzzer (milliseconds)
long previousMillis = 0;

////// Place global variable code above here


prog_char menu1_label[] PROGMEM = "Feeding";
prog_char menu2_label[] PROGMEM = "Water Change";
prog_char menu3_label[] PROGMEM = "ATO Clear";
prog_char menu4_label[] PROGMEM = "Overheat Clear";
prog_char menu5_label[] PROGMEM = "PH Calibration";
prog_char menu6_label[] PROGMEM = "Date / Time";
prog_char menu7_label[] PROGMEM = "Sal Calibration";
prog_char menu8_label[] PROGMEM = "Turn ON/OFF Skimmer";
prog_char menu9_label[] PROGMEM = "Turn Off Skimmer";
// Group the menu entries together
PROGMEM const char *menu_items[] = {
menu1_label, menu2_label, menu3_label,
menu4_label, menu5_label, menu6_label,
menu7_label, menu8_label, menu9_label
};
    
void MenuEntry1()
{
ReefAngel.FeedingModeStart();
}
void MenuEntry2()
{
ReefAngel.WaterChangeModeStart();
}
void MenuEntry3()
{
ReefAngel.ATOClear();
ReefAngel.DisplayMenuEntry("Clear ATO Timeout");
}
void MenuEntry4()
{
ReefAngel.OverheatClear();
ReefAngel.DisplayMenuEntry("Clear Overheat");
}
void MenuEntry5()
{
ReefAngel.SetupCalibratePH();
ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;
}
void MenuEntry6()
{
ReefAngel.SetupDateTime();
ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;
}
void MenuEntry7()
{
ReefAngel.SetupCalibrateSalinity();
ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;
}
void MenuEntry8()
{
ReefAngel.Relay.Toggle(Box1_Port8);
ReefAngel.Relay.Write();
ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;
}
void MenuEntry9()
{
ReefAngel.Relay.Off(Box1_Port8);
ReefAngel.Relay.Write();
ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;
}

void DrawCustomMain()
{
  ReefAngel.LCD.DrawDate(6, 119);
  pingSerial();
#if defined DisplayLEDPWM && ! defined RemoveAllLights
  ReefAngel.LCD.DrawMonitor(15, 60, ReefAngel.Params,
  ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue());
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
  ReefAngel.LCD.DrawMonitor(15, 60, ReefAngel.Params);
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
  pingSerial();
  // draw main relay
  byte TempRelay = ReefAngel.Relay.RelayData;
  TempRelay &= ReefAngel.Relay.RelayMaskOff;
  TempRelay |= ReefAngel.Relay.RelayMaskOn;
  ReefAngel.LCD.DrawOutletBox(12, 93, TempRelay);
#ifdef RelayExp
  pingSerial();
  // draw 1st expansion relay
  TempRelay = ReefAngel.Relay.RelayDataE[0];
  TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
  TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
  ReefAngel.LCD.DrawOutletBox(12, 105, TempRelay);
#endif  // RelayExp
}
void DrawCustomGraph()
{
  // Change the 45 to adjust the horizontal position of the text 
  ReefAngel.LCD.DrawGraph(5, 5);
}

void CheckReservoirStatus(byte channel, byte pump)
{
    if ( ReefAngel.IO.GetChannel(channel) )
    {
        // If empty, shutoff the port, trigger alert
        ReefAngel.CustomVar[channel] = 1;
        ReefAngel.Relay.Off(pump);
    }
    else
    {
        // If not empty, turn on the port, clear alert
        ReefAngel.CustomVar[channel] = 0;
        ReefAngel.Relay.On(pump);
    }
}


void CheckReservoirStatusPH(byte channel, byte pump)
{
    if ( ReefAngel.IO.GetChannel(channel) )
    {
        // If empty, shutoff the port, trigger alert
        ReefAngel.CustomVar[channel] = 1;
        ReefAngel.Relay.Off(pump);
    }
    else
    {
        // If not empty, turn on the port, clear alert
        ReefAngel.CustomVar[channel] = 0;
        ReefAngel.PHControl(pump);
    }
}


void CheckReservoirStatusCO2(byte channel, byte pump)
{
    if ( ReefAngel.IO.GetChannel(channel) )
    {
        // If empty, shutoff the port, trigger alert
        ReefAngel.CustomVar[channel] = 1;
        ReefAngel.Relay.Off(pump);
    }
    else
    {
        // If not empty, turn on the port, clear alert
        ReefAngel.CustomVar[channel] = 0;
        ReefAngel.CO2Control(pump);
    }
}


void MyCustomATO(int ATOTimeout)
{
    /*
    This function works as follows:

    When it's time to topoff the system, we check the levels of each
    of the three reservoirs.  If a reservoir is empty, we set a custom
    flag to indicate it's empty on the portal and we do not start that
    pump.  Otherwise, we clear the custom flag for the reservoir and
    start the pump.
    The function monitors the switch levels like normal.
    Monitor the status of the reservoirs while topping off.
    When the high switch is triggered (aka, finished topping off), 
    ALL ports are turned off regardless of status (doesn't hurt to do this).
    If the timeout occurs, the LED light comes on and all ports are 
    turned off just like when we finish topping off.
    
    */
    unsigned long TempTimeout = ATOTimeout;
    TempTimeout *= 60000; /* Try increasing this from 1000, it seems to take the number
    of seconds, 255 max, and convert to milliseconds.  So, multiply by 60
    to make ATOTimeout effectively be minutes?
     */

    if ( ReefAngel.LowATO.IsActive() && ( !ReefAngel.LowATO.IsTopping()) )
    {
        ReefAngel.LowATO.Timer = millis();
        ReefAngel.LowATO.StartTopping();

        // Check the level of each reservoir
        // If empty, set the alert and don't start topping off
        // otherwise if not empty, clear the alert and start topping
            
        if (!ReefAngel.IO.GetChannel(0) && !ReefAngel.IO.GetChannel(1) && !ReefAngel.IO.GetChannel(2) ) // If we have BOTH kalk and RODI
        {
          if (minute()%15==0 && second()>=15)
          {
          CheckReservoirStatusPH(0, Port5);
          CheckReservoirStatusPH(1, Port6);  
          CheckReservoirStatusCO2(2, Box1_Port5);
          }
          else
          {
            ReefAngel.Relay.Off(Port5);
            ReefAngel.Relay.Off(Port6);
            ReefAngel.Relay.Off(Box1_Port5);
          }
        }
        else  //Otherwise, just fill up the sump with whatever liquid we have.
        {
        CheckReservoirStatus(0, Port5);
        CheckReservoirStatus(1, Port6);  
        CheckReservoirStatus(2, Box1_Port5);        
        }
    }
    else  // Maintain pH, but don't trip the ATO high switch.
    {
      if (hour()%2==1 && minute()%15==0  && second()>=45)
      {
        CheckReservoirStatusPH(0, Port5);
      }
      else
          {
            ReefAngel.Relay.Off(Port5);
          }
      if (hour()%2==0 && minute()%15==0  && second()>=45)
      {
        CheckReservoirStatusPH(1, Port6);
      }
      else
          {
            ReefAngel.Relay.Off(Port6);
          }
    }


    // Monitor levels while topping off, to prevent a reservoir from running dry
    // Might need to remove this check here -- Nope, this seems to work fine.
  
    if ( ReefAngel.LowATO.IsTopping() )
    {
         if ((!ReefAngel.IO.GetChannel(0) || !ReefAngel.IO.GetChannel(1)) && !ReefAngel.IO.GetChannel(2) ) // If we have BOTH kalk and RODI
        {
        CheckReservoirStatusPH(0, Port5);
        CheckReservoirStatusPH(1, Port6);  
        CheckReservoirStatusCO2(2, Box1_Port5);
        }
        else  //Otherwise, just fill up the sump with whatever liquid we have.
        {
        CheckReservoirStatus(0, Port5);
        CheckReservoirStatus(1, Port6);  
        CheckReservoirStatus(2, Box1_Port5);        
        }
    }

    if ( ReefAngel.HighATO.IsActive() )
    {
        ReefAngel.LowATO.StopTopping();  // stop the low ato timer
        ReefAngel.Relay.Off(Port5);
        ReefAngel.Relay.Off(Port6);
        ReefAngel.Relay.Off(Box1_Port5);
    }

    if ( (millis()-ReefAngel.LowATO.Timer > TempTimeout) && ReefAngel.LowATO.IsTopping() )
    {
        ReefAngel.LED.On();
#ifdef ENABLE_EXCEED_FLAGS
        InternalMemory.write(ATO_Exceed_Flag, 1);
#endif  // ENABLE_EXCEED_FLAGS
        ReefAngel.Relay.Off(Port5);
        ReefAngel.Relay.Off(Port6);
        ReefAngel.Relay.Off(Box1_Port5);
#ifdef ENABLE_ATO_LOGGING
        // bump the counter if a timeout occurs
        AtoEventCount++;
        if ( AtoEventCount >= MAX_ATO_LOG_EVENTS ) { AtoEventCount = 0; }
#endif  // ENABLE_ATO_LOGGING
    }
}

void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller
    wdt_enable(WDTO_2S);
    // Initialize the custom menu
    ReefAngel.InitMenu(pgm_read_word(&(menu_items[0])),SIZE(menu_items));

    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = 0;
    ReefAngel.FeedingModePortsE[0] = Port7Bit;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port2Bit | Port4Bit;
    ReefAngel.OverheatShutoffPortsE[0] = Port1Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = Port4Bit | Port8Bit;
    ReefAngel.LightsOnPortsE[0] = Port1Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port2Bit | Port5Bit | Port6Bit;
    ReefAngel.WaterChangePortsE[0] = Port2Bit | Port5Bit | Port6Bit | Port8Bit;

    // Ports that are always on or off 
    ReefAngel.Relay.Off(Box1_Port3); //Broken port    
    ReefAngel.Relay.Off(Box1_Port4); //Broken port
    ReefAngel.Relay.On(Box1_Port7); //Powerheads 2, 3
    ////// Place additional initialization code below here
    ReefAngel.OverheatProbe = T1_PROBE; // Use Temperature probe 1 to check for overheat
    ReefAngel.TempProbe = T1_PROBE;
    ////// Place additional initialization code above here
}

void loop()
{
    // Specific functions that use Internal Memory values
    //ReefAngel.MoonLights(Port1); // Moon lights on 23:00-02:00.  What I would like to do is use logic to turn this port on if the actinic port is off, and the time of day is between 17:00-02:00
    ReefAngel.Relay.Set(Port1, !ReefAngel.Relay.Status(Port8) && hour()>7);  //Turn on moonlights of the main relay IF actinics are off AND the time is NOT between midnight and 7:00am
    ReefAngel.StandardHeater(Port2); // 800w heater on at 78.0, off at 79.0
    ReefAngel.DelayedStartLights(Port4); // MH on 14:00-22:00, delay 15m if power fails
    //ReefAngel.Relay.Set(Port7,!ReefAngel.Relay.Status(Port4)); //Sump lights on if halides are not
    ReefAngel.Relay.Set(Port7, !ReefAngel.Relay.Status(Port4) || hour()>=21 || hour()<11);  //turn on sump lights IF halides are off OR the time is between 9:00pm and 11:00am
    //ReefAngel.StandardLights(Port7,22,0,12,0); // Sump lights on 22:00-12:00
    ReefAngel.ActinicLights(Port8);  //actinics
    ReefAngel.DelayedStartLights(Box1_Port1); // MH on 14:00-22:00, delay 15m if power fails
    ReefAngel.DosingPumpRepeat2(Box1_Port2);//LaCl dose
    ReefAngel.Relay.DelayedOn(Box1_Port8); //This is the skimmer, which we dont want to turn on right after reboot, since sump might be flooded, e.g., if power was out. Wait for pumps to lift water.
    ////// Place your custom code below here
    //ATO function
      MyCustomATO(InternalMemory.ATOTimeout_read());

    //Notify when sump level is low
    if ( ReefAngel.IO.GetChannel(4) )
    {
      ReefAngel.CustomVar[4]=1;
        // If the sump level is about to cavitate the pumps, then sound the alarm
        unsigned long currentMillis = millis();
        if(currentMillis - previousMillis > buzzerinterval) {
    // save the last time the buzzer turned on 
    previousMillis = currentMillis;   
    // if the buzzer is off turn it on and vice-versa:
    if (ReefAngel.PWM.GetDaylightValue() == 0)
      ReefAngel.PWM.SetDaylight(25);
    else
      ReefAngel.PWM.SetDaylight(0);
  }
    }
    else
    {
        // Turn the buzzer off when the sump level is above cavitation levels
        ReefAngel.PWM.SetDaylight(0);
        ReefAngel.CustomVar[4]=0;
    }

//If the ATO float switch is stuck, and the topoff pump timeout flag is set, then set C5=1
ReefAngel.CustomVar[5]=InternalMemory.read(ATO_Exceed_Flag);  //Note that this value should be either 0 or 1, but for some reason is 254 or 255.
    
//Vodka dosing 
      if ( ReefAngel.IO.GetChannel(3) )  //Check there is vodka in the reservoir
  {
    ReefAngel.Relay.Off(Box1_Port6);  //If no vodka, then set a variable and turn off the port
    ReefAngel.CustomVar[3]=1;
  }
  else  //If there is vodka, then dose
  {
    if ( ReefAngel.Relay.Status(Port4) ) //But only if the halides are ON, since pH is lowered by acetic acid
    {
    ReefAngel.CustomVar[3]=0;
    ReefAngel.DosingPumpRepeat1(Box1_Port6);
    }
  }
  
//Phytoplankton dosing, 0.75ml/sec for 15 sec/hour should dose 1750ml/week.  However, run it for 1min at a time to clear out tube.
if (hour()%4==0 && minute()==0)
//ReefAngel.FeedingModeStart();
{
ReefAngel.Relay.On(Port3);
}
else
{
ReefAngel.Relay.Off(Port3);
}

//Monitor the water level in the display
ReefAngel.CustomVar[6]=ReefAngel.IO.GetChannel(5);
  
    ////// Place your custom code above here
    // This sends all the data to the portal
    // Do not add any custom code that changes any relay status after this line
    // The only code after this line should be the ShowInterface function
    ReefAngel.Portal("btorrenga","SECRET");

    // This should always be the last line
    ReefAngel.ShowInterface();
}
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Flags - will new libraries break something?

Post by rimai »

No. It would only affect if you were using ReefAngel.Flags variable.
It's very unlikely anyone was using that variable.
Roberto.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Flags - will new libraries break something?

Post by lnevo »

I was :)
Post Reply