mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-03 19:26:32 +02:00
Remove dependency from StateMachine
This commit is contained in:
@ -113,7 +113,9 @@ static void factoryConfigReset(void);
|
||||
static void wdgFeedUpdate(void);
|
||||
static void ledBarEnabledUpdate(void);
|
||||
static bool sgp41Init(void);
|
||||
static void otaHandlerCallback(StateMachine::OtaState state, String mesasge);
|
||||
static void otaHandlerCallback(OtaState state, String mesasge);
|
||||
static void displayExecuteOta(OtaState state, String msg,
|
||||
int processing);
|
||||
|
||||
AgSchedule dispLedSchedule(DISP_UPDATE_INTERVAL, oledDisplayLedBarSchedule);
|
||||
AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL,
|
||||
@ -435,25 +437,68 @@ static bool sgp41Init(void) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static void otaHandlerCallback(StateMachine::OtaState state, String mesasge) {
|
||||
static void otaHandlerCallback(OtaState state, String mesasge) {
|
||||
switch (state) {
|
||||
case StateMachine::OtaState::OTA_STATE_BEGIN:
|
||||
stateMachine.executeOTA(state, fwNewVersion, 0);
|
||||
case OtaState::OTA_STATE_BEGIN:
|
||||
displayExecuteOta(state, fwNewVersion, 0);
|
||||
break;
|
||||
case StateMachine::OtaState::OTA_STATE_FAIL:
|
||||
stateMachine.executeOTA(state, "", 0);
|
||||
case OtaState::OTA_STATE_FAIL:
|
||||
displayExecuteOta(state, "", 0);
|
||||
break;
|
||||
case StateMachine::OtaState::OTA_STATE_PROCESSING:
|
||||
stateMachine.executeOTA(state, "", mesasge.toInt());
|
||||
case OtaState::OTA_STATE_PROCESSING:
|
||||
displayExecuteOta(state, "", mesasge.toInt());
|
||||
break;
|
||||
case StateMachine::OtaState::OTA_STATE_SUCCESS:
|
||||
stateMachine.executeOTA(state, "", mesasge.toInt());
|
||||
case OtaState::OTA_STATE_SUCCESS:
|
||||
displayExecuteOta(state, "", mesasge.toInt());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void displayExecuteOta(OtaState state, String msg, int processing) {
|
||||
switch (state) {
|
||||
case OtaState::OTA_STATE_BEGIN: {
|
||||
if (ag->isOne()) {
|
||||
oledDisplay.showNewFirmwareVersion(msg);
|
||||
} else {
|
||||
Serial.println("New firmware: " + msg);
|
||||
}
|
||||
delay(2500);
|
||||
break;
|
||||
}
|
||||
case OtaState::OTA_STATE_FAIL: {
|
||||
if (ag->isOne()) {
|
||||
oledDisplay.showNewFirmwareFailed();
|
||||
} else {
|
||||
Serial.println("Error: Firmware update: failed");
|
||||
}
|
||||
|
||||
delay(2500);
|
||||
break;
|
||||
}
|
||||
case OtaState::OTA_STATE_PROCESSING: {
|
||||
if (ag->isOne()) {
|
||||
oledDisplay.showNewFirmwareUpdating(String(processing));
|
||||
} else {
|
||||
Serial.println("Firmware update: " + String(processing) + String("%"));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case OtaState::OTA_STATE_SUCCESS: {
|
||||
if (ag->isOne()) {
|
||||
oledDisplay.showNewFirmwareSuccess(String(processing));
|
||||
} else {
|
||||
Serial.println("Rebooting... " + String(processing));
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void sendDataToAg() {
|
||||
/** Change oledDisplay and led state */
|
||||
if (ag->isOne()) {
|
||||
|
@ -1,9 +1,5 @@
|
||||
#ifndef _OTA_HANDLER_H_
|
||||
#define _OTA_HANDLER_H_
|
||||
|
||||
#include "AgConfigure.h"
|
||||
#include "AgStateMachine.h"
|
||||
#include "AirGradient.h"
|
||||
#include <Arduino.h>
|
||||
#include <esp_err.h>
|
||||
#include <esp_http_client.h>
|
||||
@ -19,7 +15,14 @@ enum OtaUpdateOutcome {
|
||||
UDPATE_SKIPPED
|
||||
};
|
||||
|
||||
typedef void(*OtaHandlerCallback_t)(StateMachine::OtaState state,
|
||||
enum OtaState {
|
||||
OTA_STATE_BEGIN,
|
||||
OTA_STATE_FAIL,
|
||||
OTA_STATE_PROCESSING,
|
||||
OTA_STATE_SUCCESS
|
||||
};
|
||||
|
||||
typedef void(*OtaHandlerCallback_t)(OtaState state,
|
||||
String message);
|
||||
|
||||
class OtaHandler {
|
||||
@ -43,7 +46,7 @@ public:
|
||||
while (i != 0) {
|
||||
i = i - 1;
|
||||
if (this->callback) {
|
||||
this->callback(StateMachine::OtaState::OTA_STATE_SUCCESS, String(i));
|
||||
this->callback(OtaState::OTA_STATE_SUCCESS, String(i));
|
||||
}
|
||||
delay(1000);
|
||||
}
|
||||
@ -118,7 +121,7 @@ private:
|
||||
|
||||
// Show display start update new firmware.
|
||||
if (this->callback) {
|
||||
this->callback(StateMachine::OtaState::OTA_STATE_BEGIN, "");
|
||||
this->callback(OtaState::OTA_STATE_BEGIN, "");
|
||||
}
|
||||
|
||||
// Download file and write new firmware to OTA partition
|
||||
@ -133,7 +136,7 @@ private:
|
||||
if (data_read < 0) {
|
||||
Serial.println("Data read error");
|
||||
if (this->callback) {
|
||||
this->callback(StateMachine::OtaState::OTA_STATE_FAIL, "");
|
||||
this->callback(OtaState::OTA_STATE_FAIL, "");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -142,7 +145,7 @@ private:
|
||||
update_handle, (const void *)upgrade_data_buf, data_read);
|
||||
if (ota_write_err != ESP_OK) {
|
||||
if (this->callback) {
|
||||
this->callback(StateMachine::OtaState::OTA_STATE_FAIL, "");
|
||||
this->callback(OtaState::OTA_STATE_FAIL, "");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -154,7 +157,7 @@ private:
|
||||
// sm.executeOTA(StateMachine::OtaState::OTA_STATE_PROCESSING, "",
|
||||
// percent);
|
||||
if (this->callback) {
|
||||
this->callback(StateMachine::OtaState::OTA_STATE_PROCESSING,
|
||||
this->callback(OtaState::OTA_STATE_PROCESSING,
|
||||
String(percent));
|
||||
}
|
||||
lastUpdate = millis();
|
||||
|
@ -759,47 +759,3 @@ void StateMachine::executeCo2Calibration(void) {
|
||||
void StateMachine::executeLedBarTest(void) {
|
||||
handleLeds(AgStateMachineLedBarTest);
|
||||
}
|
||||
|
||||
void StateMachine::executeOTA(StateMachine::OtaState state, String msg,
|
||||
int processing) {
|
||||
switch (state) {
|
||||
case OtaState::OTA_STATE_BEGIN: {
|
||||
if (ag->isOne()) {
|
||||
disp.showNewFirmwareVersion(msg);
|
||||
} else {
|
||||
logInfo("New firmware: " + msg);
|
||||
}
|
||||
delay(2500);
|
||||
break;
|
||||
}
|
||||
case OtaState::OTA_STATE_FAIL: {
|
||||
if (ag->isOne()) {
|
||||
disp.showNewFirmwareFailed();
|
||||
} else {
|
||||
logError("Firmware update: failed");
|
||||
}
|
||||
|
||||
delay(2500);
|
||||
break;
|
||||
}
|
||||
case OtaState::OTA_STATE_PROCESSING: {
|
||||
if (ag->isOne()) {
|
||||
disp.showNewFirmwareUpdating(String(processing));
|
||||
} else {
|
||||
logInfo("Firmware update: " + String(processing) + String("%"));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case OtaState::OTA_STATE_SUCCESS: {
|
||||
if (ag->isOne()) {
|
||||
disp.showNewFirmwareSuccess(String(processing));
|
||||
} else {
|
||||
logInfo("Rebooting... " + String(processing));
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -49,14 +49,6 @@ public:
|
||||
AgStateMachineState getLedState(void);
|
||||
void executeCo2Calibration(void);
|
||||
void executeLedBarTest(void);
|
||||
|
||||
enum OtaState {
|
||||
OTA_STATE_BEGIN,
|
||||
OTA_STATE_FAIL,
|
||||
OTA_STATE_PROCESSING,
|
||||
OTA_STATE_SUCCESS
|
||||
};
|
||||
void executeOTA(OtaState state, String msg, int processing);
|
||||
};
|
||||
|
||||
#endif /** _AG_STATE_MACHINE_H_ */
|
||||
|
Reference in New Issue
Block a user