platform: arduino: ota: prevent watchdog hang on ota update
This commit is contained in:
parent
19f2a4f35c
commit
c4bbeccac0
@ -4,10 +4,13 @@
|
|||||||
ArduinoOTAUpdater::ArduinoOTAUpdater() : BufferedInputSource("ArduinoOTA") {
|
ArduinoOTAUpdater::ArduinoOTAUpdater() : BufferedInputSource("ArduinoOTA") {
|
||||||
ArduinoOTA.onStart(&ArduinoOTAUpdater::s_onStart);
|
ArduinoOTA.onStart(&ArduinoOTAUpdater::s_onStart);
|
||||||
ArduinoOTA.onProgress(&ArduinoOTAUpdater::s_onProgress);
|
ArduinoOTA.onProgress(&ArduinoOTAUpdater::s_onProgress);
|
||||||
|
ArduinoOTA.onError(&ArduinoOTAUpdater::s_onError);
|
||||||
|
ArduinoOTA.onEnd(&ArduinoOTAUpdater::s_onFinished);
|
||||||
|
ArduinoOTA.setRebootOnSuccess(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArduinoOTAUpdater::loop() {
|
void ArduinoOTAUpdater::loop() {
|
||||||
if (m_online) {
|
if (m_online && !m_updating) {
|
||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
}
|
}
|
||||||
BufferedInputSource::loop();
|
BufferedInputSource::loop();
|
||||||
@ -20,14 +23,32 @@ void ArduinoOTAUpdater::handleEvent(const InputEvent& evt) {
|
|||||||
ArduinoOTA.begin();
|
ArduinoOTA.begin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ArduinoOTAUpdater::s_onFinished()
|
||||||
|
{
|
||||||
|
Log.notice("OTA complete!");
|
||||||
|
Static<ArduinoOTAUpdater>::instance()->m_updating = false;
|
||||||
|
Platform::restart();
|
||||||
|
}
|
||||||
|
|
||||||
void ArduinoOTAUpdater::s_onStart() {
|
void ArduinoOTAUpdater::s_onStart() {
|
||||||
Log.notice("OTA Start!");
|
Log.notice("OTA Start!");
|
||||||
|
Static<ArduinoOTAUpdater>::instance()->m_updating = true;
|
||||||
Static<ArduinoOTAUpdater>::instance()->setEvent(InputEvent::FirmwareUpdate);
|
Static<ArduinoOTAUpdater>::instance()->setEvent(InputEvent::FirmwareUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ArduinoOTAUpdater::s_onError(ota_error_t err)
|
||||||
|
{
|
||||||
|
Log.notice("OTA failure: %d", (int)err);
|
||||||
|
Static<ArduinoOTAUpdater>::instance()->m_updating = false;
|
||||||
|
}
|
||||||
|
|
||||||
void ArduinoOTAUpdater::s_onProgress(unsigned int progress, unsigned int total) {
|
void ArduinoOTAUpdater::s_onProgress(unsigned int progress, unsigned int total) {
|
||||||
Log.notice("OTA Progress! %d / %d", progress, total);
|
Log.notice("OTA Progress! %d / %d", progress, total);
|
||||||
Static<ArduinoOTAUpdater>::instance()->setEvent(InputEvent{InputEvent::FirmwareUpdate, progress});
|
Static<ArduinoOTAUpdater>::instance()->setEvent(InputEvent{InputEvent::FirmwareUpdate, progress});
|
||||||
|
// Try to run the main loop in case we're not in a threaded updater
|
||||||
|
// environment. This keeps rendering running, and pets the watchdog.
|
||||||
|
MainLoop::instance()->loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC_ALLOC(ArduinoOTAUpdater);
|
STATIC_ALLOC(ArduinoOTAUpdater);
|
||||||
|
@ -9,6 +9,9 @@ class ArduinoOTAUpdater : public BufferedInputSource {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_online = false;
|
bool m_online = false;
|
||||||
|
bool m_updating = false;
|
||||||
static void s_onStart();
|
static void s_onStart();
|
||||||
static void s_onProgress(unsigned int progress, unsigned int total);
|
static void s_onProgress(unsigned int progress, unsigned int total);
|
||||||
|
static void s_onError(ota_error_t err);
|
||||||
|
static void s_onFinished();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user