v0.9.0 Libraries

Related to the development libraries, released by Curt Binder
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

v0.9.0 Libraries

Post by binder »

Following with Roberto's post earlier, the latest version of the development libraries (v0.9.0) have also been released.

This is a significant release and your existing sketches will need to be updated to work.

We have made drastic changes to handle all the new and upcoming features and modules for the controller.

The most notable change is the name of the libraries. They have changed. RAGen handles the conversion and change for you, but for those who are manually changing a sketch file, here's a list of the headers that need to be changed:
  • ReefAngel_AI --> AI
  • ReefAngel_Globals --> Globals
  • IO (New)
  • ReefAngel_EEPROM --> InternalEEPROM
  • ReefAngel_LED --> LED
  • ReefAngel_Memory --> Memory
  • ORP (New)
  • ReefAngel_ATO --> RA_ATO
  • ReefAngel_Colors --> RA_Colors
  • ReefAngel_CustomColors --> RA_CustomColors
  • ReefAngel_Joystick --> RA_Joystick
  • ReefAngel_NokiaLCD --> RA_NokiaLCD
  • ReefAngel_PWM --> RA_PWM
  • ReefAngel_TempSensor --> RA_TempSensor
  • ReefAngel_Wifi --> RA_Wifi
  • ReefAngel_RF --> RF
  • ReefAngel (No Change)
  • ReefAngel_Features (No Change)
  • ReefAngel_Relay --> Relay
  • ReefAngel_Salinity --> Salinity
  • ReefAngel_Timer --> Timer
If you are still unsure, it's best to use RAGen to get a handle on how things have changed. RAGen is more robust now than ever. It handles ALL the features and generates the code properly.

Another notable change is the filename for the code. It was PDE and with the use of Arduino 1.0, that was changed to INO. These libraries will ONLY work with Arduino 1.0. So you must upgrade Arduino. It's recommended that you use the installer that Roberto has provided (makes things so much easier).
http://forum.reefangel.com/viewtopic.php?f=8&t=718

Changes to the libraries.
These are just the highlights that are significant for people. There have been many other behind-the-scenes fixups and improvements plus modifications for some of the future products.
  • Temperature probe customizations (This is not currently in RAGen, but will be added in the future).

    Code: Select all

    Allowed for easy customization of Tank and Overheat temp probes
    
    Overheat temp can be customized
    * use ReefAngel.OverheatProbe = PROBE
    
    Heater & Fan/Chiller temp can be customized
    * use ReefAngel.TempProbe = PROBE
    
    PROBE can be T1_PROBE, T2_PROBE or T3_PROBE
    Place those lines in setup() and after ReefAngel.Init();
  • WebBanner is dropped, you now use Portal(). This simplifies the code. You do not need to add in the banner labels or handle the timers. You simply have a Portal() function call in the loop() and that's it. Nothing else to add to setup. Usage:

    Code: Select all

    ReefAngel.Portal("username");
    or
    ReefAngel.Portal("username", "key");
    
    The "username" is your forum username and the optional "key" is the security key you set from your portal page.
  • Additional wifi commands added
    • Clear ATO alarm (/mt)
    • Clear Overheat alarm (/mo)
  • PWM slope functions are incorporated into the PWM library. You can still use the standard PWMSlope function but the predefined functions are setup to work with the memory locations. ReefAngel.PWM.Actinic & Daylight Slope(). They are set to operate with the StandardLights on/off times. They also use the memory locations for the start and end percentage and duration.

    Code: Select all

    ReefAngel.PWM.ActinicPWMSlope(byte MinuteOffset);
    ReefAngel.PWM.DaylightPWMSlope(byte MinuteOffset);
    ReefAngel.PWM.ActinicPWMSlope();
    ReefAngel.PWM.DaylightPWMSlope();
    ReefAngel.PWM.ActinicPWMParabola(byte MinuteOffset);
    ReefAngel.PWM.DaylightPWMParabola(byte MinuteOffset);
    ReefAngel.PWM.ActinicPWMParabola();
    ReefAngel.PWM.DaylightPWMParabola();
    
    As you can see, there are lots of additions made. These listed work for the Actinic and Daylight PWM ports on the controller. If you want to use them with the PWM Expansion, you must continue to do it the way you do currently. (This is not in RAGen)
  • DosingPump function no longer needs a timer. You can have multiple dosing pumps without worry of interference with wavemakers. The function has been improved:

    Code: Select all

    ReefAngel.DosingPump(byte DPRelay, byte OnHour, byte OnMinute, byte RunTime);
  • DosingPumpRepeat also has an offset from the run time now. So you can have your dosing pump run 5 minutes later if you like. This way you can have the pumps repeat every 4 hours and have one be 5 or 10 minutes later than the other, to prevent dosing at the same time.

    Code: Select all

    ReefAngel.DosingPumpRepeat(byte DPRelay, int OffsetMinute, int RepeatMinute, byte RunTime);
    (This is not in RAGen)
  • Wavemakers now do not need the built in timers. They still have the interval/run time but the behind-the-scenes code has been trimmed up.
  • There is now a Wavemaker Random function. You can have up to 3 random wavemakers. A random value between the Min and Max time is chosen for each toggle period. It's best to have at least 5 - 10 seconds as a minimum toggle period. DO NOT PUT IN 0 otherwise the port might not toggle on or off. (This is not in RAGen)

    Code: Select all

    ReefAngel.WavemakerRandom(byte WMRelay, int MinWMTimer, int MaxWMTimer);
    ReefAngel.WavemakerRandom1(byte WMRelay, int MinWMTimer, int MaxWMTimer);
    ReefAngel.WavemakerRandom2(byte WMRelay, int MinWMTimer, int MaxWMTimer);
    
  • Fixed some content-length errors with wifi responses.
  • InternalMemory check on startup to ensure memory locations have been set before use.
  • Added Relay.Set() function. This can help simplify some of the if/else statements in your custom code.

    Code: Select all

    ReefAngel.Relay.Set(PORT, boolean Condition);
    
    Example:
    // Turn on Port 1 when temp 1 is above 80.0 degrees and off when it's 80.0 and below
    ReefAngel.Relay.Set(Port1, (ReefAngel.Params.Temp[T1_PROBE]>800));
    
  • Improvements with PWM Expansion
  • XML data sent from controller has increased for better remote monitoring of all aspects
