change callbacks to vector

This commit is contained in:
Siwat Sirichai 2023-12-30 00:49:09 +07:00
parent 71475ef2f1
commit 011710fe82
19 changed files with 207 additions and 109 deletions

View file

@ -1,7 +1,10 @@
#include <ESPMegaDisplay.hpp>
#include <TimeStructure.hpp>
#include <ESPMegaIoT.hpp>
#include <DigitalInputCard.hpp>
#include <DigitalOutputCard.hpp>
// Page IDs
#define INTERNAL_DISPLAY_DASHBOARD_PAGE 0
#define INTERNAL_DISPLAY_INPUT_PAGE 1
#define INTERNAL_DISPLAY_OUTPUT_PAGE 2
@ -12,19 +15,31 @@
#define PIC_LAN_CONNECTED 3
#define PIC_MQTT_DISCONNECTED 4
#define PIC_MQTT_CONNECTED 5
#define PIC_PWM_BAR_ON 33
#define PIC_PWM_BAR_OFF 48
// Messages
#define MSG_MQTT_CONNECTED "BMS Managed"
#define MSG_MQTT_DISCONNECTED "Standalone"
// Refresh Interval
#define INTERNAL_DISPLAY_CLOCK_REFRESH_INTERVAL 15000
#define INTERNAL_DISPLAY_TOP_BAR_REFRESH_INTERVAL 5000
class InternalDisplay : public ESPMegaDisplay {
public:
InternalDisplay(HardwareSerial *displayAdapter);
void begin(ESPMegaIoT *iot, std::function<rtctime_t()> getRtcTime);
void loop();
void bindInputCard(uint8_t card_id);
void bindOutputCard(uint8_t card_id);
void bindInputCard(DigitalInputCard *inputCard);
void bindOutputCard(DigitalOutputCard *outputCard);
private:
uint8_t bindedInputCard;
uint8_t bindedOutputCard;
DigitalInputCard *inputCard;
DigitalOutputCard *outputCard;
// Previously registered callbacks of input and output cards
// We need to call them when the respective card is binded to the display
// Because we will replace the callbacks with the display's own callbacks
void handleInputStateChange(uint8_t pin, bool state);
void handlePwmStateChange(uint8_t pin, bool state, uint16_t value);
void handlePageChange(uint8_t page);
@ -44,6 +59,8 @@ class InternalDisplay : public ESPMegaDisplay {
void refreshInput();
void refreshOutput();
void refreshAC();
MqttConfig *mqttConfig;
NetworkConfig *networkConfig;
// Pointers to various data
ESPMegaIoT *iot;
std::function<rtctime_t()> getRtcTime;