EEprom variable problem

Support forum for MegunoLink
Post Reply
Posts: 1
Joined: Sun Nov 07, 2021 7:57 pm

Sun Nov 07, 2021 8:29 pm

I just started with MegUnoLink and I really likke it's potential but I run in to a EEprom problem.

So I have this EEprom struct

Code: Select all

//EEPROM Storage
struct DecoderSettings
  int wrongAnswerPenalty; 
  static volatile int countDownClock;
  void Reset()
    int wrongAnswerPenalty = 0; //Number of minutes to penalise teams for wrong answer (0 = no penalty, 1 = 1 minute penalty) 
    static volatile int countDownClock = 1200;  //Time in seconds (3300 = 55 minutes, 2700 = 45 minutes)


EEPROMStore<DecoderSettings> DecoderConfig;
And this my GET function:

Code: Select all

//Command Handler
CommandHandler<> SerialCommandHandler;
void Cmd_GetDecoderValues(CommandParameter &Parameters)
  Parameters.GetSource().print(F("Aantal strafminuten = "));

  Parameters.GetSource().print(F("Timer = "));
Now the thing is this. Both int variables in the struct were Global Variables at first but because I wanted to use EEprom I had tot put them in the struct. So they are not global anymore and I got the "OUT OF SCOPE" error.
So my solution was simple. I took DecoderConfig.Data.wrongAnswerPenalty from the GET function and put that in place of the variable like this

Before using EEprom with Global Variable

Code: Select all

        //Apply penalty for incorrect answers (may be no penalty if wrongAnswerPenalty = 0)
        countDownClock -= wrongAnswerPenalty * 60);
        if(countDownClock< 0){
          countDownClock = 0;

Now while using EEprom with variable in struct:

Code: Select all

        //Apply penalty for incorrect answers (may be no penalty if wrongAnswerPenalty = 0)
        countDownClock -= (DecoderConfig.Data.wrongAnswerPenalty * 60);
        if(countDownClock< 0){
          countDownClock = 0;
This works fine. And when using the MegUnoLink Interface I can als use the SET and GET buttons to change and see the variable in the EEprom.

I tried to do the same with the second variable countDownClock.

But now if I use the Interface the GET button only shows GETDecoderValues in the serialmonitor but no values....
So while I don't get any errors, I'm not even sure what values the EEprom holds for those variables..

My questions are :
What is the best way to put the Eeprom value in to my code as a variable (substituting the previous Global variable)?
Why doesn't the GET button show the values on the serial monitor while SET still seems to work?
What is the best way to save multiple values from the Interface in to EEprom with just one button?

Thank you already!
Posts: 401
Joined: Mon May 26, 2014 10:58 am

Mon Dec 06, 2021 9:05 am

We believe the problem is the static keyword in the first code box. Remove both and it should solve the problem.

My colleague also said
Saving and loading may not respect the volatile definition. So he should turn off interrupts when saving/loading (assuming volatile because value is used in interrupt).

Post Reply