2023-12-28 04:41:20 +00:00
|
|
|
#pragma once
|
2023-12-28 05:46:39 +00:00
|
|
|
#include <IoTComponent.hpp>
|
2023-12-28 04:41:20 +00:00
|
|
|
#include <ExpansionCard.hpp>
|
2023-12-28 05:46:39 +00:00
|
|
|
#include <DigitalOutputCard.hpp>
|
2023-12-28 04:41:20 +00:00
|
|
|
|
2023-12-28 05:46:39 +00:00
|
|
|
class DigitalOutputIoT : public IoTComponent {
|
|
|
|
public:
|
2023-12-28 06:14:18 +00:00
|
|
|
DigitalOutputIoT();
|
|
|
|
~DigitalOutputIoT();
|
2023-12-28 05:46:39 +00:00
|
|
|
bool begin(ExpansionCard *card);
|
|
|
|
void handleMqttMessage(char *topic, char *payload);
|
|
|
|
void publishDigitalOutputs();
|
|
|
|
void publishDigitalOutput(uint8_t pin);
|
2023-12-28 06:14:18 +00:00
|
|
|
void publishDigitalOutputState(uint8_t pin);
|
|
|
|
void publishDigitalOutputValue(uint8_t pin);
|
2023-12-28 05:46:39 +00:00
|
|
|
void setDigitalOutputsPublishEnabled(bool enabled);
|
2023-12-28 06:14:18 +00:00
|
|
|
void handleValueChange(uint8_t pin, bool state, uint16_t value);
|
2023-12-28 05:46:39 +00:00
|
|
|
void registerValueChangeCallback(void (*callback)(uint8_t, bool, uint16_t));
|
2023-12-28 06:14:18 +00:00
|
|
|
void deregisterValueChangeCallback();
|
|
|
|
void publishReport();
|
|
|
|
uint8_t getType();
|
2023-12-28 05:46:39 +00:00
|
|
|
private:
|
|
|
|
bool digital_outputs_publish_enabled = false;
|
|
|
|
bool processSetStateMessage(char *topic, char *payload, uint8_t topic_length);
|
|
|
|
bool processSetValueMessage(char *topic, char *payload, uint8_t topic_length);
|
|
|
|
bool processRequestStateMessage(char *topic, char *payload, uint8_t topic_length);
|
2023-12-28 06:14:18 +00:00
|
|
|
void (*value_change_callback)(uint8_t, bool, uint16_t);
|
2023-12-28 05:46:39 +00:00
|
|
|
DigitalOutputCard *card;
|
2023-12-28 06:14:18 +00:00
|
|
|
char *state_report_topic;
|
|
|
|
char *value_report_topic;
|
2023-12-28 05:46:39 +00:00
|
|
|
uint8_t set_state_length;
|
|
|
|
uint8_t set_value_length;
|
|
|
|
uint8_t state_length;
|
|
|
|
uint8_t value_length;
|
|
|
|
uint8_t request_state_length;
|
|
|
|
uint8_t publish_enable_length;
|
|
|
|
};
|