There are additional libraries that need updates to them (OneWire, Time, DS1307RTC, Wire). It is strongly recommended that you follow Roberto's suggestion for upgrading using the installer instead of the Update Utility. At least when going from the 0.8.5.X to 0.9.0 libraries.

These were just some of the major highlights with the library release.
Last edited by binder on Fri Feb 17, 2012 12:08 pm, edited 1 time in total.
Reason: bolded and enlarged font for changes to libraries heading
Seedlessone
Posts: 135
Joined: Tue Jan 24, 2012 6:20 pm

Re: v0.9.0 Libraries

Post by Seedlessone »

Thanks for all the hard work. Can't wait to update tomorrow.
bigHUN
Posts: 97
Joined: Sat Dec 03, 2011 9:41 pm

Re: v0.9.0 Libraries

Post by bigHUN »

I didn't started programing yet beside a fact that the new (to) hardware is on my table for some time. Roberto sent me my new first screen and the menu to start with, browsing now what and where to start expanding it. Seem to me, where I want to get the RaGen don't have all buttons avaiable. I understand that we have a transition time and this could be a great opportunity to sort the new things in separate thread as a sticky. Questions:
1. how can I see which is a new library? when I am browsing through the existing posts.
2. not to run in to compatibility issues when I copy/paste over from existing
3. what is a best practice, edit the separate file or do it directly from Arduino1 ? and check for errors?
4. can I assume the *.h and *.cpp are the postprocessor and the *.pde output extension will be replaced with *.ino ? why?
thanks
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: v0.9.0 Libraries

Post by rimai »

1. The old libraries started with ReefAngel_ and the new libraries start with RA_ or have no prefix.
The reason was because several of the libraries will become shared among current and future products and reusable while the specifc for the standard RA will have RA_
2. Only the top part of the code where the libraries are is usually what is going to be changed. The code itself in general would work just fine if copied/pasted.
3. I prefer using Arduino itself as my code editor. Some prefer to use another IDE and then pasting on Arduino to compile and upload.
4. .h and .cpp are actually pre-processor. The extension from pde to ino was made by the Arduino team and we are just adopting it as their software saves everything as ino from now on.
Roberto.
StuGotz
Posts: 95
Joined: Sat Oct 15, 2011 9:17 am

Re: v0.9.0 Libraries

Post by StuGotz »

