Page 1 of 1

Transition from magic numbers in certain RA functions

Posted: Sun Apr 06, 2014 8:45 am
by MisterTang
With the recent announcement that the RA basic is being end-of-life'd, I'd like to recommend that some of the standard RA functionality be refactored to be more robust with the assumptions that the user will want to remote-control from a phone or the portal and will have enough memory to support the additional code.

For instance, the wizard uses static "magic numbers" when dimming parabolas etc are created and puts them in the "loop" section, which means (unless I'm mistaken) that you can't really override these values. I have started going through and writing a small library that makes the entire dimming module easier to both remote control, and to understand in the loop() section, so that my init() has items like this:

Code: Select all

    SetActinicLEDMax(90);
    SetActinicLEDMin(10);
    
    SetRedLEDMax(90);
    SetRedLEDMin(10);
    
    SetWhiteLEDMax(90);
    SetWhiteLEDMin(10);
    
    SetActinicLEDStartHour(09);
    SetActinicLEDStartMinute(30);
    
    SetRedLEDStartHour(10);
    SetRedLEDStartMinute(00);
    
    SetWhiteLEDStartHour(10);
    SetWhiteLEDStartMinute(00);
    
    
    SetActinicLEDEndHour(21);
    SetActinicLEDEndMinute(00);
    
    SetRedLEDEndHour(20);
    SetRedLEDEndMinute(00);
    
    SetWhiteLEDEndHour(20);
    SetWhiteLEDEndMinute(00);
    
    SetWhiteLEDDimmingParabolaRate(80);
    SetRedLEDDimmingParabolaRate(80);
    SetActinicLEDDimmingParabolaRate(60);
    
    //Pretty sure the RA inits with garbage in these, so we'll set the initial state to false (no override, operate in parabola mode) just to be certain
    OverrideNormalActinicLEDSettings(false);
    OverrideNormalRedLEDSettings(false);
    OverrideNormalWhiteLEDSettings(false);

And my loop() looks like this:

Code: Select all

    ReefAngel.PWM.SetChannel( 0, PWMSlope(GetActinicLEDStartHour(),GetActinicLEDStartMinute(),GetActinicLEDEndHour(),GetActinicLEDEndMinute(),GetActinicLEDMin(),GetActinicLEDMax(),GetActinicLEDDimmingParabolaRate(),GetActinicLEDMin()) );
    ReefAngel.PWM.SetChannel( 3, PWMSlope(GetActinicLEDStartHour(),GetActinicLEDStartMinute(),GetActinicLEDEndHour(),GetActinicLEDEndMinute(),GetActinicLEDMin(),GetActinicLEDMax(),GetActinicLEDDimmingParabolaRate(),GetActinicLEDMin()) );
It would also then allow the portal and various phone client devs to easily allow more fine-tuned control of dimming and variable-speed devices, instead of going into advanced menus and setting memory values manually.

Does this already exist and I'm reinventing the wheel? Or might it be a nice way to transition into demonstrating even more of the RA's awesome potential out of the box without having to have the user set memory values manually?

Re: Transition from magic numbers in certain RA functions

Posted: Sun Apr 06, 2014 9:09 am
by rimai
I'm not sure I understand the reason of what you did.
It seems to me that what you did is exactly what internal memory is doing.

Re: Transition from magic numbers in certain RA functions

Posted: Sun Apr 06, 2014 1:01 pm
by MisterTang
Will the wizard do that automatically? Does it use the 199-0 user-defined ranges? I guess all the examples I saw were in-code...

Re: Transition from magic numbers in certain RA functions

Posted: Sun Apr 06, 2014 3:55 pm
by rimai
I still didn't understand the question, but if you choose to use the wizard and you choose the internal memory settings, the generated code would be like this:

Code: Select all

ReefAngel.PWM.DaylightPWMParabola();
All the settings would be stored in internal memory.

Re: Transition from magic numbers in certain RA functions

Posted: Mon Apr 07, 2014 1:00 pm
by MisterTang
Yep, I think my problem was that I had only seen this before:

Code: Select all

ReefAngel.PWM.SetChannel( 1, PWMSlope(10,0,20,0,10,90,80,10) );
...and was trying to "fix" it.

Re: Transition from magic numbers in certain RA functions

Posted: Mon Apr 07, 2014 1:08 pm
by lnevo
A good place to look is in the file Globals/Global.h which has the definitions. There are also functions defined to read the variables so you a) don't have to remember the numbers b) if the numbers change, the function will get updated, c) don't have to write your own :) You can find the functions I think in InternalMemory/InternalMemory.h