init
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
#include "ota_manager.hpp"
|
||||
|
||||
OTAManager::OTAManager() : enabled(false), status("Disabled") {}
|
||||
|
||||
OTAManager::~OTAManager() {}
|
||||
|
||||
void OTAManager::begin() {
|
||||
ArduinoOTA.setHostname("RFID-Master-Client");
|
||||
|
||||
ArduinoOTA.onStart([this]() {
|
||||
this->onStart();
|
||||
});
|
||||
|
||||
ArduinoOTA.onEnd([this]() {
|
||||
this->onEnd();
|
||||
});
|
||||
|
||||
ArduinoOTA.onProgress([this](unsigned int progress, unsigned int total) {
|
||||
this->onProgress(progress, total);
|
||||
});
|
||||
|
||||
ArduinoOTA.onError([this](ota_error_t error) {
|
||||
this->onError(error);
|
||||
});
|
||||
|
||||
LOG_INFO("OTA Manager initialized");
|
||||
}
|
||||
|
||||
void OTAManager::enable() {
|
||||
if (!enabled) {
|
||||
ArduinoOTA.begin();
|
||||
enabled = true;
|
||||
status = "Enabled";
|
||||
LOG_INFO("OTA enabled");
|
||||
}
|
||||
}
|
||||
|
||||
void OTAManager::disable() {
|
||||
if (enabled) {
|
||||
ArduinoOTA.end();
|
||||
enabled = false;
|
||||
status = "Disabled";
|
||||
LOG_INFO("OTA disabled");
|
||||
}
|
||||
}
|
||||
|
||||
bool OTAManager::isEnabled() const {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
String OTAManager::getStatus() const {
|
||||
return status;
|
||||
}
|
||||
|
||||
void OTAManager::onStart() {
|
||||
status = "Starting OTA update...";
|
||||
LOG_INFO("OTA update started");
|
||||
}
|
||||
|
||||
void OTAManager::onEnd() {
|
||||
status = "OTA update completed";
|
||||
LOG_INFO("OTA update completed");
|
||||
}
|
||||
|
||||
void OTAManager::onProgress(unsigned int progress, unsigned int total) {
|
||||
status = "OTA progress: " + String(progress / (total / 100)) + "%";
|
||||
LOG_DEBUG("OTA progress: %u/%u", progress, total);
|
||||
}
|
||||
|
||||
void OTAManager::onError(ota_error_t error) {
|
||||
String errorMsg;
|
||||
switch (error) {
|
||||
case OTA_AUTH_ERROR:
|
||||
errorMsg = "Auth Failed";
|
||||
break;
|
||||
case OTA_BEGIN_ERROR:
|
||||
errorMsg = "Begin Failed";
|
||||
break;
|
||||
case OTA_CONNECT_ERROR:
|
||||
errorMsg = "Connect Failed";
|
||||
break;
|
||||
case OTA_RECEIVE_ERROR:
|
||||
errorMsg = "Receive Failed";
|
||||
break;
|
||||
case OTA_END_ERROR:
|
||||
errorMsg = "End Failed";
|
||||
break;
|
||||
default:
|
||||
errorMsg = "Unknown Error";
|
||||
break;
|
||||
}
|
||||
status = "OTA Error: " + errorMsg;
|
||||
LOG_ERROR("OTA error: %s", errorMsg.c_str());
|
||||
}
|
||||
Reference in New Issue
Block a user