ESPMegaPRO-v3-SDK/ESPMegaPRO-firmware/lib/ESPMegaPRO/InternalDisplay.hpp

91 lines
3.2 KiB
C++
Raw Normal View History

2023-12-30 06:49:37 +00:00
#pragma once
2023-12-29 13:04:25 +00:00
#include <ESPMegaDisplay.hpp>
2023-12-29 16:43:12 +00:00
#include <TimeStructure.hpp>
#include <ESPMegaIoT.hpp>
2023-12-29 17:49:09 +00:00
#include <DigitalInputCard.hpp>
#include <DigitalOutputCard.hpp>
2023-12-30 15:50:19 +00:00
#include <ClimateCard.hpp>
2023-12-29 13:04:25 +00:00
2023-12-29 17:49:09 +00:00
// Page IDs
2023-12-30 15:50:19 +00:00
#define INTERNAL_DISPLAY_BOOT_PAGE 0
#define INTERNAL_DISPLAY_DASHBOARD_PAGE 1
#define INTERNAL_DISPLAY_INPUT_PAGE 2
#define INTERNAL_DISPLAY_OUTPUT_PAGE 3
#define INTERNAL_DISPLAY_AC_PAGE 4
#define INTERNAL_DISPLAY_PWM_ADJUSTMENT_PAGE 5
#define INTERNAL_DISPLAY_NETWORK_CONFIG_PAGE 6
#define INTERNAL_DISPLAY_OTA_PAGE 9
#define INTERNAL_DISPLAY_CLIMATE_NULL_PTR_PAGE 10
#define INTERNAL_DISPLAY_MQTT_CONFIG_PAGE 11
#define INTERNAL_DISPLAY_INPUT_NULL_PTR_PAGE 12
#define INTERNAL_DISPLAY_OUTPUT_NULL_PTR_PAGE 13
2023-12-29 13:04:25 +00:00
2023-12-29 16:43:12 +00:00
// Picture IDs
#define PIC_LAN_DISCONNECTED 2
#define PIC_LAN_CONNECTED 3
#define PIC_MQTT_DISCONNECTED 4
#define PIC_MQTT_CONNECTED 5
2023-12-29 17:49:09 +00:00
#define PIC_PWM_BAR_ON 33
#define PIC_PWM_BAR_OFF 48
2023-12-29 16:43:12 +00:00
2023-12-29 17:49:09 +00:00
// Messages
#define MSG_MQTT_CONNECTED "BMS Managed"
#define MSG_MQTT_DISCONNECTED "Standalone"
2023-12-30 15:50:19 +00:00
#define MSG_PWM_ADJUSTMENT_STATE_ON "ON"
#define MSG_PWM_ADJUSTMENT_STATE_OFF "OFF"
2023-12-29 17:49:09 +00:00
// Refresh Interval
#define INTERNAL_DISPLAY_CLOCK_REFRESH_INTERVAL 15000
#define INTERNAL_DISPLAY_TOP_BAR_REFRESH_INTERVAL 5000
2023-12-29 16:43:12 +00:00
2023-12-30 15:50:19 +00:00
// Touch Types
#define TOUCH_TYPE_PRESS 0x01
#define TOUCH_TYPE_RELEASE 0x0
2023-12-29 13:04:25 +00:00
class InternalDisplay : public ESPMegaDisplay {
public:
2023-12-29 14:41:19 +00:00
InternalDisplay(HardwareSerial *displayAdapter);
2023-12-29 16:43:12 +00:00
void begin(ESPMegaIoT *iot, std::function<rtctime_t()> getRtcTime);
2023-12-29 13:04:25 +00:00
void loop();
2023-12-29 17:49:09 +00:00
void bindInputCard(DigitalInputCard *inputCard);
void bindOutputCard(DigitalOutputCard *outputCard);
2023-12-30 15:50:19 +00:00
void bindClimateCard(ClimateCard *climateCard);
2023-12-29 16:43:12 +00:00
2023-12-29 13:04:25 +00:00
private:
2023-12-29 17:49:09 +00:00
DigitalInputCard *inputCard;
DigitalOutputCard *outputCard;
2023-12-30 15:50:19 +00:00
ClimateCard *climateCard;
2023-12-29 13:04:25 +00:00
void handleInputStateChange(uint8_t pin, bool state);
2023-12-29 16:43:12 +00:00
void handlePwmStateChange(uint8_t pin, bool state, uint16_t value);
2023-12-29 13:04:25 +00:00
void handlePageChange(uint8_t page);
void setOutputBar(uint8_t pin, uint16_t value);
void setOutputStateColor(uint8_t pin, bool state);
void setInputMarker(uint8_t pin, bool state);
void setPWMAdjustmentSlider(uint16_t value);
void setPWMAdjustmentPin(uint8_t pin);
void setPWMAdjustmentButton(bool state);
void saveNetworkConfig();
void saveMQTTConfig();
2023-12-29 16:43:12 +00:00
void updateStatusIcons(bool networkStatus, bool mqttStatus);
2023-12-29 13:04:25 +00:00
void updateClock();
void refreshPage();
void refreshPage(uint8_t page);
void refreshDashboard();
void refreshInput();
void refreshOutput();
void refreshAC();
2023-12-30 15:50:19 +00:00
void refreshPWMAdjustment();
void refreshPWMAdjustmentSlider();
void refreshPWMAdjustmentState();
void refreshPWMAdjustmentId();
uint8_t pmwAdjustmentPin;
// Touch handlers
void handleTouch(uint8_t page, uint8_t component, uint8_t type);
void handlePWMAdjustmentTouch(uint8_t component, uint8_t type);
void handleACTouch(uint8_t component, uint8_t type);
2023-12-29 17:49:09 +00:00
MqttConfig *mqttConfig;
NetworkConfig *networkConfig;
2023-12-29 16:43:12 +00:00
// Pointers to various data
ESPMegaIoT *iot;
std::function<rtctime_t()> getRtcTime;
2023-12-29 13:04:25 +00:00
};