File tree 2 files changed +25
-1
lines changed
2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -37,12 +37,18 @@ UpdaterClass::UpdaterClass()
37
37
, _command(U_FLASH)
38
38
, _hash(nullptr )
39
39
, _verify(nullptr )
40
+ , _progress_callback(nullptr )
40
41
{
41
42
#if ARDUINO_SIGNING
42
43
installSignature (&hash, &sign);
43
44
#endif
44
45
}
45
46
47
+ UpdaterClass& UpdaterClass::onProgress (THandlerFunction_Progress fn) {
48
+ _progress_callback = fn;
49
+ return *this ;
50
+ }
51
+
46
52
void UpdaterClass::_reset () {
47
53
if (_buffer)
48
54
delete[] _buffer;
@@ -440,7 +446,9 @@ size_t UpdaterClass::writeStream(Stream &data) {
440
446
_reset ();
441
447
return 0 ;
442
448
}
443
-
449
+ if (_progress_callback) {
450
+ _progress_callback (0 , _size);
451
+ }
444
452
if (_ledPin != -1 ) {
445
453
pinMode (_ledPin, OUTPUT);
446
454
}
@@ -471,8 +479,14 @@ size_t UpdaterClass::writeStream(Stream &data) {
471
479
if ((_bufferLen == remaining () || _bufferLen == _bufferSize) && !_writeBuffer ())
472
480
return written;
473
481
written += toRead;
482
+ if (_progress_callback) {
483
+ _progress_callback (progress (), _size);
484
+ }
474
485
yield ();
475
486
}
487
+ if (_progress_callback) {
488
+ _progress_callback (progress (), _size);
489
+ }
476
490
return written;
477
491
}
478
492
Original file line number Diff line number Diff line change 4
4
#include < Arduino.h>
5
5
#include < flash_utils.h>
6
6
#include < MD5Builder.h>
7
+ #include < functional>
7
8
8
9
#define UPDATE_ERROR_OK (0 )
9
10
#define UPDATE_ERROR_WRITE (1 )
@@ -48,6 +49,8 @@ class UpdaterVerifyClass {
48
49
49
50
class UpdaterClass {
50
51
public:
52
+ typedef std::function<void (size_t , size_t )> THandlerFunction_Progress;
53
+
51
54
UpdaterClass ();
52
55
53
56
/* Optionally add a cryptographic signature verification hash and method */
@@ -111,6 +114,11 @@ class UpdaterClass {
111
114
*/
112
115
void md5 (uint8_t * result){ return _md5.getBytes (result); }
113
116
117
+ /*
118
+ This callback will be called when Updater is receiving data
119
+ */
120
+ UpdaterClass& onProgress (THandlerFunction_Progress fn);
121
+
114
122
// Helpers
115
123
uint8_t getError (){ return _error; }
116
124
void clearError (){ _error = UPDATE_ERROR_OK; }
@@ -191,6 +199,8 @@ class UpdaterClass {
191
199
// Optional signed binary verification
192
200
UpdaterHashClass *_hash;
193
201
UpdaterVerifyClass *_verify;
202
+ // Optional progress callback function
203
+ THandlerFunction_Progress _progress_callback;
194
204
};
195
205
196
206
extern UpdaterClass Update;
You can’t perform that action at this time.
0 commit comments