EEprom variable problem
Posted: Sun Nov 07, 2021 8:29 pm
Hi,
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
And this my GET function:
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
Now while using EEprom with variable in struct:
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!
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;Code: Select all
//Command Handler
CommandHandler<> SerialCommandHandler;
void Cmd_GetDecoderValues(CommandParameter &Parameters)
{
Parameters.GetSource().print(F("Aantal strafminuten = "));
Parameters.GetSource().println(DecoderConfig.Data.wrongAnswerPenalty);
Parameters.GetSource().print(F("Timer = "));
Parameters.GetSource().println(DecoderConfig.Data.countDownClock);
}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;
}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!