3
3
4
4
#include < ESP8266WiFi.h>
5
5
#include < WiFiUdp.h>
6
+ #include < functional>
6
7
7
8
class UdpContext ;
8
9
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
-
13
10
typedef enum {
14
11
OTA_IDLE,
15
12
OTA_WAITAUTH,
@@ -27,16 +24,20 @@ typedef enum {
27
24
class ArduinoOTAClass
28
25
{
29
26
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
+
30
31
ArduinoOTAClass ();
31
32
~ArduinoOTAClass ();
32
33
void setPort (uint16_t port);
33
34
void setHostname (const char *hostname);
34
35
String getHostname ();
35
36
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 );
40
41
void begin ();
41
42
void handle ();
42
43
@@ -54,10 +55,10 @@ class ArduinoOTAClass
54
55
IPAddress _ota_ip;
55
56
String _md5;
56
57
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;
61
62
62
63
void _runUpdate (void );
63
64
void _onRx (void );
0 commit comments