I made the switch to the v0.9.0 Libraries, but now it says my sketch is too large :( It says Binary sketch size: 33990 bytes (of a 32256 byte maximum)

I had to make changes to these lines

Code: Select all

ConvertNumToString(text, ReefAngel.Params.Temp[T1_PROBE], 10);
ConvertNumToString(text, ReefAngel.Params.Temp[T2_PROBE], 10);
ConvertNumToString(text, ReefAngel.Params.Temp[T3_PROBE], 10);
I also had to edit RA_CustomColors.h, since my original referenced "ReefAngel_Colors.h"

Here's my whole INO

Code: Select all

// Autogenerated file by RAGen (v1.0.4.92), (10/15/2011 12:40)
// RA_101511_1240.pde
//
// This version designed for v0.8.5 Beta 12 or later

// *********************************************************
// MANY THANKS TO BOTH ROBERTO AND CURT FOR ALL THEIR HELP!*
// *********************************************************

/* The following features are enabled for this PDE File: 
#define DisplayLEDPWM
#define wifi
#define VersionMenu
#define CUSTOM_MAIN
#define NUMBERS_8x16
#define COLORS_PDE
#define CUSTOM_MENU
#define CUSTOM_MENU_ENTRIES 6
#define RFEXPANSION
*/

#include <ReefAngel_Features.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 <RA_PWM.h>
#include <Timer.h>
#include <Memory.h>
#include <ReefAngel.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <avr/pgmspace.h>
#include <RF.h>

#define Sump                1
#define DosingPump2         2
#define Refugium            3
#define Daylight            4
#define Actinic             5
#define Skimmer             6
#define Heater              7
#define DosingPump1         8

//Cloud & Lightning effect Global Variables
byte ActinicPWMValue=0;
byte DaylightPWMValue=0;
boolean ForceCloud=false;

// Echosmart Global Variable
byte vtechmode;

// Moon Global Variables - Thanks Deckoz2302!
byte DayAge;
byte ThisPhase;
int JulianDate(int,int,int);
double MoonAge(int,int,int);
byte MoonState();

// Create the menu entries
prog_char menu1_label[] PROGMEM = "Feeding";
prog_char menu2_label[] PROGMEM = "Water Change";
prog_char menu3_label[] PROGMEM = "Force Cloud";
prog_char menu4_label[] PROGMEM = "Reboot";
prog_char menu5_label[] PROGMEM = "Overheat Clear";
prog_char menu6_label[] PROGMEM = "PH Calibration";
prog_char menu7_label[] PROGMEM = "Version";

// Group the menu entries together
PROGMEM const char *menu_items[] = {
menu1_label, menu2_label, menu3_label,
menu4_label, menu5_label, menu6_label, menu7_label
};

// Menu Item actions
void MenuEntry1()
{
ReefAngel.FeedingModeStart();
}
void MenuEntry2()
{
ReefAngel.WaterChangeModeStart();
}
void MenuEntry3()
{
ForceCloud=true;
ReefAngel.DisplayedMenu=RETURN_MAIN_MODE;
}
void MenuEntry4()
{
delay(1000);
}
void MenuEntry5()
{
ReefAngel.OverheatClear();
ReefAngel.DisplayMenuEntry("Clear Overheat");
}
void MenuEntry6()
{
ReefAngel.SetupCalibratePH();
ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;
}
void MenuEntry7()
{
ReefAngel.DisplayVersion();
}

// Custom Main Screen

void DrawCustomMain()
{
  ReefAngel.LCD.DrawText(COLOR_WHITE, COLOR_CORNFLOWERBLUE, 0, 0, "                       "); //Top Banner
  ReefAngel.LCD.DrawText(COLOR_WHITE, COLOR_CORNFLOWERBLUE, 0, 2, " BioCube 14 Nano Reef  "); //Top Banner
  ReefAngel.LCD.DrawDate(6, 123);
  pingSerial();
  
  // Display Temp Text
  ReefAngel.LCD.DrawText(0,255,12,12,"Temp");
  
  // Display the T1 temp value 10,22
  char text[7];
  ConvertNumToString(text, ReefAngel.Params.Temp[T1_PROBE], 10);
  ReefAngel.LCD.Clear(255, 0, 20, 50, 36);
  ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE, 255, 10, 20, text, Num8x16);
  pingSerial();
  
  // Display pH Text
  ReefAngel.LCD.DrawText(0,255,100,12,"pH");
  
  // Display pH Value
  ConvertNumToString(text, ReefAngel.Params.PH, 100);
  ReefAngel.LCD.Clear(255, 90, 20, 98, 36);
  ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE, 255, 90, 20, text, Num8x16);
  pingSerial();
   
  // Display Actinic Percentage Text
  ReefAngel.LCD.DrawText(0,255,8,35,"Actinic %");
  
  // Display the Actinic PWM channel value at 90,40
  ReefAngel.LCD.DrawSingleMonitor(ReefAngel.PWM.GetActinicValue(),COLOR_CORNFLOWERBLUE, 90, 35, 1);
  
  // Display Daylight Percentage Text
  ReefAngel.LCD.DrawText(0,255,8,45,"Daylight %");
    
  // Display the Daylight PWM channel value at 90,50
  ReefAngel.LCD.DrawSingleMonitor(ReefAngel.PWM.GetDaylightValue(),COLOR_CORNFLOWERBLUE, 90, 45, 1);
  
  // Display T2 Temp Text
  ReefAngel.LCD.DrawText(0,255,8,55,"Canopy Temp");
  
  // Display the T2 temperature value at 90,60
  ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp[T2_PROBE], COLOR_CORNFLOWERBLUE, 90, 55, 10);
  
  // Display T3 Temp Text
  ReefAngel.LCD.DrawText(0,255,8,65,"Ambient Temp");
  
  // Display the T3 temperature at 90,70
  ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp[T3_PROBE], COLOR_CORNFLOWERBLUE, 90, 65, 10);
  
  // Display Seperat0r
  ReefAngel.LCD.DrawText(0,255,5,73,"--------------------------");
  
  ReefAngel.LCD.DrawText(0,255,8,80,"EcoSmart");
  
  // Display EcoSmart Mode Value - Thanks Deckoz2302!
  //ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,90,80,"Storm");
  ReefAngel.LCD.Clear(255, 58, 80, 128, 90);
  if (vtechmode == 0) ReefAngel.LCD.DrawText(COLOR_LIMEGREEN,255,58,80,"Constant");
  else if(vtechmode == 1) ReefAngel.LCD.DrawText(COLOR_GOLD,255,58,80,"Lagoon");
  else if (vtechmode == 2) ReefAngel.LCD.DrawText(COLOR_GOLD,255,58,80,"Reef Crest");
  else if (vtechmode == 3) ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,58,80,"Short Pulse");
  else if (vtechmode == 4) ReefAngel.LCD.DrawText(COLOR_PINK,255,58,80,"Long Pulse");
  else if (vtechmode == 5) ReefAngel.LCD.DrawText(COLOR_MAGENTA,255,58,80,"Nut. Trans");
  else if (vtechmode == 6) ReefAngel.LCD.DrawText(COLOR_MAGENTA,255,58,80,"Tidal Swell");
  else if (vtechmode == 9) ReefAngel.LCD.DrawText(COLOR_WHITE,0,58,80," Night ");
  pingSerial();
  
  // Display Moon Phase & State Text
  ReefAngel.LCD.DrawText(0,255,8,90,"Moon");
  
  // Display Moon Phase & State at 35,90
  DayAge = MoonAge(day(), month(), year());
  MoonState(DayAge);
  char* ThisPhaseLabel[]={
    "New","Waxing Crescent","First Quarter","Waxing Gibbous","Full","Waning Gibbous","Last Quarter","Waning Crescent"                        };
  ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,35,90,ThisPhaseLabel[ThisPhase]);
  
  // Display Outlet Box 
  pingSerial();
  byte TempRelay = ReefAngel.Relay.RelayData;
  TempRelay &= ReefAngel.Relay.RelayMaskOff;
  TempRelay |= ReefAngel.Relay.RelayMaskOn;
  ReefAngel.LCD.DrawOutletBox(13, 99, TempRelay);
}
void DrawCustomGraph()
{
 // ReefAngel.LCD.DrawGraph(5,7);
}

void setup()
{
  ReefAngel.Init();  //Initialize controller
  ReefAngel.InitMenu(pgm_read_word(&(menu_items[0])),SIZE(menu_items)); //For Custom Menu
  ReefAngel.FeedingModePorts = B00100001; // Feeding mode: Ports 6 & 1 turn off
  ReefAngel.WaterChangePorts = B00100001; // Water Change mode: Ports 6 & 1 turn off
  ReefAngel.OverheatShutoffPorts = B00011000; // Overheat mode: Ports 4 & 5 turn off
  ReefAngel.LightsOnPorts = B00011000; // Lights On mode: ports 4 & 5 turn on
  ReefAngel.Relay.On(Port1); // Port 1 always on
}

