Page 1 of 1

Where are the variables defined for the "memory" option?

Posted: Tue Apr 25, 2017 4:35 pm
by MisterTang
So one of the things I'm currently doing as I reboot tank is redo all of my RA code.

Previously, I had kept all the variables "in the code" as magic numbers, but this time around, I'd like the flexibility to change light timing and stuff like that remotely, so I built a new project with the "in memory" option.

The only problem is I don't see at all in the project/sketch where these values are even defined - I assumed they'd be defined as globals or something like that. I'm sure they must be SOMEwhere... just can't find them.

I'm specifically asking because I want my doser to run on a schedule that isn't my lighting schedule and isn't exactly opposite the lighting schedule either - and when I use the wizard, it doesn't allow me to set a second schedule. In general, I'd also like to be able to write code in the sketch that references in-memory values so everything is truly remotely-controllable.

I do recognize the potential implications of what I'm trying to do - namely, that the various RA apps expect the in-memory values to be situated at certain locations on the RA's stack equivalent. My intent is to add any custom variables after all of the RA pre-defined stuff to mitigate this issue.

Re: Where are the variables defined for the "memory" option?

Posted: Wed Apr 26, 2017 2:44 am
by cosmith71
You'll need to do something like this. I think memory locations 100-199 are available to use. Bytes, take 1 location, ints take 2, floats take 4. In globals:

Code: Select all

// Memory locations for adjusting dosing amounts.
#define Mem_B_AlkDosage      100
#define Mem_B_CalDosage      101 
#define Mem_B_Doses          102
#define Mem_B_DoserOffset    103
Then in your loop or in a subroutine read the value like this:

Code: Select all

 byte AlkDosage = InternalMemory.read(Mem_B_AlkDosage);    // Amount in ml of 2 part to dispense per day
  byte CalDosage = InternalMemory.read(Mem_B_CalDosage); 
Currently the easiest way to change values in custom locations is with the Reef Angel Status app.

--Colin

Re: Where are the variables defined for the "memory" option?

Posted: Wed Apr 26, 2017 4:52 am
by MisterTang
cosmith71 wrote:You'll need to do something like this. I think memory locations 100-199 are available to use. Bytes, take 1 location, ints take 2, floats take 4. In globals:

Code: Select all

// Memory locations for adjusting dosing amounts.
#define Mem_B_AlkDosage      100
#define Mem_B_CalDosage      101 
#define Mem_B_Doses          102
#define Mem_B_DoserOffset    103
Then in your loop or in a subroutine read the value like this:

Code: Select all

 byte AlkDosage = InternalMemory.read(Mem_B_AlkDosage);    // Amount in ml of 2 part to dispense per day
  byte CalDosage = InternalMemory.read(Mem_B_CalDosage); 
Currently the easiest way to change values in custom locations is with the Reef Angel Status app.

--Colin
Thanks Colin! This makes a lot of sense - but where are these defines for the values the wizard generates? I'd like to be able to reference those (ie one hour after 'lights off' value, start dosing etc).

Re: Where are the variables defined for the "memory" option?

Posted: Wed Apr 26, 2017 5:04 am
by cosmith71
They are in Globals.h in the libraries. If you have the Android app you can use that to get the memory locations for individual items as well.. They start at 200.

There are mnemonics for most of these too, but I don't know the location off the top of my head. Roberto may know off the top of his head, otherwise you'll have to dig through the libraries.

--Colin

Re: Where are the variables defined for the "memory" option?

Posted: Thu Apr 27, 2017 3:50 am
by MisterTang
So what I have so far:

Globals.h is where all the memory positions are defined.

EEProm.cpp is where all of the Get/Set functions are stored for these memory positions.

In "stored in memory" mode, Mem_B_StdLightsOn and Mem_B_StdLightsOff looks to be the only timer that you can define. When you use the wizard with the "stored in memory" option, all the times seem to be based on this one timer.

I'm going to start making some modifications to RF.cpp that will allow you to set an offset to each of the Radion channels based on the Mem_B_StdLights - namely, the number of minutes after StdLightsOn to start dimming certain channels, and the number of minutes before StdLightsOff to start dimming certain channels. I will store these as bytes, so I guess a max of 250 minutes after the lights turn on and 250 minutes before the lights turn off since bytes in this look to be unsigned. This mimics the functionality of the Ecotech program a little better, and would allow users to have the "all blue" period in the mornings and evenings.

I'm still not clear on where the Wizard is storing the user settings before they get uploaded to the Arduino, and that might be helpful to know. And maybe also how to make the graphical changes to the Wizard.

Re: Where are the variables defined for the "memory" option?

Posted: Wed May 03, 2017 8:30 am
by binder
have you figured out what you were wanting to do? I have a couple ideas and suggestions for you but cannot respond fully right now from my phone.

