add new sub callback typedef for io wrapper
This commit is contained in:
parent
f793f8d2d0
commit
ad83c09d20
@ -472,11 +472,16 @@ void Adafruit_MQTT::processPackets(int16_t timeout) {
|
||||
//Serial.print("*** calling double callback with : "); Serial.println(data);
|
||||
sub->callback_double(data);
|
||||
}
|
||||
else if (sub->callback_buffer != NULL) {
|
||||
else if (sub->callback_buffer != null) {
|
||||
// huh lets do the callback in buffer mode
|
||||
//Serial.print("*** calling buffer callback with : "); Serial.println(data);
|
||||
//serial.print("*** calling buffer callback with : "); serial.println(data);
|
||||
sub->callback_buffer((char *)sub->lastread, sub->datalen);
|
||||
}
|
||||
else if (sub->callback_io != null) {
|
||||
// huh lets do the callback in io mode
|
||||
//serial.print("*** calling io instance callback with : "); serial.println(data);
|
||||
sub->callback_io((char *)sub->lastread, sub->datalen);
|
||||
}
|
||||
}
|
||||
|
||||
// keep track over elapsed time
|
||||
@ -861,6 +866,7 @@ Adafruit_MQTT_Subscribe::Adafruit_MQTT_Subscribe(Adafruit_MQTT *mqttserver,
|
||||
callback_uint32t = 0;
|
||||
callback_buffer = 0;
|
||||
callback_double = 0;
|
||||
callback_io = 0;
|
||||
}
|
||||
|
||||
Adafruit_MQTT_Subscribe::Adafruit_MQTT_Subscribe(Adafruit_MQTT *mqttserver,
|
||||
@ -871,7 +877,7 @@ Adafruit_MQTT_Subscribe::Adafruit_MQTT_Subscribe(Adafruit_MQTT *mqttserver,
|
||||
datalen = 0;
|
||||
callback_uint32t = 0;
|
||||
callback_buffer = 0;
|
||||
callback_double = 0;
|
||||
callback_io = 0;
|
||||
}
|
||||
|
||||
void Adafruit_MQTT_Subscribe::setCallback(SubscribeCallbackUInt32Type cb) {
|
||||
@ -886,8 +892,13 @@ void Adafruit_MQTT_Subscribe::setCallback(SubscribeCallbackBufferType cb) {
|
||||
callback_buffer = cb;
|
||||
}
|
||||
|
||||
void Adafruit_MQTT_Subscribe::setCallback(SubscribeCallbackIOType cb) {
|
||||
callback_io = cb;
|
||||
}
|
||||
|
||||
void Adafruit_MQTT_Subscribe::removeCallback(void) {
|
||||
callback_uint32t = 0;
|
||||
callback_buffer = 0;
|
||||
callback_double = 0;
|
||||
callback_io = 0;
|
||||
}
|
||||
|
@ -108,12 +108,16 @@
|
||||
// eg max-subscription-payload-size
|
||||
#define SUBSCRIPTIONDATALEN 20
|
||||
|
||||
class AdafruitIO_Feed; // forward decl
|
||||
|
||||
//Function pointer that returns an int
|
||||
typedef void (*SubscribeCallbackUInt32Type)(uint32_t);
|
||||
// returns a double
|
||||
typedef void (*SubscribeCallbackDoubleType)(double);
|
||||
// returns a chunk of raw data
|
||||
typedef void (*SubscribeCallbackBufferType)(char *str, uint16_t len);
|
||||
// returns an io data wrapper instance
|
||||
typedef void (AdafruitIO_Feed::*SubscribeCallbackIOType)(char *str, uint16_t len);
|
||||
|
||||
extern void printBuffer(uint8_t *buffer, uint16_t len);
|
||||
|
||||
@ -284,6 +288,7 @@ class Adafruit_MQTT_Subscribe {
|
||||
void setCallback(SubscribeCallbackUInt32Type callb);
|
||||
void setCallback(SubscribeCallbackDoubleType callb);
|
||||
void setCallback(SubscribeCallbackBufferType callb);
|
||||
void setCallback(SubscribeCallbackIOType callb);
|
||||
void removeCallback(void);
|
||||
|
||||
const char *topic;
|
||||
@ -297,6 +302,7 @@ class Adafruit_MQTT_Subscribe {
|
||||
SubscribeCallbackUInt32Type callback_uint32t;
|
||||
SubscribeCallbackDoubleType callback_double;
|
||||
SubscribeCallbackBufferType callback_buffer;
|
||||
SubscribeCallbackIOType callback_io;
|
||||
|
||||
private:
|
||||
Adafruit_MQTT *mqtt;
|
||||
|
Loading…
Reference in New Issue
Block a user