refactor to use namespaces

This commit is contained in:
Nicu Hodos 2021-12-05 10:54:19 +01:00
parent 64be68c740
commit 261e87a97b

View File

@ -1,22 +1,30 @@
#include <ArduinoOTA.h> #include <ArduinoOTA.h>
void setupOTA() { namespace Ota
ArduinoOTA.onStart([]() { {
Serial.println("Start");
}); void setup() {
ArduinoOTA.onEnd([]() { ArduinoOTA.onStart([]() {
Serial.println("\nEnd"); Serial.println("Start");
}); });
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { ArduinoOTA.onEnd([]() {
Serial.printf("Progress: %u%%\r", (progress / (total / 100))); Serial.println("\nEnd");
}); });
ArduinoOTA.onError([](ota_error_t error) { ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Error[%u]: ", error); Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed"); });
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed"); ArduinoOTA.onError([](ota_error_t error) {
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed"); Serial.printf("Error[%u]: ", error);
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed"); if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed"); else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
}); else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
ArduinoOTA.begin(); else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});
ArduinoOTA.begin();
}
void loop() {
ArduinoOTA.handle();
}
} }