Sent from my XT1585 using Tapatalk

Re: Where are the variables defined for the "memory" option?

Posted: Fri May 05, 2017 4:04 am
by MisterTang
binder wrote:have you figured out what you were wanting to do? I have a couple ideas and suggestions for you but cannot respond fully right now from my phone.

Sent from my XT1585 using Tapatalk
I still need to figure out where the values specified by the user in the wizard are ultimately defined.

Simply put, it doesn't feel like there is enough flexibility with the current wizard and on/off schedules and I'd like to change some of that for my setup. I can't be the only person who has run into this - I suspect other people are just hard-coding the values into code, which necessitates a recompile any time you want to change something.

Re: Where are the variables defined for the "memory" option?

Posted: Fri May 05, 2017 4:07 am
by binder
ok. i will have a chance later today to respond in more detail for you.

Sent from my XT1585 using Tapatalk

Re: Where are the variables defined for the "memory" option?

Posted: Fri May 05, 2017 8:13 pm
by binder
MisterTang wrote: I'm going to start making some modifications to RF.cpp that will allow you to set an offset to each of the Radion channels based on the Mem_B_StdLights - namely, the number of minutes after StdLightsOn to start dimming certain channels, and the number of minutes before StdLightsOff to start dimming certain channels. I will store these as bytes, so I guess a max of 250 minutes after the lights turn on and 250 minutes before the lights turn off since bytes in this look to be unsigned. This mimics the functionality of the Ecotech program a little better, and would allow users to have the "all blue" period in the mornings and evenings.

I'm still not clear on where the Wizard is storing the user settings before they get uploaded to the Arduino, and that might be helpful to know. And maybe also how to make the graphical changes to the Wizard.
I would discourage against modifying the system libraries. The reason is if you ever updated the libraries, your modifications and changes would be lost. This could happen accidentally, even if you are being careful.

The wizard generates the internal memory values and creates its own sketch and uploads it to the controller. It creates it on the fly and uploads it to the controller. It does not save the sketch file. Once the controller reads, "Memory Updates, You can now upload your INO code", your memory is already updated with the values. Then you would continue with the wizard to upload your INO (sketch) for the controller to run your code.

Now, if you are wanting to modify or adapt a function, I would suggest using the long form of the functions. The functions that utilize the internal memory just reference the long forms. The shortened form, which they use, is much "cleaner" and easier to read in your sketch file.
Here's an example to show you. The StandardLights function is what I will show (since you are discussing it).
The "shortened" version of it that uses the internal memory is this:

Code: Select all

// Only using a port
ReefAngel.StandardLights(Port1);
// OR
// Using a Port with a minute offset
ReefAngel.StandardLights(Port1, 5);
Now, these 2 functions just simply call the long version of the StandardLights function. Here's that function:

Code: Select all

ReefAngel.StandardLights(Port1,
    InternalMemory.StdLightsOnHour_read(),
    InternalMemory.StdLightsOnMinute_read(),
    InternalMemory.StdLightsOffHour_read(),
    InternalMemory.StdLightsOffMinute_read());
So, as you can see, you just call the memory functions to fill in the variables for the proper values.

Now, if you want to have your own function that varies the time from the standard lights function, you could do something like I used to do. Here is the code that I used to turn on Port8 one hour after the lights come on and shut off one hour before the lights go off.

Code: Select all

ReefAngel.StandardLights(Port8,
    InternalMemory.StdLightsOnHour_read()+1,
    InternalMemory.StdLightsOnMinute_read(),
    InternalMemory.StdLightsOffHour_read()-1,
    InternalMemory.StdLightsOffMinute_read());
If you wanted to be able to change the offset in that function, you could just have a function read from internal memory for you. You would need to define a memory location. Then create the memory function to read the location. Use that function in the above function in place of my hard coded value.

This should hopefully be a start for you and help you figure things out a little more.
Now, if you had a start of what you want to do, we can continue to code it. It shouldn't be too complicated to figure out and setup.

Re: Where are the variables defined for the "memory" option?

Posted: Wed May 10, 2017 6:35 am
by MisterTang
Thanks for the ideas, binder.

You're probably right re: making changes to system libraries. I may end up having to extend them or something.

I'm still fiddling with the RF module with my Radion but making good progress. I'll post some code later next week.

Re: Where are the variables defined for the "memory" option?

Posted: Wed May 10, 2017 7:20 pm
by binder
MisterTang wrote:Thanks for the ideas, binder.

You're probably right re: making changes to system libraries. I may end up having to extend them or something.

I'm still fiddling with the RF module with my Radion but making good progress. I'll post some code later next week.
it's not going to be hard to do what you want. it will take some time but not be hard. we have tried hard to simplify things and make it easy to extend code and have great control over it.

i'd be happy to help you get your code up and running.


Sent from my iPad using Tapatalk