void loop()
{
  ReefAngel.ShowInterface();
  
  // Delay Skimmer port 5 minutes whenever turned on
  // From Curt - THANKS CURT!
  ReefAngel.Relay.DelayedOn(Port6, 5);
  
  //Heater    
  ReefAngel.StandardHeater(Heater,775,780);  // Setup Heater to turn on at 77.5F and off at 78.0F
 
  //Lighting schedule
  ReefAngel.MHLights(Daylight,9,0,17,0,0);  //Daylight schedule 9:00am - 5:00pm with 0min cool down
  ReefAngel.StandardLights(Actinic,7,0,19,0);  //Actinic schedule 7:00am - 7:00pm
  ReefAngel.StandardLights(Refugium,19,0,7,0);  //Refugium schedule 7:00pm - 7:00am
  
  // Dosing pumps (OLD DOSING METHOD OF PUMP ONE ON THE HOUR, THEN PUMP2 5 MIN LATER - to use when tank is more mature
  //From Roberto - THANKS ROBERTO!
   /* if (ReefAngel.DisplayedMenu==255 && minute()==0 && second()<1)  //Alk Doser - Only works if Main screen is showing
      ReefAngel.Relay.On(DosingPump1);  //Turn Alk Doser on
    else
      ReefAngel.Relay.Off(DosingPump1);  //Turn Alk Doser off
    if (ReefAngel.DisplayedMenu==255 && minute()==5 && second()<1)  //CA Doser - Only works if Main screen is showing
      ReefAngel.Relay.On(DosingPump2);  //Turn CA Doser on
    else
      ReefAngel.Relay.Off(DosingPump2);  //Turn CA Doser off 
   */
 
  // Dosing pumps
  // From Roberto - THANKS ROBERTO!
  
  if (ReefAngel.DisplayedMenu==255 && hour()%2==0 && minute()==0 && second()<1) // 1 sec dosing on even hours
    ReefAngel.Relay.On(DosingPump1);  //Turn DosingPump1 Doser on
  else
    ReefAngel.Relay.Off(DosingPump1);  //Turn DosingPump1 Doser off
  if (ReefAngel.DisplayedMenu==255 && hour()%2==1 && minute()==0 && second()<1) // 1 sec dosing on odd hours
    ReefAngel.Relay.On(DosingPump2);  //Turn DosingPump2 Doser on
  else
    ReefAngel.Relay.Off(DosingPump2);  //Turn DosingPump2 Doser off

  // Cloud & Lightning effects - Calculate your regular sunrise/sunset PWM value
  // From Roberto - THANKS ROBERTO!
  // byte PWMSlope(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
  if (hour()>=19 || hour()<7)
    {
      ReefAngel.PWM.SetActinic(MoonPhase());  //Moon phase schedule between 7:00pm - 7:00am
      ReefAngel.RF.UseMemory=false;
      ReefAngel.RF.SetMode(Night,15,0);
      vtechmode = 9;
    }
  else
    {
      ActinicPWMValue=PWMSlope(7,00,19,0,0,35,60,ActinicPWMValue); //Actinic turn on at 7am, off at 10am, and ramp up 0% to 50% PWM in 60 minutes
      //ActinicPWMValue=PWMSlope(16,00,19,0,0,50,60,ActinicPWMValue); //Actinic turn on at 4pm, off at 7pm, and ramp up 0% to 50% PWM in 60 minutes
      ReefAngel.PWM.SetActinic(ActinicPWMValue);
      ReefAngel.RF.SetMode(Feeding_Stop,0,0); //Temp fix for coming out of Night mode
      ReefAngel.RF.UseMemory=true;
      vtechmode = InternalMemory.RFMode_read();
    }
  DaylightPWMValue=PWMSlope(9,00,17,0,0,75,60,DaylightPWMValue); //Daylight turn on at 9am, off at 5pm, and ramp up 0% to 50% PWM in 60 minutes
  CheckCloud(); 
  ReefAngel.PWM.SetDaylight(DaylightPWMValue);
}

