-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathota_manager.cpp
More file actions
66 lines (52 loc) · 1.52 KB
/
ota_manager.cpp
File metadata and controls
66 lines (52 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* OTA Manager Implementation
* Handles Over-The-Air firmware updates with progress tracking
*/
#include "ota_manager.h"
#include "display_manager.h"
#include <Update.h>
// Global instance
OTAManager otaManager;
OTAManager::OTAManager()
: status(OTA_UPDATE_IDLE), progress(0) {
statusMessage[0] = '\0';
}
void OTAManager::begin() {
status = OTA_UPDATE_IDLE;
progress = 0;
statusMessage[0] = '\0';
if (debugPrint) {
debugPrint("OTA Manager initialized", COLOR_GREEN);
}
}
void OTAManager::setDebugFunction(
std::function<void(const char*, uint16_t)> debugPrintFunc
) {
debugPrint = debugPrintFunc;
}
void OTAManager::setStatus(OTAUpdateStatus newStatus, const char* message) {
status = newStatus;
if (message) {
strncpy(statusMessage, message, sizeof(statusMessage) - 1);
statusMessage[sizeof(statusMessage) - 1] = '\0';
if (debugPrint) {
debugPrint(message, COLOR_CYAN);
}
}
}
void OTAManager::setProgress(uint8_t percent) {
progress = (percent > 100) ? 100 : percent;
}
void OTAManager::reset() {
status = OTA_UPDATE_IDLE;
progress = 0;
statusMessage[0] = '\0';
}
void OTAManager::displayProgress(const char* operation, uint8_t percent) {
progress = (percent > 100) ? 100 : percent;
// Update status message and display
snprintf(statusMessage, sizeof(statusMessage), "%s: %d%%", operation, progress);
if (debugPrint) {
debugPrint(statusMessage, COLOR_CYAN);
}
}