1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00
NullMedia d60d744b59 ArduinoOTA library change (#2013)
* Fixed callbacks to allow lambda capture

* Update ArduinoOTA.cpp

* Fixed callbacks to allow lambda capture

* Fixed callbacks to allow lambda capture

* Update ArduinoOTA.h

* Tests update

Update ArduinoOTA.h

Fixed callbacks to allow lambda capture

* Modified callbacks to enable lambda capture

* Modified callbacks to enable lambda capture
2016-06-01 11:10:29 +08:00

72 lines
1.5 KiB
C++

#ifndef __ARDUINO_OTA_H
#define __ARDUINO_OTA_H
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <functional>
class UdpContext;
typedef enum {
OTA_IDLE,
OTA_WAITAUTH,
OTA_RUNUPDATE
} ota_state_t;
typedef enum {
OTA_AUTH_ERROR,
OTA_BEGIN_ERROR,
OTA_CONNECT_ERROR,
OTA_RECEIVE_ERROR,
OTA_END_ERROR
} ota_error_t;
class ArduinoOTAClass
{
public:
typedef std::function<void(void)> THandlerFunction;
typedef std::function<void(ota_error_t)> THandlerFunction_Error;
typedef std::function<void(unsigned int, unsigned int)> THandlerFunction_Progress;
ArduinoOTAClass();
~ArduinoOTAClass();
void setPort(uint16_t port);
void setHostname(const char *hostname);
String getHostname();
void setPassword(const char *password);
void onStart(THandlerFunction fn);
void onEnd(THandlerFunction fn);
void onError(THandlerFunction_Error fn);
void onProgress(THandlerFunction_Progress fn);
void begin();
void handle();
private:
int _port;
String _password;
String _hostname;
String _nonce;
UdpContext *_udp_ota;
bool _initialized;
ota_state_t _state;
int _size;
int _cmd;
int _ota_port;
IPAddress _ota_ip;
String _md5;
THandlerFunction _start_callback;
THandlerFunction _end_callback;
THandlerFunction_Error _error_callback;
THandlerFunction_Progress _progress_callback;
void _runUpdate(void);
void _onRx(void);
int parseInt(void);
String readStringUntil(char end);
};
extern ArduinoOTAClass ArduinoOTA;
#endif /* __ARDUINO_OTA_H */