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()
.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();
#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;
}

View file

@ -64,4 +64,6 @@ void improv_set_error(improv::Error error);
void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info);
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,
// 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