1#ifdef NOT_FOR_SHOW_ONLY
4#ifndef ESP8266UPDATER_H
5#define ESP8266UPDATER_H
10#include "esp_partition.h"
12#define UPDATE_ERROR_OK (0)
13#define UPDATE_ERROR_WRITE (1)
14#define UPDATE_ERROR_ERASE (2)
15#define UPDATE_ERROR_READ (3)
16#define UPDATE_ERROR_SPACE (4)
17#define UPDATE_ERROR_SIZE (5)
18#define UPDATE_ERROR_STREAM (6)
19#define UPDATE_ERROR_MD5 (7)
20#define UPDATE_ERROR_MAGIC_BYTE (8)
21#define UPDATE_ERROR_ACTIVATE (9)
22#define UPDATE_ERROR_NO_PARTITION (10)
23#define UPDATE_ERROR_BAD_ARGUMENT (11)
24#define UPDATE_ERROR_ABORT (12)
26#define UPDATE_SIZE_UNKNOWN 0xFFFFFFFF
32#define ENCRYPTED_BLOCK_SIZE 16
36 typedef std::function<void(
size_t,
size_t)> THandlerFunction_Progress;
43 UpdateClass& onProgress(THandlerFunction_Progress fn);
49 bool begin(
size_t size=UPDATE_SIZE_UNKNOWN,
int command = U_FLASH,
int ledPin = -1, uint8_t ledOn = LOW,
const char *label = NULL);
55 size_t write(uint8_t *data,
size_t len);
64 size_t writeStream(Stream &data);
76 bool end(
bool evenIfRemaining =
false);
86 void printError(Print &out);
88 const char * errorString();
93 bool setMD5(
const char * expected_md5);
98 String md5String(
void){
return _md5.toString(); }
103 void md5(uint8_t * result){
return _md5.getBytes(result); }
106 uint8_t getError(){
return _error; }
107 void clearError(){ _error = UPDATE_ERROR_OK; }
108 bool hasError(){
return _error != UPDATE_ERROR_OK; }
109 bool isRunning(){
return _size > 0; }
110 bool isFinished(){
return _progress == _size; }
111 size_t size(){
return _size; }
112 size_t progress(){
return _progress; }
113 size_t remaining(){
return _size - _progress; }
122 size_t write(T &data){
124 if (hasError() || !isRunning())
127 size_t available = data.available();
129 if(_bufferLen + available > remaining()){
130 available = remaining() - _bufferLen;
132 if(_bufferLen + available > 4096) {
133 size_t toBuff = 4096 - _bufferLen;
134 data.read(_buffer + _bufferLen, toBuff);
135 _bufferLen += toBuff;
140 data.read(_buffer + _bufferLen, available);
141 _bufferLen += available;
142 written += available;
143 if(_bufferLen == remaining()) {
144 if(!_writeBuffer()) {
151 available = data.available();
167 void _abort(uint8_t err);
169 bool _verifyHeader(uint8_t data);
171 bool _enablePartition(
const esp_partition_t* partition);
176 uint8_t *_skipBuffer;
179 THandlerFunction_Progress _progress_callback;
182 const esp_partition_t* _partition;
191extern UpdateClass Update;