-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathota_update.cpp
More file actions
158 lines (143 loc) · 7.16 KB
/
Copy pathota_update.cpp
File metadata and controls
158 lines (143 loc) · 7.16 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* ********************************************************************************************** */
/* */
/* Smart Watch Firmware ::::::::: ::: */
/* ota_update.cpp :+: :+: :+: :+: */
/* +:+ +:+ +:+ +:+ */
/* By: Roman Alexandrov <r.aleksandroff@gmail.com> +#++:++#: +#++:++#++: */
/* +#+ +#+ +#+ +#+ */
/* Created: 2022/07/03 11:28:16 #+# #+# #+# #+# */
/* Updated: 2023/11/12 13:48:41 ### ### ### ### */
/* */
/* */
/* Support file for Over The Air firmware update. */
/* */
/* ********************************************************************************************** */
#include "header.h"
void ft_setup_ota(const char* nameprefix, const char* ssid, const char* password)
{
uint16_t maxlen;
char* fullhostname;
uint8_t mac[6];
// Configure the hostname
maxlen = strlen(nameprefix) + 7;
fullhostname = new char[maxlen];
WiFi.macAddress(mac);
snprintf(fullhostname, maxlen, "%s-%02x%02x%02x", nameprefix, mac[3], mac[4], mac[5]);
ArduinoOTA.setHostname(fullhostname);
delete[] fullhostname;
// Port defaults to 3232
// ArduinoOTA.setPort(3232); // Use 8266 port if you are working in Sloeber IDE, it is fixed there and not adjustable
// No authentication by default
// ArduinoOTA.setPassword("admin");
// Password can be set with it's md5 value as well
// MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
// ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");
ArduinoOTA.onStart([]() {
//NOTE: make .detach() here for all functions called by Ticker.h library - not to interrupt transfer process in any way.
String type;
if (ArduinoOTA.getCommand() == U_FLASH)
type = "sketch";
else // U_SPIFFS
type = "filesystem";
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
DEBUG_PRINT("Start updating " + type);
});
ArduinoOTA.onEnd([]() {
display.clearDisplay();
ft_mini_analog_clock_ui();
display.drawLine(64, 51, 64, 12, WHITE);
display.drawBitmap(93, 37, bit_O, 7, 5, WHITE);
display.drawBitmap(93, 29, bit_T, 7, 5, WHITE);
display.drawBitmap(93, 21, bit_A, 7, 5, WHITE);
display.drawBitmap(106, 51, bit_C, 7, 5, WHITE);
display.drawBitmap(106, 45, bit_O, 7, 5, WHITE);
display.drawBitmap(106, 39, bit_M, 7, 5, WHITE);
display.drawBitmap(106, 33, bit_P, 7, 5, WHITE);
display.drawBitmap(106, 26, bit_L, 7, 5, WHITE);
display.drawBitmap(106, 20, bit_E, 7, 5, WHITE);
display.drawBitmap(106, 14, bit_T, 7, 5, WHITE);
display.drawBitmap(106, 8, bit_E, 7, 5, WHITE);
display.display();
DEBUG_PRINT("\nEnd");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
display.clearDisplay();
ft_mini_analog_clock_ui();
display.drawLine(64, 51, 64, 12, WHITE);
display.drawBitmap(93, 37, bit_O, 7, 5, WHITE);
display.drawBitmap(93, 29, bit_T, 7, 5, WHITE);
display.drawBitmap(93, 21, bit_A, 7, 5, WHITE);
display.drawRoundRect(106, 11, 7, 40, 4, WHITE); // loading outline
display.fillRoundRect(106, (51 - (40 * progress / total)), 7, (40 * progress / total), 4, WHITE); // loading
display.display();
DEBUG_PRINT("Progress: "); DEBUG_PRINT(progress);
});
ArduinoOTA.onError([](ota_error_t error) {
display.clearDisplay();
ft_mini_analog_clock_ui();
display.drawLine(64, 51, 64, 12, WHITE);
display.drawBitmap(93, 37, bit_O, 7, 5, WHITE);
display.drawBitmap(93, 29, bit_T, 7, 5, WHITE);
display.drawBitmap(93, 21, bit_A, 7, 5, WHITE);
display.drawBitmap(106, y+44, bit_E, 7, 5, WHITE);
display.drawBitmap(106, y+37, bit_R, 7, 5, WHITE);
display.drawBitmap(106, y+30, bit_R, 7, 5, WHITE);
display.drawBitmap(106, y+23, bit_O, 7, 5, WHITE);
display.drawBitmap(106, y+16, bit_R, 7, 5, WHITE);
display.display();
DEBUG_PRINT("Error: "); DEBUG_PRINT(error);
if (error == OTA_AUTH_ERROR)
DEBUG_PRINT("\nAuth Failed");
if (error == OTA_BEGIN_ERROR)
DEBUG_PRINT("\nBegin Failed");
if (error == OTA_CONNECT_ERROR)
DEBUG_PRINT("\nConnect Failed");
if (error == OTA_RECEIVE_ERROR)
DEBUG_PRINT("\nReceive Failed");
if (error == OTA_END_ERROR)
DEBUG_PRINT("\nEnd Failed");
});
ArduinoOTA.begin();
DEBUG_PRINT("OTA Initialized");
DEBUG_PRINT("IP address: "); DEBUG_PRINT(WiFi.localIP());
}
void ft_ota_start_and_ui(short battery_charge)
{
if (g_icon_cycle > 15 || g_icon_cycle < 1)
g_icon_cycle = 1;
ArduinoOTA.handle();
rtcMng.controls_tracker = 0; // Keeps the system awake during OTA
display.drawLine(64, 51, 64, 12, WHITE);
display.drawBitmap(93, 37, bit_O, 7, 5, WHITE);
display.drawBitmap(93, 29, bit_T, 7, 5, WHITE);
display.drawBitmap(93, 21, bit_A, 7, 5, WHITE);
display.drawRoundRect(106, 11, 7, 40, 4, WHITE);
if (battery_charge < 12)
{
display.drawBitmap(105, 51, bit_B, 7, 5, WHITE);
display.drawBitmap(105, 44, bit_A, 7, 5, WHITE);
display.drawBitmap(105, 37, bit_T, 7, 5, WHITE);
display.drawBitmap(105, 30, bit_T, 7, 5, WHITE);
display.drawBitmap(105, 23, bit_E, 7, 5, WHITE);
display.drawBitmap(105, 16, bit_R, 7, 5, WHITE);
display.drawBitmap(105, 9, bit_Y, 7, 5, WHITE);
display.drawBitmap(114, 33, bit_I, 7, 5, WHITE);
display.drawBitmap(114, 26, bit_S, 7, 5, WHITE);
display.drawBitmap(123, 51, bit_T, 7, 5, WHITE);
display.drawBitmap(123, 44, bit_O, 7, 5, WHITE);
display.drawBitmap(123, 37, bit_O, 7, 5, WHITE);
display.drawBitmap(123, 23, bit_L, 7, 5, WHITE);
display.drawBitmap(123, 16, bit_O, 7, 5, WHITE);
display.drawBitmap(123, 9, bit_W, 7, 5, WHITE);
}
else
{
if (g_icon_cycle == 1 || g_icon_cycle == 2)
display.fillRect(109, 38, 1, 2, WHITE);
if (g_icon_cycle == 3 || g_icon_cycle == 4)
display.fillRect(109, 30, 1, 2, WHITE);
if (g_icon_cycle == 5 || g_icon_cycle == 6)
display.fillRect(109, 22, 1, 2, WHITE);
g_icon_cycle++;
}
}