2023-12-27 20:09:41 +00:00
|
|
|
#pragma once
|
2023-12-28 05:46:39 +00:00
|
|
|
#include <IoTComponent.hpp>
|
2023-12-27 20:09:41 +00:00
|
|
|
#include <AnalogCard.hpp>
|
2023-12-28 17:39:11 +00:00
|
|
|
|
|
|
|
#define DAC_SET_STATE_TOPIC "/set/state"
|
|
|
|
#define DAC_SET_VALUE_TOPIC "/set/value"
|
|
|
|
#define DAC_STATE_TOPIC "/dac/00/state"
|
|
|
|
#define DAC_VALUE_TOPIC "/dac/00/value"
|
|
|
|
#define DAC_PUBLISH_ENABLE_TOPIC "/publish_enable"
|
|
|
|
#define REQUEST_STATE_TOPIC "requeststate"
|
|
|
|
|
2023-12-28 05:46:39 +00:00
|
|
|
class AnalogIoT : public IoTComponent {
|
2023-12-27 20:09:41 +00:00
|
|
|
public:
|
2023-12-28 06:14:18 +00:00
|
|
|
AnalogIoT();
|
|
|
|
~AnalogIoT();
|
2023-12-28 17:39:11 +00:00
|
|
|
bool begin(uint8_t card_id, ExpansionCard *card, PubSubClient *mqtt, char *base_topic);
|
2023-12-27 20:09:41 +00:00
|
|
|
void handleMqttMessage(char *topic, char *payload);
|
2023-12-28 17:39:11 +00:00
|
|
|
void handleDACChange(uint8_t pin, uint16_t value);
|
2023-12-27 20:09:41 +00:00
|
|
|
void publishADCs();
|
2023-12-28 17:39:11 +00:00
|
|
|
void publishADC(uint8_t pin);
|
|
|
|
void publishDACs();
|
|
|
|
void publishDAC(uint8_t pin);
|
|
|
|
void publishDACState(uint8_t pin);
|
|
|
|
void publishDACValue(uint8_t pin);
|
2023-12-27 20:09:41 +00:00
|
|
|
void setADCsPublishInterval(uint32_t interval);
|
|
|
|
void setADCsPublishEnabled(bool enabled);
|
2023-12-28 17:39:11 +00:00
|
|
|
void registerDACChangeCallback(std::function<void(uint8_t, uint16_t)> callback);
|
|
|
|
void deregisterDACChangeCallback();
|
|
|
|
void registerADCConversionCallback(std::function<void(uint8_t, uint16_t)> callback);
|
|
|
|
void deregisterADCConversionCallback();
|
|
|
|
void setADCConversionInterval(uint8_t pin, uint16_t interval);
|
|
|
|
void setADCConversionEnabled(uint8_t pin, bool enabled);
|
|
|
|
bool processADCSetConversionIntervalMessage(char *topic, char *payload, uint8_t topic_length);
|
|
|
|
bool processADCSetConversionEnabledMessage(char *topic, char *payload, uint8_t topic_length);
|
|
|
|
bool processDACSetStateMessage(char *topic, char *payload, uint8_t topic_length);
|
|
|
|
bool processDACSetValueMessage(char *topic, char *payload, uint8_t topic_length);
|
|
|
|
bool processRequestStateMessage(char *topic, char *payload, uint8_t topic_length);
|
|
|
|
void publishReport();
|
|
|
|
void subscribe();
|
|
|
|
void loop();
|
2023-12-28 06:14:18 +00:00
|
|
|
uint8_t getType();
|
2023-12-27 20:09:41 +00:00
|
|
|
private:
|
2023-12-28 17:39:11 +00:00
|
|
|
uint8_t dac_set_state_length;
|
|
|
|
uint8_t dac_set_value_length;
|
|
|
|
uint8_t dac_state_length;
|
|
|
|
uint8_t dac_value_length;
|
|
|
|
uint8_t request_state_length;
|
|
|
|
uint8_t dac_publish_enable_length;
|
2023-12-27 20:09:41 +00:00
|
|
|
uint32_t last_adc_publish = 0;
|
|
|
|
AnalogCard *card;
|
2023-12-28 17:39:11 +00:00
|
|
|
bool adc_publish_enabled[8];
|
|
|
|
uint16_t adc_conversion_interval[8];
|
|
|
|
uint32_t last_adc_conversion[8];
|
|
|
|
std::function<void(uint8_t, uint16_t)> dac_change_callback;
|
|
|
|
std::function<void(uint8_t, uint16_t)> adc_conversion_callback;
|
2023-12-27 20:09:41 +00:00
|
|
|
};
|