diff --git a/data b/data index 4f15eee..2a7ba58 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 4f15eee72bcd3873a0edb61bc77638a0ff5e3724 +Subproject commit 2a7ba588e2ab06d433e9ac3f6882bfd4a7f714fe diff --git a/scripts/git_rev.py b/scripts/git_rev.py index 9594475..33fd8cc 100644 --- a/scripts/git_rev.py +++ b/scripts/git_rev.py @@ -5,4 +5,17 @@ revision = ( .strip() .decode("utf-8") ) -print("'-DGIT_REV=\"%s\"'" % revision) \ No newline at end of file + +try: + tag = ( + subprocess.check_output(["git", "describe", "--tags", "--exact-match"]) + .strip() + .decode("utf-8") + ) + git_tag_define = '-DGIT_TAG="%s"' % tag +except subprocess.CalledProcessError: + git_tag_define = '' + +print("'-DGIT_REV=\"%s\"'" % revision) +if git_tag_define: + print(git_tag_define) \ No newline at end of file diff --git a/src/lib/config.cpp b/src/lib/config.cpp index 8a2f463..032dc19 100644 --- a/src/lib/config.cpp +++ b/src/lib/config.cpp @@ -68,12 +68,13 @@ void setup() waitUntilNoneBusy(); - #ifdef HAS_FRONTLIGHT - if (!preferences.getBool("flAlwaysOn", false)) { +#ifdef HAS_FRONTLIGHT + if (!preferences.getBool("flAlwaysOn", false)) + { frontlightFadeOutAll(preferences.getUInt("flEffectDelay"), true); flArray.allOFF(); } - #endif +#endif forceFullRefresh(); } @@ -380,7 +381,7 @@ void setupHardware() } #ifdef IS_HW_REV_B -pinMode(39, INPUT_PULLUP); + pinMode(39, INPUT_PULLUP); #endif @@ -734,18 +735,33 @@ void setupFrontlight() } #endif -String getHwRev() { - #ifndef HW_REV - return "REV_0"; - #else - return HW_REV; - #endif +String getHwRev() +{ +#ifndef HW_REV + return "REV_0"; +#else + return HW_REV; +#endif } -bool isWhiteVersion() { - #ifdef IS_HW_REV_B +bool isWhiteVersion() +{ +#ifdef IS_HW_REV_B return digitalRead(39); - #else +#else return false; - #endif +#endif +} + +String getFsRev() +{ + File fsHash = LittleFS.open("/fs_hash.txt", "r"); + if (!fsHash) + { + Serial.println(F("Error loading WebUI")); + } + + String ret = fsHash.readString(); + fsHash.close(); + return ret; } \ No newline at end of file diff --git a/src/lib/config.hpp b/src/lib/config.hpp index 8c03023..b6fae71 100644 --- a/src/lib/config.hpp +++ b/src/lib/config.hpp @@ -64,4 +64,6 @@ void improv_set_error(improv::Error error); void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info); String getHwRev(); -bool isWhiteVersion(); \ No newline at end of file +bool isWhiteVersion(); + +String getFsRev(); \ No newline at end of file diff --git a/src/lib/webserver.cpp b/src/lib/webserver.cpp index d242eb7..accc7c2 100644 --- a/src/lib/webserver.cpp +++ b/src/lib/webserver.cpp @@ -67,8 +67,10 @@ void setupWebserver() // server.on("^\\/api\\/lights\\/([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$", HTTP_GET, // onApiLightsSetColor); - server.on("/firmware/update", HTTP_POST, onFirmwareUpdate, asyncFirmwareUpdateHandler); - server.on("/firmware/update_webui", HTTP_POST, onFirmwareUpdate, asyncWebuiUpdateHandler); + if (preferences.getBool("otaEnabled", true)) { + server.on("/upload/firmware", HTTP_POST, onFirmwareUpdate, asyncFirmwareUpdateHandler); + server.on("/upload/webui", HTTP_POST, onFirmwareUpdate, asyncWebuiUpdateHandler); + } server.on("/api/restart", HTTP_GET, onApiRestart); server.addRewrite(new OneParamRewrite("/api/lights/color/{color}", @@ -120,8 +122,6 @@ void onFirmwareUpdate(AsyncWebServerRequest *request) request->send(response); } - - void asyncWebuiUpdateHandler(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) { asyncFileUpdateHandler(request, filename, index, data, len, final, U_SPIFFS); @@ -129,14 +129,27 @@ void asyncWebuiUpdateHandler(AsyncWebServerRequest *request, String filename, si void asyncFileUpdateHandler(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final, int command) { - if (!index) + if (!index) { Serial.printf("Update Start: %s\n", filename.c_str()); - // Update.runAsync(true); - if (!Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000), command) + if (command == U_FLASH) { - Update.printError(Serial); + // Update.runAsync(true); + if (!Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000), command) + { + Update.printError(Serial); + return; + } + } + else if (command == U_SPIFFS) + { + size_t fsSize = UPDATE_SIZE_UNKNOWN; // or specify the size of your filesystem partition + if (!Update.begin(fsSize, U_SPIFFS)) // or U_FS for LittleFS + { + Update.printError(Serial); + return; + } } } if (!Update.hasError()) @@ -162,7 +175,7 @@ void asyncFileUpdateHandler(AsyncWebServerRequest *request, String filename, siz void asyncFirmwareUpdateHandler(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) { - asyncFileUpdateHandler(request, filename, index, data, len, final, U_FLASH); + asyncFileUpdateHandler(request, filename, index, data, len, final, U_FLASH); // if (!index) // { @@ -577,9 +590,16 @@ void onApiSettingsGet(AsyncWebServerRequest *request) root["hasFrontlight"] = false; #endif + root["hwRev"] = getHwRev(); + root["fsRev"] = getFsRev(); + #ifdef GIT_REV root["gitRev"] = String(GIT_REV); #endif +#ifdef GIT_TAG + root["gitTag"] = String(GIT_TAG); +#endif + #ifdef LAST_BUILD_TIME root["lastBuildTime"] = String(LAST_BUILD_TIME); #endif