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

Do you have a question on how to do something.
Ask in here.

Posts: 58
Joined: Sat Jan 04, 2014 3:12 pm
PostPosted: Tue Apr 25, 2017 4:35 pm
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.
Image
User avatar
Posts: 1426
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City
PostPosted: Wed Apr 26, 2017 2:44 am
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

Posts: 58
Joined: Sat Jan 04, 2014 3:12 pm
PostPosted: Wed Apr 26, 2017 4:52 am
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).
Image
User avatar
Posts: 1426
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City
PostPosted: Wed Apr 26, 2017 5:04 am
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

Posts: 58
Joined: Sat Jan 04, 2014 3:12 pm
PostPosted: Thu Apr 27, 2017 3:50 am
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.
Image
User avatar
Posts: 2732
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
PostPosted: Wed May 03, 2017 8:30 am
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

Posts: 58
Joined: Sat Jan 04, 2014 3:12 pm
PostPosted: Fri May 05, 2017 4:04 am
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.
Image
User avatar
Posts: 2732
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
PostPosted: Fri May 05, 2017 4:07 am
ok. i will have a chance later today to respond in more detail for you.

Sent from my XT1585 using Tapatalk
User avatar
Posts: 2732
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
PostPosted: Fri May 05, 2017 8:13 pm
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.

Posts: 58
Joined: Sat Jan 04, 2014 3:12 pm
PostPosted: Wed May 10, 2017 6:35 am
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.
Image
Next

Return to How do I code ...

Who is online

Users browsing this forum: No registered users and 3 guests