1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

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
This commit is contained in:
NullMedia 2016-06-01 04:10:29 +01:00 committed by Ivan Grokhotkov
parent 3cfad27e38
commit d60d744b59
2 changed files with 17 additions and 16 deletions

View File

@ -49,19 +49,19 @@ ArduinoOTAClass::~ArduinoOTAClass(){
} }
} }
void ArduinoOTAClass::onStart(OTA_CALLBACK(fn)) { void ArduinoOTAClass::onStart(THandlerFunction fn) {
_start_callback = fn; _start_callback = fn;
} }
void ArduinoOTAClass::onEnd(OTA_CALLBACK(fn)) { void ArduinoOTAClass::onEnd(THandlerFunction fn) {
_end_callback = fn; _end_callback = fn;
} }
void ArduinoOTAClass::onProgress(OTA_CALLBACK_PROGRESS(fn)) { void ArduinoOTAClass::onProgress(THandlerFunction_Progress fn) {
_progress_callback = fn; _progress_callback = fn;
} }
void ArduinoOTAClass::onError(OTA_CALLBACK_ERROR(fn)) { void ArduinoOTAClass::onError(THandlerFunction_Error fn) {
_error_callback = fn; _error_callback = fn;
} }

View File

@ -3,13 +3,10 @@
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <WiFiUdp.h> #include <WiFiUdp.h>
#include <functional>
class UdpContext; class UdpContext;
#define OTA_CALLBACK(callback) void (*callback)()
#define OTA_CALLBACK_PROGRESS(callback) void (*callback)(unsigned int, unsigned int)
#define OTA_CALLBACK_ERROR(callback) void (*callback)(ota_error_t)
typedef enum { typedef enum {
OTA_IDLE, OTA_IDLE,
OTA_WAITAUTH, OTA_WAITAUTH,
@ -27,16 +24,20 @@ typedef enum {
class ArduinoOTAClass class ArduinoOTAClass
{ {
public: 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();
~ArduinoOTAClass(); ~ArduinoOTAClass();
void setPort(uint16_t port); void setPort(uint16_t port);
void setHostname(const char *hostname); void setHostname(const char *hostname);
String getHostname(); String getHostname();
void setPassword(const char *password); void setPassword(const char *password);
void onStart(OTA_CALLBACK(fn)); void onStart(THandlerFunction fn);
void onEnd(OTA_CALLBACK(fn)); void onEnd(THandlerFunction fn);
void onProgress(OTA_CALLBACK_PROGRESS(fn)); void onError(THandlerFunction_Error fn);
void onError(OTA_CALLBACK_ERROR (fn)); void onProgress(THandlerFunction_Progress fn);
void begin(); void begin();
void handle(); void handle();
@ -54,10 +55,10 @@ class ArduinoOTAClass
IPAddress _ota_ip; IPAddress _ota_ip;
String _md5; String _md5;
OTA_CALLBACK(_start_callback); THandlerFunction _start_callback;
OTA_CALLBACK(_end_callback); THandlerFunction _end_callback;
OTA_CALLBACK_ERROR(_error_callback); THandlerFunction_Error _error_callback;
OTA_CALLBACK_PROGRESS(_progress_callback); THandlerFunction_Progress _progress_callback;
void _runUpdate(void); void _runUpdate(void);
void _onRx(void); void _onRx(void);