Skip to content

Commit

Permalink
Merge pull request #7 from gordoste/master
Browse files Browse the repository at this point in the history
Add optional progress bar instead of % progress.
@gordoste Thank you for your contribution!
  • Loading branch information
jeroenvermeulen authored Sep 27, 2018
2 parents 3f01150 + 066df5c commit e1cc489
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/JeVe_EasyOTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ int EasyOTA::setupOTA(unsigned long now)
ArduinoOTA.onEnd([this]() {
showMessage("OTA done.Reboot...",1);
});
#ifdef OTA_USE_PROGRESS_BAR
static char progressBar[OTA_PROGRESS_BAR_SIZE+1];
memset(progressBar, ' ', OTA_PROGRESS_BAR_SIZE);
progressBar[0] = '[';
progressBar[OTA_PROGRESS_BAR_SIZE-1] = ']';
progressBar[OTA_PROGRESS_BAR_SIZE] = '\0';
ArduinoOTA.onProgress([this](unsigned int progress, unsigned int total) {
static unsigned int prevProg = 100;
unsigned int prog = progress / (total/(OTA_PROGRESS_BAR_SIZE-2));
Serial.println(prog);
if ( prog != prevProg) {
memset(progressBar+sizeof(char), '=', prog);
showMessage(progressBar, 2);
}
});
#else
ArduinoOTA.onProgress([this](unsigned int progress, unsigned int total) {
static unsigned int prevPerc = 100;
unsigned int perc = (progress / (total / 100));
Expand All @@ -101,6 +117,7 @@ int EasyOTA::setupOTA(unsigned long now)
showMessage("OTA upload " + String(roundPerc) + "%", 1);
}
});
#endif
ArduinoOTA.onError([this](ota_error_t error) {
showMessage("OTA Error " + String(error) + ":", 0);
String line2 = "";
Expand Down
6 changes: 6 additions & 0 deletions src/JeVe_EasyOTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
#define DEFAULT_OTA_PORT 8266
#define DEFAULT_OTA_HOSTNAME "EasyOta"

#ifdef OTA_USE_PROGRESS_BAR // Enable this via compiler flag
#ifndef OTA_PROGRESS_BAR_SIZE // Define this via compiler flag to override the default
#define OTA_PROGRESS_BAR_SIZE 20
#endif
#endif

#define EO_GETTER(T, name) T name() { return _##name; }
#define EO_SETTER(T, name) T name(T name) { T pa##name = _##name; _##name = name; return pa##name; }

Expand Down

0 comments on commit e1cc489

Please sign in to comment.