Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-esp32
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-esp32
Commits
2633fc3c
Commit
2633fc3c
authored
Jan 18, 2018
by
Clemens Kirchgatterer
Committed by
Me No Dev
Jan 18, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add progress callback to Update::writeStream(). (#948)
parent
78acedd2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
1 deletion
+26
-1
libraries/Update/src/Update.h
libraries/Update/src/Update.h
+11
-0
libraries/Update/src/Updater.cpp
libraries/Update/src/Updater.cpp
+15
-1
No files found.
libraries/Update/src/Update.h
View file @
2633fc3c
...
...
@@ -3,6 +3,7 @@
#include <Arduino.h>
#include <MD5Builder.h>
#include <functional>
#include "esp_partition.h"
#define UPDATE_ERROR_OK (0)
...
...
@@ -27,7 +28,15 @@
class
UpdateClass
{
public:
typedef
std
::
function
<
void
(
size_t
,
size_t
)
>
THandlerFunction_Progress
;
UpdateClass
();
/*
This callback will be called when Update is receiving data
*/
UpdateClass
&
onProgress
(
THandlerFunction_Progress
fn
);
/*
Call this to check the space needed for the update
Will return false if there is not enough space
...
...
@@ -153,6 +162,8 @@ class UpdateClass {
bool
_verifyHeader
(
uint8_t
data
);
bool
_verifyEnd
();
THandlerFunction_Progress
_progress_callback
;
uint8_t
_error
;
uint8_t
*
_buffer
;
size_t
_bufferLen
;
...
...
libraries/Update/src/Updater.cpp
View file @
2633fc3c
...
...
@@ -71,9 +71,15 @@ UpdateClass::UpdateClass()
,
_progress
(
0
)
,
_command
(
U_FLASH
)
,
_partition
(
NULL
)
,
_progress_callback
(
NULL
)
{
}
UpdateClass
&
UpdateClass
::
onProgress
(
THandlerFunction_Progress
fn
)
{
_progress_callback
=
fn
;
return
*
this
;
}
void
UpdateClass
::
_reset
()
{
if
(
_buffer
)
delete
[]
_buffer
;
...
...
@@ -306,7 +312,9 @@ size_t UpdateClass::writeStream(Stream &data) {
_reset
();
return
0
;
}
if
(
_progress_callback
)
{
_progress_callback
(
0
,
_size
);
}
while
(
remaining
())
{
toRead
=
data
.
readBytes
(
_buffer
+
_bufferLen
,
(
SPI_FLASH_SEC_SIZE
-
_bufferLen
));
if
(
toRead
==
0
)
{
//Timeout
...
...
@@ -321,6 +329,12 @@ size_t UpdateClass::writeStream(Stream &data) {
if
((
_bufferLen
==
remaining
()
||
_bufferLen
==
SPI_FLASH_SEC_SIZE
)
&&
!
_writeBuffer
())
return
written
;
written
+=
toRead
;
if
(
_progress_callback
)
{
_progress_callback
(
_progress
,
_size
);
}
}
if
(
_progress_callback
)
{
_progress_callback
(
_size
,
_size
);
}
return
written
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment