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")
) )
print("'-DGIT_REV=\"%s\"'" % revision)
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)

View file

@ -68,12 +68,13 @@ 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();
} }
#endif #endif
forceFullRefresh(); forceFullRefresh();
} }
@ -380,7 +381,7 @@ void setupHardware()
} }
#ifdef IS_HW_REV_B #ifdef IS_HW_REV_B
pinMode(39, INPUT_PULLUP); pinMode(39, INPUT_PULLUP);
#endif #endif
@ -734,18 +735,33 @@ void setupFrontlight()
} }
#endif #endif
String getHwRev() { String getHwRev()
#ifndef HW_REV {
return "REV_0"; #ifndef HW_REV
#else return "REV_0";
return HW_REV; #else
#endif return HW_REV;
#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

@ -64,4 +64,6 @@ 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);
@ -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) 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()); Serial.printf("Update Start: %s\n", filename.c_str());
// Update.runAsync(true); if (command == U_FLASH)
if (!Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000), command)
{ {
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()) 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) 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) // if (!index)
// { // {
@ -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