File tree Expand file tree Collapse file tree 4 files changed +51
-11
lines changed Expand file tree Collapse file tree 4 files changed +51
-11
lines changed Original file line number Diff line number Diff line change @@ -88,10 +88,18 @@ class SettingsESP : public sets::SettingsBase {
8888 HTTPUpload& upload = server.upload ();
8989 if (upload.status == UPLOAD_FILE_START) {
9090 sets::beginOta ();
91+ if (_onStart)
92+ _onStart ();
9193 } else if (upload.status == UPLOAD_FILE_WRITE) {
9294 Update.write (upload.buf , upload.currentSize );
95+ if (_onProgress) {
96+ size_t maxSketchSpace = sets::OtaGetMaxSize ();
97+ _onProgress (upload.totalSize , maxSketchSpace);
98+ }
9399 } else if (upload.status == UPLOAD_FILE_END) {
94- Update.end (true );
100+ bool result = Update.end (true );
101+ if (_onDone)
102+ _onDone (result);
95103 } });
96104
97105 server.onNotFound ([this ]() {
@@ -193,4 +201,4 @@ class SettingsESP : public sets::SettingsBase {
193201 server.sendHeader (F (" Access-Control-Allow-Methods" ), F (" *" ));
194202#endif
195203 }
196- };
204+ };
Original file line number Diff line number Diff line change 2626
2727namespace sets {
2828
29+ typedef void (*onUpdateFWStart_t)();
30+ typedef void (*onUpdateFWProgress_t)(size_t current, size_t final );
31+ typedef void (*onUpdateFWDone_t)(bool success);
32+
2933class SettingsBase {
3034 static const uint16_t FOCUS_TOUT = 5000 ;
3135 static const uint16_t DB_WS_UPDATE_PRD = 300 ;
3236
3337 protected:
38+ sets::onUpdateFWStart_t _onStart = nullptr ;
39+ sets::onUpdateFWProgress_t _onProgress = nullptr ;
40+ sets::onUpdateFWDone_t _onDone = nullptr ;
41+
3442 typedef std::function<void (Builder& b)> BuildCallback;
3543 typedef std::function<void (Updater& upd)> UpdateCallback;
3644 typedef std::function<void (Text path)> FileCallback;
@@ -116,6 +124,18 @@ class SettingsBase {
116124 }
117125
118126 public:
127+ void onUpdateFWStart (sets::onUpdateFWStart_t fn) {
128+ _onStart = fn;
129+ };
130+
131+ void onUpdateFWProgress (sets::onUpdateFWProgress_t fn) {
132+ _onProgress = fn;
133+ };
134+
135+ void onUpdateFWDone (sets::onUpdateFWDone_t fn) {
136+ _onDone = fn;
137+ };
138+
119139#ifndef SETT_NO_DB
120140 SettingsBase (const String& title = " " , GyverDB* db = nullptr ) : _title(title), _db(db) {
121141#else
Original file line number Diff line number Diff line change 88#endif
99
1010namespace sets {
11+ size_t OtaGetMaxSize (bool ota_flash)
12+ {
13+ size_t ota_size = 0 ;
14+ if (ota_flash) {
15+ #ifdef ESP8266
16+ ota_size = (size_t )((ESP.getFreeSketchSpace () - 0x1000 ) & 0xFFFFF000 );
17+ #else
18+ ota_size = UPDATE_SIZE_UNKNOWN;
19+ #endif
20+ } else {
21+ #ifdef ESP8266
22+ close_all_fs ();
23+ ota_size = (size_t )&_FS_end - (size_t )&_FS_start;
24+ #else
25+ ota_size = UPDATE_SIZE_UNKNOWN;
26+ #endif
27+ }
28+ return ota_size;
29+ }
1130
1231bool beginOta (bool ota_flash, bool async) {
13- size_t ota_size = 0 ;
32+ size_t ota_size = OtaGetMaxSize (ota_flash) ;
1433 int ota_type = 0 ;
1534
1635 if (ota_flash) {
1736 ota_type = U_FLASH;
18- #ifdef ESP8266
19- ota_size = (size_t )((ESP.getFreeSketchSpace () - 0x1000 ) & 0xFFFFF000 );
20- #else
21- ota_size = UPDATE_SIZE_UNKNOWN;
22- #endif
2337 } else {
2438#ifdef ESP8266
2539 ota_type = U_FS;
2640 close_all_fs ();
27- ota_size = (size_t )&_FS_end - (size_t )&_FS_start;
2841#else
2942 ota_type = U_SPIFFS;
30- ota_size = UPDATE_SIZE_UNKNOWN;
3143#endif
3244 }
3345
Original file line number Diff line number Diff line change 77#endif
88
99namespace sets {
10-
10+ size_t OtaGetMaxSize ( bool ota_flash = true );
1111bool beginOta (bool ota_flash = true , bool async = false );
1212
1313} // namespace sets
You can’t perform that action at this time.
0 commit comments