32
32
#define ADDR_SLEEPING 1023
33
33
34
34
#define PRESS_DELAY 100
35
- /* #define SHORT_HOLD 1000 */
36
- /* #define LONG_HOLD 2000 */
37
- /* #define VERY_LONG_HOLD 6000 */
38
35
#define SHORT_HOLD 500
39
36
#define LONG_HOLD 1000
40
37
#define VERY_LONG_HOLD 3000
@@ -256,6 +253,7 @@ void setup() {
256
253
attachInterrupt (0 , pushInterrupt, FALLING);
257
254
258
255
if (EEPROM.read (ADDR_SLEEPING)) {
256
+ while (!eeprom_is_ready ());
259
257
EEPROM.update (ADDR_SLEEPING, 0 );
260
258
LowPower.powerDown (SLEEP_FOREVER, ADC_OFF, BOD_ON);
261
259
button_state = new_state = S_SLEEP_WAKE;
@@ -474,6 +472,7 @@ void handlePress(bool pressed) {
474
472
flash (128 , 128 , 128 , 5 );
475
473
new_state = S_PLAY_SLEEP_WAIT;
476
474
} else if (!pressed) {
475
+ while (!eeprom_is_ready ());
477
476
EEPROM.update (ADDR_LOCKED, 1 );
478
477
enterSleep ();
479
478
}
@@ -651,6 +650,7 @@ void handlePress(bool pressed) {
651
650
new_state = S_BUNDLE_EDIT_WAIT;
652
651
} else if (!pressed) {
653
652
flash (128 , 128 , 128 , 5 );
653
+ while (!eeprom_is_ready ());
654
654
EEPROM.update (ADDR_CUR_BUNDLE, cur_bundle);
655
655
new_state = S_PLAY_OFF;
656
656
}
@@ -713,6 +713,7 @@ void handlePress(bool pressed) {
713
713
if (since_trans == VERY_LONG_HOLD) flash (0 , 128 , 0 , 5 );
714
714
if (!pressed) {
715
715
if (since_trans > VERY_LONG_HOLD) {
716
+ while (!eeprom_is_ready ());
716
717
EEPROM.update (ADDR_LOCKED, 0 );
717
718
new_state = S_PLAY_OFF;
718
719
} else {
@@ -784,6 +785,7 @@ void handlePress(bool pressed) {
784
785
flash (128 , 128 , 128 , 1 );
785
786
flash (0 , 128 , 0 , 1 );
786
787
flash (128 , 128 , 128 , 1 );
788
+ while (!eeprom_is_ready ());
787
789
saveMode (cur_mode_idx);
788
790
new_state = S_PLAY_OFF;
789
791
break ;
@@ -794,6 +796,7 @@ void handlePress(bool pressed) {
794
796
flash (128 , 128 , 128 , 1 );
795
797
flash (0 , 0 , 128 , 1 );
796
798
flash (128 , 128 , 128 , 1 );
799
+ while (!eeprom_is_ready ());
797
800
saveBundles ();
798
801
new_state = S_PLAY_OFF;
799
802
break ;
@@ -826,6 +829,7 @@ void handlePress(bool pressed) {
826
829
void enterSleep () {
827
830
writeFrame (0 , 0 , 0 );
828
831
accelStandby ();
832
+ while (!eeprom_is_ready ());
829
833
EEPROM.update (ADDR_SLEEPING, 1 );
830
834
digitalWrite (PIN_LDO, LOW);
831
835
delay (64000 );
@@ -896,6 +900,7 @@ void loadBundles() {
896
900
}
897
901
898
902
void resetMemory () {
903
+ while (!eeprom_is_ready ());
899
904
clearMemory ();
900
905
initModes ();
901
906
saveModes ();
0 commit comments