Browse Source

Fix to break bootloops when PLAY_LAST_RFID_AFTER_REBOOT is active

master
Torsten Stauder 4 years ago
parent
commit
03f201b406
  1. 2
      src/Log.h
  2. 2
      src/LogMessages_DE.cpp
  3. 2
      src/LogMessages_EN.cpp
  4. 2
      src/logmessages.h
  5. 40
      src/main.cpp

2
src/Log.h

@ -1,5 +1,5 @@
#pragma once
#include "LogMessages.h"
#include "logmessages.h"
// Loglevels available (don't change!)
#define LOGLEVEL_ERROR 1 // only errors

2
src/LogMessages_DE.cpp

@ -192,5 +192,7 @@
const char playlistGenModeUncached[] PROGMEM = "Playlist-Generierung: uncached";
const char playlistGenModeCached[] PROGMEM = "Playlist-Generierung: cached";
const char playlistCacheFoundBut0[] PROGMEM = "Playlist-Cache-File gefunden, jedoch 0 Bytes groß";
const char bootLoopDetected[] PROGMEM = "Bootschleife erkannt! Letzte RFID wird nicht aufgerufen.";
const char noBootLoopDetected[] PROGMEM = "Keine Bootschleife erkannt. Wunderbar :-)";
#endif

2
src/LogMessages_EN.cpp

@ -192,5 +192,7 @@
const char playlistGenModeUncached[] PROGMEM = "Playlist-generation: uncached";
const char playlistGenModeCached[] PROGMEM = "Playlist-generation: cached";
const char playlistCacheFoundBut0[] PROGMEM = "Playlist-cache-file found but 0 bytes";
const char bootLoopDetected[] PROGMEM = "Bootloop detected! Last RFID won't be restored.";
const char noBootLoopDetected[] PROGMEM = "No bootloop detected. Great :-)";
#endif

2
src/logmessages.h

@ -188,3 +188,5 @@ extern const char warningRefactoring[];
extern const char playlistGenModeUncached[];
extern const char playlistGenModeCached[];
extern const char playlistCacheFoundBut0[];
extern const char bootLoopDetected[];
extern const char noBootLoopDetected[];

40
src/main.cpp

@ -26,6 +26,9 @@
#ifdef PLAY_LAST_RFID_AFTER_REBOOT
bool recoverLastRfid = true;
bool recoverBootCount = true;
bool resetBootCount = false;
uint32_t bootCount = 0;
#endif
////////////
@ -42,8 +45,40 @@
#endif
#ifdef PLAY_LAST_RFID_AFTER_REBOOT
// If a problem occurs, remembering last rfid can lead into a boot loop that's hard to escape of.
// That reason for a mechanism is necessary to prevent this.
// At start of a boot, bootCount is incremented by one and after 30s decremented because
// uptime of 30s is considered as "successful boot".
void recoverBootCountFromNvs(void) {
if (recoverBootCount) {
recoverBootCount = false;
resetBootCount = true;
bootCount = gPrefsSettings.getUInt("bootCount", 999);
if (bootCount == 999) { // first init
bootCount = 1;
gPrefsSettings.putUInt("bootCount", bootCount);
} else if (bootCount >= 3) { // considered being a bootloop => don't recover last rfid!
bootCount = 1;
gPrefsSettings.putUInt("bootCount", bootCount);
gPrefsSettings.putString("lastRfid", "-1"); // reset last rfid
Log_Println((char *) FPSTR(bootLoopDetected), LOGLEVEL_ERROR);
recoverLastRfid = false;
} else { // normal operation
gPrefsSettings.putUInt("bootCount", ++bootCount);
}
}
if (resetBootCount && millis() >= 30000) { // reset bootcount
resetBootCount = false;
bootCount = 0;
gPrefsSettings.putUInt("bootCount", bootCount);
Log_Println((char *) FPSTR(noBootLoopDetected), LOGLEVEL_INFO);
}
}
// Get last RFID-tag applied from NVS
void recoverLastRfidPlayed(void) {
void recoverLastRfidPlayedFromNvs(void) {
if (recoverLastRfid) {
if (System_GetOperationMode() == OPMODE_BLUETOOTH) { // Don't recover if BT-mode is desired
recoverLastRfid = false;
@ -220,7 +255,8 @@ void loop() {
Rfid_PreferenceLookupHandler();
#ifdef PLAY_LAST_RFID_AFTER_REBOOT
recoverLastRfidPlayed();
recoverBootCountFromNvs();
recoverLastRfidPlayedFromNvs();
#endif
IrReceiver_Cyclic();

Loading…
Cancel
Save