//*********************************************************************************************************************************
// Random Cloud/Thunderstorm effects function
// From Roberto - THANKS ROBERTO!
void CheckCloud()
{

  // ------------------------------------------------------------
  // Change the values below to customize your cloud/storm effect

  // Frequency in days based on the day of the month - number 2 means every 2 days, for example (day 2,4,6 etc)
  // For testing purposes, you can use 1 and cause the cloud to occur everyday
#define Clouds_Every_X_Days 1 

  // Percentage chance of a cloud happening today
  // For testing purposes, you can use 100 and cause the cloud to have 100% chance of happening
#define Cloud_Chance_per_Day 100

  // Minimum number of minutes for cloud duration.  Don't use max duration of less than 6
#define Min_Cloud_Duration 7

  // Maximum number of minutes for the cloud duration. Don't use max duration of more than 255
#define Max_Cloud_Duration 15

  // Minimum number of clouds that can happen per day
#define Min_Clouds_per_Day 3

  // Maximum number of clouds that can happen per day
#define Max_Clouds_per_Day 6

  // Only start the cloud effect after this setting
  // In this example, start could after 11:30am
#define Start_Cloud_After NumMins(11,30)

  // Always end the cloud effect before this setting
  // In this example, end could before 4:30pm
#define End_Cloud_Before NumMins(16,30)

  // Percentage chance of a lightning happen for every cloud
  // For testing purposes, you can use 100 and cause the lightning to have 100% chance of happening
#define Lightning_Change_per_Cloud 25

  // Note: Make sure to choose correct values that will work within your PWMSLope settings.
  // For example, in our case, we could have a max of 5 clouds per day and they could last for 50 minutes.
  // Which could mean 250 minutes of clouds. We need to make sure the PWMSlope can accomodate 250 minutes of effects or unforseen result could happen.
  // Also, make sure that you can fit double those minutes between Start_Cloud_After and End_Cloud_Before.
  // In our example, we have 510 minutes between Start_Cloud_After and End_Cloud_Before, so double the 250 minutes (or 500 minutes) can fit in that 510 minutes window.
  // It's a tight fit, but it did.

    //#define printdebug // Uncomment this for debug print on Serial Monitor window
#define forcecloudcalculation // Uncomment this to force the cloud calculation to happen in the boot process. 


  // Change the values above to customize your cloud/storm effect
  // ------------------------------------------------------------
  // Do not change anything below here

  static byte cloudchance=255;
  static byte cloudduration=0;
  static int cloudstart=0;
  static byte numclouds=0;
  static byte lightningchance=0;
  static byte cloudindex=0;
  static byte lightningstatus=0;
  static int LastNumMins=0;
  // Every day at midnight, we check for chance of cloud happening today
  if (hour()==0 && minute()==0 && second()==0) cloudchance=255;

#ifdef forcecloudcalculation
  if (cloudchance==255)
#else
    if (hour()==0 && minute()==0 && second()==1 && cloudchance==255) 
#endif
    {
      //Pick a random number between 0 and 99
      cloudchance=random(100); 
      // if picked number is greater than Cloud_Chance_per_Day, we will not have clouds today
      if (cloudchance>Cloud_Chance_per_Day) cloudchance=0;
      // Check if today is day for clouds. 
      if ((day()%Clouds_Every_X_Days)!=0) cloudchance=0; 
      // If we have cloud today
      if (cloudchance)
      {
        // pick a random number for number of clouds between Min_Clouds_per_Day and Max_Clouds_per_Day
        numclouds=random(Min_Clouds_per_Day,Max_Clouds_per_Day);
        // pick the time that the first cloud will start
        // the range is calculated between Start_Cloud_After and the even distribuition of clouds on this day. 
        cloudstart=random(Start_Cloud_After,Start_Cloud_After+((End_Cloud_Before-Start_Cloud_After)/(numclouds*2)));
        // pick a random number for the cloud duration of first cloud.
        cloudduration=random(Min_Cloud_Duration,Max_Cloud_Duration);
        //Pick a random number between 0 and 99
        lightningchance=random(100);
        // if picked number is greater than Lightning_Change_per_Cloud, we will not have lightning today
        if (lightningchance>Lightning_Change_per_Cloud) lightningchance=0;
      }
    }
  
  //When custom menu Force cloud is selected
  if (ForceCloud)
  {
    ForceCloud=false;
    cloudchance=1;
    cloudduration=10;
    lightningchance=1;
    cloudstart=NumMins(hour(),minute())+1;
  }
  
  // Now that we have all the parameters for the cloud, let's create the effect
  if (cloudchance)
  {
    //is it time for cloud yet?
    if (NumMins(hour(),minute())>=cloudstart && NumMins(hour(),minute())<(cloudstart+cloudduration))
    {
      DaylightPWMValue=ReversePWMSlope(cloudstart,cloudstart+cloudduration,DaylightPWMValue,0,180);
      if (lightningchance && (NumMins(hour(),minute())==(cloudstart+(cloudduration/2))) && second()<5) 
      {
        if (random(100)<20) lightningstatus=1; 
        else lightningstatus=0;
        if (lightningstatus)
        {
          DaylightPWMValue=100; 
          ActinicPWMValue=100;
        }
        else 
        {
          DaylightPWMValue=0;
          ActinicPWMValue=0;
        }
        delay(1);
      }
    }
    if (NumMins(hour(),minute())>(cloudstart+cloudduration))
    {
      cloudindex++;
      if (cloudindex < numclouds)
      {
        cloudstart=random(Start_Cloud_After+(((End_Cloud_Before-Start_Cloud_After)/(numclouds*2))*cloudindex*2),(Start_Cloud_After+(((End_Cloud_Before-Start_Cloud_After)/(numclouds*2))*cloudindex*2))+((End_Cloud_Before-Start_Cloud_After)/(numclouds*2)));
        // pick a random number for the cloud duration of first cloud.
        cloudduration=random(Min_Cloud_Duration,Max_Cloud_Duration);
        //Pick a random number between 0 and 99
        lightningchance=random(100);
        // if picked number is greater than Lightning_Change_per_Cloud, we will not have lightning today
        if (lightningchance>Lightning_Change_per_Cloud) lightningchance=0;
      }
    }
  }

  if (LastNumMins!=NumMins(hour(),minute()))
  {
    LastNumMins=NumMins(hour(),minute());
    ReefAngel.LCD.Clear(255,0,113,132,121);
    ReefAngel.LCD.DrawText(0,255,12,113,"C");
    ReefAngel.LCD.DrawText(0,255,18,113,"00:00");
    ReefAngel.LCD.DrawText(0,255,52,113,"L");
    ReefAngel.LCD.DrawText(0,255,58,113,"00:00");
    ReefAngel.LCD.DrawText(0,255,93,113,"DUR");
    if (cloudchance && (NumMins(hour(),minute())<cloudstart))
    {
      int x=0;
      if ((cloudstart/60)>=10) x=18; 
      else x=24;
      ReefAngel.LCD.DrawText(0,255,x,113,(cloudstart/60));
      if ((cloudstart%60)>=10) x=36; 
      else x=42;
      ReefAngel.LCD.DrawText(0,255,x,113,(cloudstart%60));
    }
    ReefAngel.LCD.DrawText(0,255,114,113,cloudduration);
    if (lightningchance) 
    {
      int x=0;
      if (((cloudstart+(cloudduration/2))/60)>=10) x=88; 
      else x=94;
      ReefAngel.LCD.DrawText(0,255,x,113,((cloudstart+(cloudduration/2))/60));
      if (((cloudstart+(cloudduration/2))%60)>=10) x=109; 
      else x=112;
      ReefAngel.LCD.DrawText(0,255,x,113,((cloudstart+(cloudduration/2))%60));
    }
  }   
}

