From d0b0041a40656f8125d54d3987b661634d1a66d7 Mon Sep 17 00:00:00 2001 From: Dirk Jahnke Date: Fri, 7 Jun 2019 09:43:09 +0200 Subject: [PATCH] Make use of SimpleFS to init filesystem. --- src/DjSimpleFS.cpp | 3 +-- src/main.cpp | 33 ++++++++++----------------------- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/src/DjSimpleFS.cpp b/src/DjSimpleFS.cpp index d9d2c64..ed124e2 100644 --- a/src/DjSimpleFS.cpp +++ b/src/DjSimpleFS.cpp @@ -5,7 +5,7 @@ // // -#include +#include "DjSimpleFS.h" boolean SimpleFS::_initialized = false; FSInfo SimpleFS::fsInfo; @@ -76,4 +76,3 @@ size_t SimpleFS::getMaxPathLength() { } return fsInfo.maxPathLength; } - diff --git a/src/main.cpp b/src/main.cpp index 377621a..3aee4e0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,12 +3,8 @@ #include #include //https://github.com/esp8266/Arduino #include - -//needed for library #include -//#include #include - #include #include #include "DjDebug.h" @@ -17,6 +13,7 @@ #include "DjDebug.h" #include "ClockClient.h" #include "WebUI.h" +#include "DjSimpleFS.h" // NTP WiFiUDP ntpUDP; @@ -25,7 +22,6 @@ WiFiUDP ntpUDP; // update interval (in milliseconds, can be changed using setUpdateInterval() ). NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 7200, 60000); - static const char *appName = "FastclockClient7Seg"; const char * const PROGMEM mainConfig[] = { "appMode:string:" MODE_DEMO, @@ -42,6 +38,7 @@ SevenSegmentClock sevenSegmentClock(debug, config); ClockClient fastclockClient(debug, config); //ESP8266WebServer *server; WebUI *webUI; +SimpleFS filesystem(debug); //flag for saving data bool shouldSaveConfig = false; @@ -94,22 +91,12 @@ void setup() { debug.out(F("Reset reason: "), DEBUG_MIN_INFO); debug.outln(ESP.getResetReason(), DEBUG_MIN_INFO); - //clean FS, for testing - //SPIFFS.format(); - - //read configuration from FS json - debug.outln(F("mounting FS..."), DEBUG_MAX_INFO); - - if (SPIFFS.begin()) { - debug.outln(F("mounted file system"), DEBUG_MAX_INFO); - config.begin("main.cfg", mainConfig, sizeof(mainConfig)/sizeof(mainConfig[0])); - } else { - debug.outln(F("failed to mount FS"), DEBUG_ERROR); - config.begin("main.cfg", mainConfig, sizeof(mainConfig)/sizeof(mainConfig[0])); - } + filesystem.begin(); + config.begin("main.cfg", mainConfig, sizeof(mainConfig)/sizeof(mainConfig[0])); setupWifiConnection(); debug.outln(F("Starting NTP Client"), DEBUG_MAX_INFO); timeClient.begin(); + timeClient.setTimeOffset(config.getInt("utcTimeOffsetMinutes") * 60); debug.outln(F("Have following configuration:"), DEBUG_MAX_INFO); debug.out(F(" App Mode: "), DEBUG_MAX_INFO); debug.outln(config.getString("appMode"), DEBUG_MAX_INFO); @@ -118,7 +105,6 @@ void setup() { debug.out(F(" Clock listen port: "), DEBUG_MAX_INFO); debug.outln(config.getString("listenPort"), DEBUG_MAX_INFO); debug.out(F(" Real time UTC offset: "), DEBUG_MAX_INFO); debug.outln(config.getString("utcTimeOffsetMinutes"), DEBUG_MAX_INFO); - timeClient.setTimeOffset(config.getInt("utcTimeOffsetMinutes") * 60); debug.outln(F("Starting fastclock ..."), DEBUG_MAX_INFO); fastclock.begin(); @@ -127,14 +113,14 @@ void setup() { sevenSegmentClock.setBrightness(config.getInt("brightness")); sevenSegmentClock.setColor(sevenSegmentClock.getColorHandleByName(config.getString("clockColor"))); - // setting up web server for clock configuration - //server = new ESP8266WebServer(80); + // setting up web server for clock configuration; intentionally very late + // as we need the web server during boot to be able to connect to/configure WiFi webUI = new WebUI(debug, config, timeClient, fastclock, sevenSegmentClock); webUI->begin(); } -int hours = 0, minutes = 0; -uint32_t nextUpdate_ms = 0; +static int hours = 0, minutes = 0; +static uint32_t nextUpdate_ms = 0; void loop() { timeClient.update(); @@ -166,4 +152,5 @@ void loop() { sevenSegmentClock.displayUpdate(); webUI->loop(); + filesystem.loop(); }