Skip to content

Commit

Permalink
fix(storage): fix flags and move mode loading to bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1p committed Apr 6, 2023
1 parent f53c460 commit e675489
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
1 change: 1 addition & 0 deletions include/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define ENABLE_SERVER

// disable if you do not want to use the internal storage
// https://randomnerdtutorials.com/esp32-save-data-permanently-preferences/
#define ENABLE_STORAGE

#ifdef ENABLE_SERVER
Expand Down
10 changes: 5 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ void setup()
pinMode(PIN_ENABLE, OUTPUT);
pinMode(PIN_BUTTON, INPUT_PULLUP);

Screen.clear();
loadMode();
Screen.loadFromStorage();

// server
#ifdef ENABLE_SERVER
// wifi
Expand All @@ -32,7 +28,7 @@ void setup()
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED && attempts < 7)
{
delay(500);
delay(2000);
Serial.print(".");
attempts++;
}
Expand All @@ -55,6 +51,10 @@ void setup()
initWebsocketServer(server);
initWebServer();
#endif

Screen.clear();
loadMode();
Screen.loadFromStorage();
}

void loop()
Expand Down
5 changes: 2 additions & 3 deletions src/mode/mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,9 @@ void loopOfAllModes()
}
}


void persistMode()
{
#ifdef STORAGE_ENABLED
#ifdef ENABLE_STORAGE
storage.begin("led-wall", false);
storage.putInt("mode", currentMode);
storage.end();
Expand All @@ -295,7 +294,7 @@ void persistMode()

void loadMode()
{
#ifdef STORAGE_ENABLED
#ifdef ENABLE_STORAGE
storage.begin("led-wall", false);
setMode((MODE)storage.getInt("mode"));
storage.end();
Expand Down
1 change: 0 additions & 1 deletion src/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ uint8_t Screen_::getBufferIndex(int index)

void Screen_::loadFromStorage()
{
// https://randomnerdtutorials.com/esp32-save-data-permanently-preferences/
#ifdef ENABLE_STORAGE
storage.begin("led-wall", false);
if (currentMode == NONE)
Expand Down

0 comments on commit e675489

Please sign in to comment.