byte ReversePWMSlope(long cstart,long cend,byte PWMStart,byte PWMEnd, byte clength)
{
  long n=elapsedSecsToday(now());
  cstart*=60;
  cend*=60;
  if (n<cstart) return PWMStart;
  if (n>=cstart && n<=(cstart+clength)) return map(n,cstart,cstart+clength,PWMStart,PWMEnd);
  if (n>(cstart+clength) && n<(cend-clength)) return PWMEnd;
  if (n>=(cend-clength) && n<=cend) return map(n,cend-clength,cend,PWMEnd,PWMStart);
  if (n>cend) return PWMStart;
  //End Cloud & Lighting 
}

// Moon Calculators - Thanks Deckoz2302!
int JulianDate(int d, int m, int y)
{ 
  int mm, yy;
  int k1, k2, k3;
  int j;

  yy = y - (int)((12 - m) / 10);
  mm = m + 9;
  if (mm >= 12)
  {
    mm = mm - 12;
  }
  k1 = (int)(365.25 * (yy + 4712));
  k2 = (int)(30.6001 * mm + 0.5);
  k3 = (int)((int)((yy / 100) + 49) * 0.75) - 38;
  // 'j' for dates in Julian calendar:
  j = k1 + k2 + d + 59;
  if (j > 2299160)
  {
    // For Gregorian calendar:
    j = j - k3; // 'j' is the Julian date at 12h UT (Universal Time)
  }
  return j;
}

double MoonAge(int d, int m, int y)
{ 
  int j = JulianDate(d, m, y);
  //Calculate the approximate phase of the moon
  int ip = (j + 4.867) / 29.53059;
  ip = ip - abs(ip); 
  //After several trials I've seen to add the following lines, 
  //which gave the result was not bad 
  if(ip < 0.5)
    int ag = ip * 29.53059 + 29.53059 / 2;
  else
    int ag = ip * 29.53059 - 29.53059 / 2;
  // Moon's age in days
  byte ag = abs(ag) + 1;
  return ag;
}

byte MoonState(byte D)
{
  switch(D){
  case 1: 
    0, 29;
    ThisPhase = 0;
  case 2: 
    1, 2, 3, 4, 5, 6;
    ThisPhase = 1;
  case 3: 
    7;
    ThisPhase = 2;
  case 4: 
    8, 9, 10, 11, 12, 13;
    ThisPhase = 3;
  case 5: 
    14;
    ThisPhase = 4;
  case 6: 
    15, 16, 17, 18, 19, 20, 21;
    ThisPhase = 5;
  case 7: 
    22;
    ThisPhase = 6;
  case 8: 
    23, 24, 25, 26, 27, 28;
    ThisPhase = 7;
  default: 
    return 0;
  }
}
I really don't want to give anything up. Any suggestions?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: v0.9.0 Libraries

Post by rimai »

