30
30
31
31
#include < Wire.h>
32
32
33
- bool gPlayLastRfIdWhenWiFiConnected = false ;
34
- bool gTriedToConnectToHost = false ;
35
-
36
33
static constexpr const char *logo = R"literal(
37
34
_____ ____ ____ _
38
35
| ____| / ___| | _ \ _ _ (_) _ __ ___
@@ -49,13 +46,6 @@ bool testSPIRAM(void) {
49
46
return true ;
50
47
}
51
48
52
- #ifdef PLAY_LAST_RFID_AFTER_REBOOT
53
- bool recoverLastRfid = true ;
54
- bool recoverBootCount = true ;
55
- bool resetBootCount = false ;
56
- uint32_t bootCount = 0 ;
57
- #endif
58
-
59
49
// //////////
60
50
61
51
#if (HAL == 2)
@@ -75,49 +65,43 @@ TwoWire i2cBusTwo = TwoWire(1);
75
65
// At start of a boot, bootCount is incremented by one and after 30s decremented because
76
66
// uptime of 30s is considered as "successful boot".
77
67
void recoverBootCountFromNvs (void ) {
78
- if (recoverBootCount) {
79
- recoverBootCount = false ;
80
- resetBootCount = true ;
81
- bootCount = gPrefsSettings .getUInt (" bootCount" , 999 );
82
-
83
- if (bootCount == 999 ) { // first init
84
- bootCount = 1 ;
85
- gPrefsSettings .putUInt (" bootCount" , bootCount);
86
- } else if (bootCount >= 3 ) { // considered being a bootloop => don't recover last rfid!
87
- bootCount = 1 ;
88
- gPrefsSettings .putUInt (" bootCount" , bootCount);
89
- gPrefsSettings .putString (" lastRfid" , " -1" ); // reset last rfid
90
- Log_Println (bootLoopDetected, LOGLEVEL_ERROR);
91
- recoverLastRfid = false ;
92
- } else { // normal operation
93
- gPrefsSettings .putUInt (" bootCount" , ++bootCount);
94
- }
95
- }
68
+ uint32_t bootCount = gPrefsSettings .getUInt (" bootCount" , 999 );
96
69
97
- if (resetBootCount && millis () >= 30000 ) { // reset bootcount
98
- resetBootCount = false ;
99
- bootCount = 0 ;
70
+ if (bootCount == 999 ) { // first init
71
+ bootCount = 1 ;
100
72
gPrefsSettings .putUInt (" bootCount" , bootCount);
73
+ } else if (bootCount >= 3 ) { // considered being a bootloop => don't recover last rfid!
74
+ bootCount = 1 ;
75
+ gPrefsSettings .putUInt (" bootCount" , bootCount);
76
+ gPrefsSettings .remove (" lastRfid" ); // reset last rfid
77
+ Log_Println (bootLoopDetected, LOGLEVEL_ERROR);
78
+ } else { // normal operation
79
+ gPrefsSettings .putUInt (" bootCount" , ++bootCount);
80
+ }
81
+ }
82
+
83
+ void resetBootCount (void ) {
84
+ static bool wasReset = false ;
85
+
86
+ if (!wasReset && millis () >= 30000 ) { // reset bootcount
87
+ wasReset = true ;
88
+ gPrefsSettings .putUInt (" bootCount" , 0 );
101
89
Log_Println (noBootLoopDetected, LOGLEVEL_INFO);
102
90
}
103
91
}
104
92
105
93
// Get last RFID-tag applied from NVS
106
- void recoverLastRfidPlayedFromNvs (bool force) {
107
- if (recoverLastRfid || force) {
108
- if (System_GetOperationMode () == OPMODE_BLUETOOTH_SINK) { // Don't recover if BT-mode is desired
109
- recoverLastRfid = false ;
110
- return ;
111
- }
112
- recoverLastRfid = false ;
113
- String lastRfidPlayed = gPrefsSettings .getString (" lastRfid" , " -1" );
114
- if (!lastRfidPlayed.compareTo (" -1" )) {
115
- Log_Println (unableToRestoreLastRfidFromNVS, LOGLEVEL_INFO);
116
- } else {
117
- xQueueSend (gRfidCardQueue , lastRfidPlayed.c_str (), 0 );
118
- gPlayLastRfIdWhenWiFiConnected = !force;
119
- Log_Printf (LOGLEVEL_INFO, restoredLastRfidFromNVS, lastRfidPlayed.c_str ());
120
- }
94
+ void recoverLastRfidPlayedFromNvs () {
95
+ if (System_GetOperationMode () == OPMODE_BLUETOOTH_SINK) { // Don't recover if BT-mode is desired
96
+ return ;
97
+ }
98
+
99
+ String lastRfidPlayed = gPrefsSettings .getString (" lastRfid" , " -1" );
100
+ if (!lastRfidPlayed.compareTo (" -1" )) {
101
+ Log_Println (unableToRestoreLastRfidFromNVS, LOGLEVEL_INFO);
102
+ } else {
103
+ xQueueSend (gRfidCardQueue , lastRfidPlayed.c_str (), 0 );
104
+ Log_Printf (LOGLEVEL_INFO, restoredLastRfidFromNVS, lastRfidPlayed.c_str ());
121
105
}
122
106
}
123
107
#endif
@@ -240,6 +224,11 @@ void setup() {
240
224
#ifdef CONTROLS_LOCKED_BY_DEFAULT
241
225
System_SetLockControls (true );
242
226
#endif
227
+
228
+ #ifdef PLAY_LAST_RFID_AFTER_REBOOT
229
+ recoverBootCountFromNvs ();
230
+ recoverLastRfidPlayedFromNvs ();
231
+ #endif
243
232
}
244
233
245
234
void loop () {
@@ -269,8 +258,7 @@ void loop() {
269
258
Rfid_PreferenceLookupHandler ();
270
259
271
260
#ifdef PLAY_LAST_RFID_AFTER_REBOOT
272
- recoverBootCountFromNvs ();
273
- recoverLastRfidPlayedFromNvs ();
261
+ resetBootCount ();
274
262
#endif
275
263
276
264
IrReceiver_Cyclic ();
0 commit comments