Add web UI flasher functionality

This commit is contained in:
Djuri Baars 2024-06-09 00:45:46 +02:00
parent 313efb7604
commit 2a8e391342
5 changed files with 77 additions and 26 deletions

2
data

@ -1 +1 @@
Subproject commit 4f15eee72bcd3873a0edb61bc77638a0ff5e3724 Subproject commit 2a7ba588e2ab06d433e9ac3f6882bfd4a7f714fe

View File

@ -5,4 +5,17 @@ revision = (
.strip() .strip()
.decode("utf-8") .decode("utf-8")
) )
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) print("'-DGIT_REV=\"%s\"'" % revision)
if git_tag_define:
print(git_tag_define)

View File

@ -69,7 +69,8 @@ void setup()
waitUntilNoneBusy(); waitUntilNoneBusy();
#ifdef HAS_FRONTLIGHT #ifdef HAS_FRONTLIGHT
if (!preferences.getBool("flAlwaysOn", false)) { if (!preferences.getBool("flAlwaysOn", false))
{
frontlightFadeOutAll(preferences.getUInt("flEffectDelay"), true); frontlightFadeOutAll(preferences.getUInt("flEffectDelay"), true);
flArray.allOFF(); flArray.allOFF();
} }
@ -734,7 +735,8 @@ void setupFrontlight()
} }
#endif #endif
String getHwRev() { String getHwRev()
{
#ifndef HW_REV #ifndef HW_REV
return "REV_0"; return "REV_0";
#else #else
@ -742,10 +744,24 @@ String getHwRev() {
#endif #endif
} }
bool isWhiteVersion() { bool isWhiteVersion()
{
#ifdef IS_HW_REV_B #ifdef IS_HW_REV_B
return digitalRead(39); return digitalRead(39);
#else #else
return false; 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;
}

View File

@ -65,3 +65,5 @@ void improv_set_error(improv::Error error);
void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info); void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info);
String getHwRev(); String getHwRev();
bool isWhiteVersion(); bool isWhiteVersion();
String getFsRev();

View File

@ -67,8 +67,10 @@ void setupWebserver()
// server.on("^\\/api\\/lights\\/([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$", HTTP_GET, // server.on("^\\/api\\/lights\\/([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$", HTTP_GET,
// onApiLightsSetColor); // onApiLightsSetColor);
server.on("/firmware/update", HTTP_POST, onFirmwareUpdate, asyncFirmwareUpdateHandler); if (preferences.getBool("otaEnabled", true)) {
server.on("/firmware/update_webui", HTTP_POST, onFirmwareUpdate, asyncWebuiUpdateHandler); server.on("/upload/firmware", HTTP_POST, onFirmwareUpdate, asyncFirmwareUpdateHandler);
server.on("/upload/webui", HTTP_POST, onFirmwareUpdate, asyncWebuiUpdateHandler);
}
server.on("/api/restart", HTTP_GET, onApiRestart); server.on("/api/restart", HTTP_GET, onApiRestart);
server.addRewrite(new OneParamRewrite("/api/lights/color/{color}", server.addRewrite(new OneParamRewrite("/api/lights/color/{color}",
@ -120,8 +122,6 @@ void onFirmwareUpdate(AsyncWebServerRequest *request)
request->send(response); request->send(response);
} }
void asyncWebuiUpdateHandler(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) 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); asyncFileUpdateHandler(request, filename, index, data, len, final, U_SPIFFS);
@ -133,10 +133,23 @@ void asyncFileUpdateHandler(AsyncWebServerRequest *request, String filename, siz
{ {
Serial.printf("Update Start: %s\n", filename.c_str()); Serial.printf("Update Start: %s\n", filename.c_str());
if (command == U_FLASH)
{
// Update.runAsync(true); // Update.runAsync(true);
if (!Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000), command) if (!Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000), command)
{ {
Update.printError(Serial); 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()) if (!Update.hasError())
@ -577,9 +590,16 @@ void onApiSettingsGet(AsyncWebServerRequest *request)
root["hasFrontlight"] = false; root["hasFrontlight"] = false;
#endif #endif
root["hwRev"] = getHwRev();
root["fsRev"] = getFsRev();
#ifdef GIT_REV #ifdef GIT_REV
root["gitRev"] = String(GIT_REV); root["gitRev"] = String(GIT_REV);
#endif #endif
#ifdef GIT_TAG
root["gitTag"] = String(GIT_TAG);
#endif
#ifdef LAST_BUILD_TIME #ifdef LAST_BUILD_TIME
root["lastBuildTime"] = String(LAST_BUILD_TIME); root["lastBuildTime"] = String(LAST_BUILD_TIME);
#endif #endif