Skip to content

Commit d60d744

Browse files
NullMediaigrr
authored andcommitted
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
1 parent 3cfad27 commit d60d744

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

libraries/ArduinoOTA/ArduinoOTA.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@ ArduinoOTAClass::~ArduinoOTAClass(){
4949
}
5050
}
5151

52-
void ArduinoOTAClass::onStart(OTA_CALLBACK(fn)) {
52+
void ArduinoOTAClass::onStart(THandlerFunction fn) {
5353
_start_callback = fn;
5454
}
5555

56-
void ArduinoOTAClass::onEnd(OTA_CALLBACK(fn)) {
56+
void ArduinoOTAClass::onEnd(THandlerFunction fn) {
5757
_end_callback = fn;
5858
}
5959

60-
void ArduinoOTAClass::onProgress(OTA_CALLBACK_PROGRESS(fn)) {
60+
void ArduinoOTAClass::onProgress(THandlerFunction_Progress fn) {
6161
_progress_callback = fn;
6262
}
6363

64-
void ArduinoOTAClass::onError(OTA_CALLBACK_ERROR(fn)) {
64+
void ArduinoOTAClass::onError(THandlerFunction_Error fn) {
6565
_error_callback = fn;
6666
}
6767

libraries/ArduinoOTA/ArduinoOTA.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33

44
#include <ESP8266WiFi.h>
55
#include <WiFiUdp.h>
6+
#include <functional>
67

78
class UdpContext;
89

9-
#define OTA_CALLBACK(callback) void (*callback)()
10-
#define OTA_CALLBACK_PROGRESS(callback) void (*callback)(unsigned int, unsigned int)
11-
#define OTA_CALLBACK_ERROR(callback) void (*callback)(ota_error_t)
12-
1310
typedef enum {
1411
OTA_IDLE,
1512
OTA_WAITAUTH,
@@ -27,16 +24,20 @@ typedef enum {
2724
class ArduinoOTAClass
2825
{
2926
public:
27+
typedef std::function<void(void)> THandlerFunction;
28+
typedef std::function<void(ota_error_t)> THandlerFunction_Error;
29+
typedef std::function<void(unsigned int, unsigned int)> THandlerFunction_Progress;
30+
3031
ArduinoOTAClass();
3132
~ArduinoOTAClass();
3233
void setPort(uint16_t port);
3334
void setHostname(const char *hostname);
3435
String getHostname();
3536
void setPassword(const char *password);
36-
void onStart(OTA_CALLBACK(fn));
37-
void onEnd(OTA_CALLBACK(fn));
38-
void onProgress(OTA_CALLBACK_PROGRESS(fn));
39-
void onError(OTA_CALLBACK_ERROR (fn));
37+
void onStart(THandlerFunction fn);
38+
void onEnd(THandlerFunction fn);
39+
void onError(THandlerFunction_Error fn);
40+
void onProgress(THandlerFunction_Progress fn);
4041
void begin();
4142
void handle();
4243

@@ -54,10 +55,10 @@ class ArduinoOTAClass
5455
IPAddress _ota_ip;
5556
String _md5;
5657

57-
OTA_CALLBACK(_start_callback);
58-
OTA_CALLBACK(_end_callback);
59-
OTA_CALLBACK_ERROR(_error_callback);
60-
OTA_CALLBACK_PROGRESS(_progress_callback);
58+
THandlerFunction _start_callback;
59+
THandlerFunction _end_callback;
60+
THandlerFunction_Error _error_callback;
61+
THandlerFunction_Progress _progress_callback;
6162

6263
void _runUpdate(void);
6364
void _onRx(void);

0 commit comments

Comments
 (0)