btclock_v3/src/lib/ota.cpp

51 lines
1.2 KiB
C++
Raw Normal View History

#include "ota.hpp"
TaskHandle_t taskOtaHandle = NULL;
void setupOTA()
{
ArduinoOTA.onStart(onOTAStart);
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total)
{ Serial.printf("OTA Progress: %u%%\r", (progress / (total / 100))); });
ArduinoOTA.onEnd([]()
{ Serial.println("\nOTA update finished"); });
ArduinoOTA.setHostname(getMyHostname().c_str());
ArduinoOTA.setMdnsEnabled(false);
ArduinoOTA.begin();
xTaskCreate(handleOTATask, "handleOTA", 4096, NULL, tskIDLE_PRIORITY, &taskOtaHandle);
}
void onOTAStart()
{
// Stop all timers
esp_timer_stop(screenRotateTimer);
esp_timer_stop(minuteTimer);
// Stop or suspend all tasks
vTaskSuspend(priceUpdateTaskHandle);
vTaskSuspend(blockUpdateTaskHandle);
vTaskSuspend(timeUpdateTaskHandle);
vTaskSuspend(taskScreenRotateTaskHandle);
vTaskSuspend(ledTaskHandle);
vTaskSuspend(buttonTaskHandle);
stopWebServer();
stopBlockNotify();
stopPriceNotify();
}
void handleOTATask(void *parameter) {
for (;;) {
// Task 1 code
ArduinoOTA.handle(); // Allow OTA updates to occur
2023-11-10 22:33:24 +00:00
vTaskDelay(pdMS_TO_TICKS(2500));
}
}