Sounds like you need to upgrade to RA+ or keep the old libraries :(
Roberto.
User avatar
jsclownfish
Posts: 378
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: v0.9.0 Libraries

Post by jsclownfish »

Could you move the code for the moon phase to the PWM expansion and just send the result to the main to free up space?
bigHUN
Posts: 97
Joined: Sat Dec 03, 2011 9:41 pm

new Libraries

Post by bigHUN »

is this a coincident ??? I had a first internal memory upgrade and my first RA generator upload.
now I want to start playing with some manual editing, created a first code, compile, and shoots me back the error "com4 is in use by an other program, close it first.... unplug the cable several times, even I log out and back again, same error.
what this could be?
rossbryant1956
Posts: 471
Joined: Sat Jan 14, 2012 2:08 pm
Location: Montgomery Village, MD

Re: v0.9.0 Libraries

Post by rossbryant1956 »

You have the listeners running from the the client app. Either go into the client, click on service dash, and stop the listeners. If that doesn't work I have also gone into task manager and found the services running there. Try that. Thx
Roscoe's Reefs - Starting Over Again:

Building new 29g Nano after landlord went berserk over my 4 75 gallon tanks, Multiple RA's, Water mixing stations, etc. Your help welcomed in remembering all I've forgotten.
bigHUN
Posts: 97
Joined: Sat Dec 03, 2011 9:41 pm

Re: v0.9.0 Libraries

Post by bigHUN »

rossbryant1956 wrote:You have the listeners running from the the client app. ...
couple days ago I had them both running w/o issue, will try this one now....
the listener was stop, but the logger was running, when I stop that one as well, saved, and the error:
"unhandled exception has occured in your application....blablabla...Im running XPsp3 if this helps
aranax
Posts: 120
Joined: Thu Jun 02, 2011 11:54 pm

Re: v0.9.0 Libraries

Post by aranax »

Hey guys,
I just updated (everything installed fine) but I'm having errors compiling. I ran the newest RAGen just to see the code then tried to verify the code RAGen created and I got this error:

Code: Select all

C:\Documents and Settings\jfolder\My Documents\Arduino\libraries\DS1307RTC\DS1307RTC.cpp: In static member function 'static void DS1307RTC::read(tmElements_t&)':
C:\Documents and Settings\jfolder\My Documents\Arduino\libraries\DS1307RTC\DS1307RTC.cpp:56: error: 'class TwoWire' has no member named 'write'
C:\Documents and Settings\jfolder\My Documents\Arduino\libraries\DS1307RTC\DS1307RTC.cpp:65: error: 'class TwoWire' has no member named 'read'
C:\Documents and Settings\jfolder\My Documents\Arduino\libraries\DS1307RTC\DS1307RTC.cpp:66: error: 'class TwoWire' has no member named 'read'
C:\Documents and Settings\jfolder\My Documents\Arduino\libraries\DS1307RTC\DS1307RTC.cpp:67: error: 'class TwoWire' has no member named 'read'
C:\Documents and Settings\jfolder\My Documents\Arduino\libraries\DS1307RTC\DS1307RTC.cpp:68: error: 'class TwoWire' has no member named 'read'
C:\Documents and Settings\jfolder\My Documents\Arduino\libraries\DS1307RTC\DS1307RTC.cpp:69: error: 'class TwoWire' has no member named 'read'
C:\Documents and Settings\jfolder\My Documents\Arduino\libraries\DS1307RTC\DS1307RTC.cpp:70: error: 'class TwoWire' has no member named 'read'
C:\Documents and Settings\jfolder\My Documents\Arduino\libraries\DS1307RTC\DS1307RTC.cpp:71: error: 'class TwoWire' has no member named 'read'
C:\Documents and Settings\jfolder\My Documents\Arduino\libraries\DS1307RTC\DS1307RTC.cpp: In static member function 'static void DS1307RTC::write(tmElements_t&)':
C:\Documents and Settings\jfolder\My Documents\Arduino\libraries\DS1307RTC\DS1307RTC.cpp:87: error: 'class TwoWire' has no member named 'write'
C:\Documents and Settings\jfolder\My Documents\Arduino\libraries\DS1307RTC\DS1307RTC.cpp:88: error: 'class TwoWire' has no member named 'write'
C:\Documents and Settings\jfolder\My Documents\Arduino\libraries\DS1307RTC\DS1307RTC.cpp:89: error: 'class TwoWire' has no member named 'write'
C:\Documents and Settings\jfolder\My Documents\Arduino\libraries\DS1307RTC\DS1307RTC.cpp:90: error: 'class TwoWire' has no member named 'write'
C:\Documents and Settings\jfolder\My Documents\Arduino\libraries\DS1307RTC\DS1307RTC.cpp:91: error: 'class TwoWire' has no member named 'write'
C:\Documents and Settings\jfolder\My Documents\Arduino\libraries\DS1307RTC\DS1307RTC.cpp:92: error: 'class TwoWire' has no member named 'write'
C:\Documents and Settings\jfolder\My Documents\Arduino\libraries\DS1307RTC\DS1307RTC.cpp:93: error: 'class TwoWire' has no member named 'write'
C:\Documents and Settings\jfolder\My Documents\Arduino\libraries\DS1307RTC\DS1307RTC.cpp:94: error: 'class TwoWire' has no member named 'write'
Can someone please help? Thanks.

-J
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: v0.9.0 Libraries

Post by rimai »

It seems you still have some old libraries remaining on your system.
I suggest you rename the folder libraries to some other name and either install the installer or use the update utility
Roberto.
psyrob
Posts: 247
Joined: Thu Sep 01, 2011 8:44 pm

Re: v0.9.0 Libraries

Post by psyrob »

I had the same error messages...I deleted EVERYTHING, RAGen I had to delete twice, and I still had to use the example code to upload an internal memory before I got it to work....patience and persistence...
Image
aranax
Posts: 120
Joined: Thu Jun 02, 2011 11:54 pm

Re: v0.9.0 Libraries

Post by aranax »

BTW...what happened to the storm code? I had remove it from my PDE to get it to fit but the menu option to mess with it is not in the "new" features.h file? Is that function no longer being supported? Thanks.

-J
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: v0.9.0 Libraries

Post by rimai »

The storm code was never in the features file.
Roberto.
projectx
Posts: 120
Joined: Sat Apr 23, 2011 6:53 pm

Re: v0.9.0 Libraries

Post by projectx »

What is the proper way to list the relay expansion ports in the lighting, feed mode etc?
Image
projectx
Posts: 120
Joined: Sat Apr 23, 2011 6:53 pm

Re: v0.9.0 Libraries

Post by projectx »

I think I figured it out
ReefAngel.FeedingModePorts = Port1Bit | Port3Bit;
ReefAngel.FeedingModePortsE[0] = Port3Bit | Port4Bit;
ReefAngel.WaterChangePorts = Port1Bit | Port3Bit | Port5Bit | Port7Bit | Port8Bit;
ReefAngel.WaterChangePortsE[0] = Port3Bit | Port4Bit;
ReefAngel.OverheatShutoffPorts = Port2Bit | Port4Bit | Port6Bit;
ReefAngel.LightsOnPorts = Port2Bit | Port4Bit | Box0_Port1 | Box0_Port2;
ReefAngel.LightsOnPortsE[0] = Port1Bit | Port2Bit | Port5Bit | Port6Bit;
Image
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: v0.9.0 Libraries

Post by binder »

Yeah, that's "almost" right. You can only use PortXBit and not BoxX_PortY in them. So this line will not work properly:

Code: Select all

ReefAngel.LightsOnPorts = Port2Bit | Port4Bit | Box0_Port1 | Box0_Port2;
You will need to remove the Box0_Port1 & Box0_Port2 from the line.
projectx
Posts: 120
Joined: Sat Apr 23, 2011 6:53 pm

Re: v0.9.0 Libraries

Post by projectx »

This compiles without any errors, is this the proper way?
ReefAngel.FeedingModePorts = Port1Bit | Port3Bit;
ReefAngel.FeedingModePortsE[0] = Port3Bit | Port4Bit;
Image
lukeluke
Posts: 88
Joined: Mon Apr 04, 2011 4:12 am
Location: Rome, Italy

Re: v0.9.0 Libraries

Post by lukeluke »

binder wrote: [*]DosingPumpRepeat also has an offset from the run time now. So you can have your dosing pump run 5 minutes later if you like. This way you can have the pumps repeat every 4 hours and have one be 5 or 10 minutes later than the other, to prevent dosing at the same time.

Code: Select all

ReefAngel.DosingPumpRepeat(byte DPRelay, int OffsetMinute, int RepeatMinute, byte RunTime);
(This is not in RAGen)
the max repeat time is 4 hour ?
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: v0.9.0 Libraries

Post by binder »

lukeluke wrote:the max repeat time is 4 hour ?
No. I was just using that as an example for repeat. The maximum number for repeat is 32767 minutes. That is well above 4 hours. It will work if you exceed 24 hours (1440 minutes).
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: v0.9.0 Libraries

Post by binder »

projectx wrote:This compiles without any errors, is this the proper way?
ReefAngel.FeedingModePorts = Port1Bit | Port3Bit;
ReefAngel.FeedingModePortsE[0] = Port3Bit | Port4Bit;
Yeah, that's the "preferred" way with 0.9.X libraries. The reason is that it's more "human readable" and easier to understand. You could put it in terms of the 0's & 1's but that's just a little harder to read.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: v0.9.0 Libraries

Post by rimai »

int RepeatMinute variable can handle 32768 minutes.
Roberto.
rossbryant1956
Posts: 471
Joined: Sat Jan 14, 2012 2:08 pm
Location: Montgomery Village, MD

Re: v0.9.0 Libraries

Post by rossbryant1956 »

projectx wrote: ReefAngel.FeedingModePortsE[0] = Port3Bit | Port4Bit;
What is this syntax? E[0]

Haven't seen that before. Thx
Roscoe's Reefs - Starting Over Again:

Building new 29g Nano after landlord went berserk over my 4 75 gallon tanks, Multiple RA's, Water mixing stations, etc. Your help welcomed in remembering all I've forgotten.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: v0.9.0 Libraries

Post by rimai »

E[0] is for expansion relay box.
You can have E[0] through E[7] to set the ports of all other expansion boxes.
Roberto.
projectx
Posts: 120
Joined: Sat Apr 23, 2011 6:53 pm

Re: v0.9.0 Libraries

Post by projectx »

Great Thanks just did a few comparisons from the old to the new, just have to learn the code, I have found that Notepad++ is great for making it readable vs notepad
Image
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: v0.9.0 Libraries

Post by binder »

projectx wrote:Great Thanks just did a few comparisons from the old to the new, just have to learn the code, I have found that Notepad++ is great for making it readable vs notepad
I love Notepad++ on windows. It works so much better than notepad. :)
projectx
Posts: 120
Joined: Sat Apr 23, 2011 6:53 pm

