loadState in 2.3.2 is not a happy function....
-
I am trying to get another node done and using saveState and loadState in the node for power cut recovery.
Although I can get saveState to work in the receive function (wasn't expecting that to complie I must admit), whenever I try to loadState in setup I get an error like this.....
Arduino: 1.8.9 (Windows 10), Board: "Arduino Pro or Pro Mini, ATmega328P (5V, 16 MHz)"
WARNING: Spurious .ci folder in 'MySensors' library
WARNING: Spurious .mystools folder in 'MySensors' library
C:\Users\captain\Documents\Arduino\MYS-M_BED_LED-0.2\MYS-M_BED_LED-0.2.ino: In function 'void setup()':MYS-M_BED_LED-0.2:69:23: error: too many arguments to function 'uint8_t loadState(uint8_t)'
loadState(10, lights);
^
In file included from C:\Users\captain\Documents\Arduino\libraries\MySensors/MySensors.h:433:0,
from C:\Users\captain\Documents\Arduino\MYS-M_BED_LED-0.2\MYS-M_BED_LED-0.2.ino:32:
C:\Users\captain\Documents\Arduino\libraries\MySensors/core/MySensorsCore.cpp:550:9: note: declared here
uint8_t loadState(const uint8_t pos)
^~~~~~~~~
exit status 1
too many arguments to function 'uint8_t loadState(uint8_t)'This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.void setup() { Serial.begin(9600); // loadState(1, SOUND_Armed); // loadState(7, Auto_lights); loadState(10, lights); if (lights == 1) { newcodeRX == 1; code = 0xFFA25D; } irrecv.enableIRIn(); // Start the receiver LightMeter.begin(); wdt_enable(WDTO_8S); }
So I wonder why saveState(10, lights); compiles and loadState(10, lights); does not? What am I not knowing about this as I have not had this issue before.
-
Do
lights = loadState(10);
-
@hek You are a star!
That works as expected - so I guess that saveState should also have this construction.
Did this change recently or have I just been lucky doing it the way I originally had it?
-
It has always been like this. In order to do like you propose, you'd have to send in a pointer for the light variable into the function to be able to update it. This would be a bit awkward and none standard for simple scalar values.
-
Just tested this and my assumption was incorrect it seems (using arduino 1.8.9 and mysensors 2.3.2).....
Correct usage is......
lights = loadState(10); //to read value from eeprom to variable.
saveState(10, lights); //to write value from variable to eeprom.Now I got it!
-
@hek Thanks! Our posts crossed in the matrix!
I even got this right on a previous sketch, but a lot has been going on for me lately and I am finding it difficult to concentrate on things.