2023-12-28 05:46:39 +00:00
|
|
|
#pragma once
|
2023-12-27 20:09:41 +00:00
|
|
|
|
2023-12-28 05:46:39 +00:00
|
|
|
#include <IoTComponent.hpp>
|
2023-12-27 20:09:41 +00:00
|
|
|
#include <DigitalInputCard.hpp>
|
2023-12-28 05:46:39 +00:00
|
|
|
|
2023-12-28 12:11:12 +00:00
|
|
|
#define PUBLISH_ENABLE_TOPIC "publish_enable"
|
|
|
|
|
2023-12-28 05:46:39 +00:00
|
|
|
class DigitalInputIoT : public IoTComponent {
|
2023-12-27 20:09:41 +00:00
|
|
|
public:
|
2023-12-28 07:08:10 +00:00
|
|
|
bool begin(uint8_t card_id, DigitalInputCard *card, PubSubClient *mqtt, char *base_topic);
|
2023-12-27 20:09:41 +00:00
|
|
|
void handleMqttMessage(char *topic, char *payload);
|
|
|
|
void publishDigitalInputs();
|
2023-12-28 12:11:12 +00:00
|
|
|
void publishDigitalInput(uint8_t pin);
|
2023-12-27 20:09:41 +00:00
|
|
|
void setDigitalInputsPublishEnabled(bool enabled);
|
|
|
|
void handleValueChange(uint8_t pin, uint8_t value);
|
2023-12-28 12:11:12 +00:00
|
|
|
void registerChangeCallback(std::function<void(uint8_t, uint8_t)> callback);
|
2023-12-28 06:14:18 +00:00
|
|
|
void publishReport();
|
|
|
|
uint8_t getType();
|
2023-12-27 20:09:41 +00:00
|
|
|
private:
|
2023-12-28 12:11:12 +00:00
|
|
|
uint8_t card_id;
|
|
|
|
PubSubClient *mqtt;
|
|
|
|
char *base_topic;
|
|
|
|
std::function<void(uint8_t, uint8_t)> change_callback;
|
2023-12-27 20:09:41 +00:00
|
|
|
bool digital_inputs_publish_enabled = false;
|
|
|
|
DigitalInputCard *card;
|
|
|
|
};
|