mirror of
https://github.com/btclock/btclock_v3.git
synced 2024-11-19 02:30:01 +01:00
Better handling of steal screen, add firmware web update functionality
This commit is contained in:
parent
491618dd78
commit
313efb7604
@ -192,6 +192,7 @@ void onWebsocketBlockMessage(esp_websocket_event_data_t *event_data)
|
|||||||
esp_timer_start_periodic(screenRotateTimer,
|
esp_timer_start_periodic(screenRotateTimer,
|
||||||
timerPeriod * usPerSecond);
|
timerPeriod * usPerSecond);
|
||||||
}
|
}
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(315*NUM_SCREENS)); // Extra delay because of screen switching
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preferences.getBool("ledFlashOnUpd", false))
|
if (preferences.getBool("ledFlashOnUpd", false))
|
||||||
|
@ -67,6 +67,9 @@ 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);
|
||||||
|
server.on("/firmware/update_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}",
|
||||||
"/api/lights/color?c={color}"));
|
"/api/lights/color?c={color}"));
|
||||||
@ -109,6 +112,89 @@ void setupWebserver()
|
|||||||
|
|
||||||
void stopWebServer() { server.end(); }
|
void stopWebServer() { server.end(); }
|
||||||
|
|
||||||
|
void onFirmwareUpdate(AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
|
bool shouldReboot = !Update.hasError();
|
||||||
|
AsyncWebServerResponse *response = request->beginResponse(200, "text/plain", shouldReboot ? "OK" : "FAIL");
|
||||||
|
response->addHeader("Connection", "close");
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void asyncFileUpdateHandler(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final, int command)
|
||||||
|
{
|
||||||
|
if (!index)
|
||||||
|
{
|
||||||
|
Serial.printf("Update Start: %s\n", filename.c_str());
|
||||||
|
|
||||||
|
// Update.runAsync(true);
|
||||||
|
if (!Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000), command)
|
||||||
|
{
|
||||||
|
Update.printError(Serial);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!Update.hasError())
|
||||||
|
{
|
||||||
|
if (Update.write(data, len) != len)
|
||||||
|
{
|
||||||
|
Update.printError(Serial);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (final)
|
||||||
|
{
|
||||||
|
if (Update.end(true))
|
||||||
|
{
|
||||||
|
Serial.printf("Update Success: %uB\n", index + len);
|
||||||
|
onApiRestart(request);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Update.printError(Serial);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
// if (!index)
|
||||||
|
// {
|
||||||
|
// Serial.printf("Update Start: %s\n", filename.c_str());
|
||||||
|
|
||||||
|
// // Update.runAsync(true);
|
||||||
|
// if (!Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000))
|
||||||
|
// {
|
||||||
|
// Update.printError(Serial);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (!Update.hasError())
|
||||||
|
// {
|
||||||
|
// if (Update.write(data, len) != len)
|
||||||
|
// {
|
||||||
|
// Update.printError(Serial);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (final)
|
||||||
|
// {
|
||||||
|
// if (Update.end(true))
|
||||||
|
// {
|
||||||
|
// Serial.printf("Update Success: %uB\n", index + len);
|
||||||
|
// onApiRestart(request);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// Update.printError(Serial);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
JsonDocument getStatusObject()
|
JsonDocument getStatusObject()
|
||||||
{
|
{
|
||||||
JsonDocument root;
|
JsonDocument root;
|
||||||
|
@ -44,6 +44,10 @@ void onApiLightsSetColor(AsyncWebServerRequest *request);
|
|||||||
void onApiLightsSetJson(AsyncWebServerRequest *request, JsonVariant &json);
|
void onApiLightsSetJson(AsyncWebServerRequest *request, JsonVariant &json);
|
||||||
|
|
||||||
void onApiRestart(AsyncWebServerRequest *request);
|
void onApiRestart(AsyncWebServerRequest *request);
|
||||||
|
void onFirmwareUpdate(AsyncWebServerRequest *request);
|
||||||
|
void asyncFirmwareUpdateHandler(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);
|
||||||
|
void asyncFileUpdateHandler(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final, int command);
|
||||||
|
void asyncWebuiUpdateHandler(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);
|
||||||
|
|
||||||
void onIndex(AsyncWebServerRequest *request);
|
void onIndex(AsyncWebServerRequest *request);
|
||||||
void onNotFound(AsyncWebServerRequest *request);
|
void onNotFound(AsyncWebServerRequest *request);
|
||||||
|
Loading…
Reference in New Issue
Block a user