extend power statemachine
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
#include "ota.h"
|
||||
|
||||
OtaProcess_class ota(100);
|
||||
|
||||
|
||||
bool OtaProcess_class::initialize(void)
|
||||
{
|
||||
if (m_newState)
|
||||
@@ -47,6 +50,7 @@ bool OtaProcess_class::initialize(void)
|
||||
.onStart([]()
|
||||
{
|
||||
String type;
|
||||
ota.m_otaState = otaStart;
|
||||
if (ArduinoOTA.getCommand() == U_FLASH)
|
||||
{
|
||||
type = "sketch";
|
||||
@@ -59,12 +63,13 @@ bool OtaProcess_class::initialize(void)
|
||||
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
|
||||
Serial.println("Start updating " + type); })
|
||||
.onEnd([]()
|
||||
{ log_i("End"); })
|
||||
{ log_i("End"); ota.m_otaState = otaDone; })
|
||||
.onProgress([](unsigned int progress, unsigned int total)
|
||||
{ log_i("Progress: %u%%\r", (progress / (total / 100))); })
|
||||
{ log_i("Progress: %u%%\r", (progress / (total / 100))); ota.m_otaState = otaBusy; })
|
||||
.onError([](ota_error_t error)
|
||||
{
|
||||
log_e("Error[%u]: ", error);
|
||||
ota.m_otaState = otaError;
|
||||
if (error == OTA_AUTH_ERROR) log_e("Auth Failed");
|
||||
else if (error == OTA_BEGIN_ERROR) log_e("Begin Failed");
|
||||
else if (error == OTA_CONNECT_ERROR) log_e("Connect Failed");
|
||||
@@ -151,10 +156,27 @@ void OtaProcess_class::stopped(void)
|
||||
}
|
||||
}
|
||||
|
||||
void otaEnable(void)
|
||||
{
|
||||
ota.setProcessState(PROCESS_STATE::processInit);
|
||||
}
|
||||
|
||||
void otaDisable(void)
|
||||
{
|
||||
ota.setProcessState(PROCESS_STATE::processDisabled);
|
||||
}
|
||||
|
||||
void initOta(void)
|
||||
{
|
||||
/* noting */
|
||||
}
|
||||
|
||||
OTASTATES getOtaState(void)
|
||||
{
|
||||
return ota.m_otaState;
|
||||
}
|
||||
|
||||
void handleOta(void)
|
||||
{
|
||||
ota.run();
|
||||
}
|
||||
Reference in New Issue
Block a user