From d60d744b598838544f5dfb40489a80acc8e3d00e Mon Sep 17 00:00:00 2001 From: NullMedia Date: Wed, 1 Jun 2016 04:10:29 +0100 Subject: [PATCH] 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 --- libraries/ArduinoOTA/ArduinoOTA.cpp | 8 ++++---- libraries/ArduinoOTA/ArduinoOTA.h | 25 +++++++++++++------------ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/libraries/ArduinoOTA/ArduinoOTA.cpp b/libraries/ArduinoOTA/ArduinoOTA.cpp index ec4e4ff74..ea45a6e85 100644 --- a/libraries/ArduinoOTA/ArduinoOTA.cpp +++ b/libraries/ArduinoOTA/ArduinoOTA.cpp @@ -49,19 +49,19 @@ ArduinoOTAClass::~ArduinoOTAClass(){ } } -void ArduinoOTAClass::onStart(OTA_CALLBACK(fn)) { +void ArduinoOTAClass::onStart(THandlerFunction fn) { _start_callback = fn; } -void ArduinoOTAClass::onEnd(OTA_CALLBACK(fn)) { +void ArduinoOTAClass::onEnd(THandlerFunction fn) { _end_callback = fn; } -void ArduinoOTAClass::onProgress(OTA_CALLBACK_PROGRESS(fn)) { +void ArduinoOTAClass::onProgress(THandlerFunction_Progress fn) { _progress_callback = fn; } -void ArduinoOTAClass::onError(OTA_CALLBACK_ERROR(fn)) { +void ArduinoOTAClass::onError(THandlerFunction_Error fn) { _error_callback = fn; } diff --git a/libraries/ArduinoOTA/ArduinoOTA.h b/libraries/ArduinoOTA/ArduinoOTA.h index d914146c4..2cae458cc 100644 --- a/libraries/ArduinoOTA/ArduinoOTA.h +++ b/libraries/ArduinoOTA/ArduinoOTA.h @@ -3,13 +3,10 @@ #include #include +#include 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 { OTA_IDLE, OTA_WAITAUTH, @@ -27,16 +24,20 @@ typedef enum { class ArduinoOTAClass { public: + typedef std::function THandlerFunction; + typedef std::function THandlerFunction_Error; + typedef std::function THandlerFunction_Progress; + ArduinoOTAClass(); ~ArduinoOTAClass(); void setPort(uint16_t port); void setHostname(const char *hostname); String getHostname(); void setPassword(const char *password); - void onStart(OTA_CALLBACK(fn)); - void onEnd(OTA_CALLBACK(fn)); - void onProgress(OTA_CALLBACK_PROGRESS(fn)); - void onError(OTA_CALLBACK_ERROR (fn)); + void onStart(THandlerFunction fn); + void onEnd(THandlerFunction fn); + void onError(THandlerFunction_Error fn); + void onProgress(THandlerFunction_Progress fn); void begin(); void handle(); @@ -54,10 +55,10 @@ class ArduinoOTAClass IPAddress _ota_ip; String _md5; - OTA_CALLBACK(_start_callback); - OTA_CALLBACK(_end_callback); - OTA_CALLBACK_ERROR(_error_callback); - OTA_CALLBACK_PROGRESS(_progress_callback); + THandlerFunction _start_callback; + THandlerFunction _end_callback; + THandlerFunction_Error _error_callback; + THandlerFunction_Progress _progress_callback; void _runUpdate(void); void _onRx(void);