ESPMegaPRO-v3-SDK/Template Project/lib/ESPMegaPRO/DigitalInputIoT.hpp

26 lines
926 B
C++

#pragma once
#include <IoTComponent.hpp>
#include <DigitalInputCard.hpp>
#define PUBLISH_ENABLE_TOPIC "publish_enable"
class DigitalInputIoT : public IoTComponent {
public:
bool begin(uint8_t card_id, DigitalInputCard *card, PubSubClient *mqtt, char *base_topic);
void handleMqttMessage(char *topic, char *payload);
void publishDigitalInputs();
void publishDigitalInput(uint8_t pin);
void setDigitalInputsPublishEnabled(bool enabled);
void handleValueChange(uint8_t pin, uint8_t value);
void registerChangeCallback(std::function<void(uint8_t, uint8_t)> callback);
void publishReport();
uint8_t getType();
private:
uint8_t card_id;
PubSubClient *mqtt;
char *base_topic;
std::function<void(uint8_t, uint8_t)> change_callback;
bool digital_inputs_publish_enabled = false;
DigitalInputCard *card;
};