2023-11-10 22:18:14 +00:00
|
|
|
#include "ota.hpp"
|
|
|
|
|
|
|
|
TaskHandle_t taskOtaHandle = NULL;
|
|
|
|
|
|
|
|
void setupOTA()
|
|
|
|
{
|
2023-11-12 23:33:48 +00:00
|
|
|
if (preferences.getBool("otaEnabled", true))
|
|
|
|
{
|
2023-11-10 22:18:14 +00:00
|
|
|
ArduinoOTA.onStart(onOTAStart);
|
|
|
|
|
2023-11-12 23:33:48 +00:00
|
|
|
ArduinoOTA.onProgress(onOTAProgress);
|
2023-11-13 00:02:01 +00:00
|
|
|
ArduinoOTA.onError(onOTAError);
|
2023-11-12 23:33:48 +00:00
|
|
|
ArduinoOTA.onEnd(onOTAComplete);
|
2023-11-10 22:18:14 +00:00
|
|
|
|
|
|
|
ArduinoOTA.setHostname(getMyHostname().c_str());
|
|
|
|
ArduinoOTA.setMdnsEnabled(false);
|
2023-11-12 23:33:48 +00:00
|
|
|
ArduinoOTA.setRebootOnSuccess(false);
|
2023-11-10 22:18:14 +00:00
|
|
|
ArduinoOTA.begin();
|
|
|
|
|
|
|
|
xTaskCreate(handleOTATask, "handleOTA", 4096, NULL, tskIDLE_PRIORITY, &taskOtaHandle);
|
2023-11-12 23:33:48 +00:00
|
|
|
}
|
|
|
|
}
|
2023-11-10 22:18:14 +00:00
|
|
|
|
2023-11-12 23:33:48 +00:00
|
|
|
void onOTAProgress(unsigned int progress, unsigned int total)
|
|
|
|
{
|
|
|
|
uint percentage = progress / (total / 100);
|
|
|
|
pixels.fill(pixels.Color(0, 255, 0));
|
|
|
|
if (percentage < 100)
|
|
|
|
{
|
|
|
|
pixels.setPixelColor(0, pixels.Color(0, 0, 0));
|
|
|
|
}
|
|
|
|
if (percentage < 75)
|
|
|
|
{
|
|
|
|
pixels.setPixelColor(1, pixels.Color(0, 0, 0));
|
|
|
|
}
|
|
|
|
if (percentage < 50)
|
|
|
|
{
|
|
|
|
pixels.setPixelColor(2, pixels.Color(0, 0, 0));
|
|
|
|
}
|
|
|
|
if (percentage < 25)
|
|
|
|
{
|
|
|
|
pixels.setPixelColor(3, pixels.Color(0, 0, 0));
|
|
|
|
}
|
|
|
|
pixels.show();
|
2023-11-10 22:18:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void onOTAStart()
|
|
|
|
{
|
2023-11-12 23:33:48 +00:00
|
|
|
forceFullRefresh();
|
|
|
|
std::array<String, NUM_SCREENS> epdContent = {"U", "P", "D", "A", "T", "E", "!"};
|
|
|
|
setEpdContent(epdContent);
|
|
|
|
// Stop all timers
|
|
|
|
esp_timer_stop(screenRotateTimer);
|
|
|
|
esp_timer_stop(minuteTimer);
|
2023-11-10 22:18:14 +00:00
|
|
|
|
2023-11-12 23:33:48 +00:00
|
|
|
// Stop or suspend all tasks
|
2023-11-12 11:38:28 +00:00
|
|
|
// vTaskSuspend(priceUpdateTaskHandle);
|
2023-11-12 23:33:48 +00:00
|
|
|
// vTaskSuspend(blockUpdateTaskHandle);
|
|
|
|
vTaskSuspend(workerTaskHandle);
|
|
|
|
vTaskSuspend(taskScreenRotateTaskHandle);
|
2023-11-10 22:18:14 +00:00
|
|
|
|
2023-11-12 23:33:48 +00:00
|
|
|
vTaskSuspend(ledTaskHandle);
|
|
|
|
vTaskSuspend(buttonTaskHandle);
|
2023-11-10 22:18:14 +00:00
|
|
|
|
2023-11-12 23:33:48 +00:00
|
|
|
stopWebServer();
|
|
|
|
stopBlockNotify();
|
|
|
|
stopPriceNotify();
|
2023-11-10 22:18:14 +00:00
|
|
|
}
|
|
|
|
|
2023-11-12 23:33:48 +00:00
|
|
|
void handleOTATask(void *parameter)
|
|
|
|
{
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
ArduinoOTA.handle(); // Allow OTA updates to occur
|
2023-11-10 22:33:24 +00:00
|
|
|
vTaskDelay(pdMS_TO_TICKS(2500));
|
2023-11-10 22:18:14 +00:00
|
|
|
}
|
2023-11-12 11:38:28 +00:00
|
|
|
}
|
|
|
|
|
2023-11-12 23:33:48 +00:00
|
|
|
void downloadUpdate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-11-13 00:02:01 +00:00
|
|
|
void onOTAError(ota_error_t error) {
|
|
|
|
Serial.println("\nOTA update error, restarting");
|
|
|
|
Wire.end();
|
|
|
|
SPI.end();
|
|
|
|
delay(1000);
|
|
|
|
ESP.restart();
|
|
|
|
}
|
|
|
|
|
2023-11-12 23:33:48 +00:00
|
|
|
void onOTAComplete()
|
|
|
|
{
|
|
|
|
Serial.println("\nOTA update finished");
|
|
|
|
Wire.end();
|
|
|
|
SPI.end();
|
|
|
|
delay(1000);
|
|
|
|
ESP.restart();
|
|
|
|
}
|