Skip to content

ArduinoOTA library change #2013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jun 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions libraries/ArduinoOTA/ArduinoOTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
25 changes: 13 additions & 12 deletions libraries/ArduinoOTA/ArduinoOTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <functional>

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,
Expand All @@ -27,15 +24,19 @@ typedef enum {
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);
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();

Expand All @@ -53,10 +54,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);
Expand Down