Re: v0.9.0 Libraries

Post by projectx »

So I have something thats amiss with my expansion relay. from the portal I am able to turn on n off my pumps, but with the new code they are not being turned on.
here is my INO file

// Autogenerated file by RAGen (v1.2.1.158), (02/20/2012 22:17)
// RA_022012_2217.ino
//
// This version designed for v0.9.0 or later

/* The following features are enabled for this File:
#define DirectTempSensor
#define wifi
#define RelayExp
#define InstalledRelayExpansionModules 1
#define SIMPLE_MENU
#define ENABLE_ATO_LOGGING
#define ENABLE_EXCEED_FLAGS
*/


#include <ReefAngel_Features.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 <RA_PWM.h>
#include <Timer.h>
#include <Memory.h>
#include <ReefAngel.h>


void setup()
{
ReefAngel.Init(); //Initialize controller

ReefAngel.FeedingModePorts = Port1Bit | Port3Bit;
ReefAngel.FeedingModePortsE[0] = Port3Bit | Port4Bit;
ReefAngel.WaterChangePorts = Port1Bit | Port3Bit | Port5Bit | Port7Bit | Port8Bit;
ReefAngel.WaterChangePortsE[0] = Port3Bit | Port4Bit;
ReefAngel.OverheatShutoffPorts = Port2Bit | Port4Bit | Port6Bit;
ReefAngel.LightsOnPorts = Port2Bit | Port4Bit | Box0_Port1 | Box0_Port2;
ReefAngel.LightsOnPortsE[0] = Port1Bit | Port2Bit | Port5Bit | Port6Bit;

// Ports that are always on
ReefAngel.Relay.On(Port3);
ReefAngel.Relay.On(Port5);
ReefAngel.Relay.On(Box0_Port3);
ReefAngel.Relay.On(Box0_Port4);
ReefAngel.Relay.On(Box0_Port7);
ReefAngel.Relay.On(Box0_Port8);
}

void loop()
{
// Specific functions
ReefAngel.SingleATOLow(Port1);
ReefAngel.StandardLights(Port2);
ReefAngel.StandardLights(Box0_Port1, 21, 0, 7, 0);
ReefAngel.StandardLights(Box0_Port2, 7, 0, 20, 0);
ReefAngel.MHLights(Box0_Port5);
ReefAngel.MHLights(Box0_Port6);
ReefAngel.MHLights(Port4);
ReefAngel.StandardHeater(Port6);
ReefAngel.DosingPump1(Port7);
ReefAngel.DosingPump2(Port8);
;

ReefAngel.ShowInterface();
}
Image
projectx
Posts: 120
Joined: Sat Apr 23, 2011 6:53 pm

Re: v0.9.0 Libraries

Post by projectx »

I have real problems now, my ATO is staying on all of the time, I stripped out all of the expansion box items as it started to happen when my moon lights (box0_port1) were scheduled to come on.

I repushed the code and it is still on, thankfully i was sitting there when it did it so i was able to pull the plug on the pump before I had a mess to clean up.

Any ideas?
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: v0.9.0 Libraries

Post by rimai »

The ATO is because your code is should use Box1_ instead of Box0_
Box0_ refers to the main relay box.
The Dosing pump is because there was a bug that was fixed today.
Please download the latest libraries using the update utility.
http://www.reefangel.com/update
It was a premature move to update the dosing pump code and I had to return back to the original code.
Roberto.
Post Reply