#pragma once #include #include #define DISPLAY_FETCH_TIMEOUT 100 // ms #define DISPLAY_FETCH_RETRY_COUNT 5 class ESPMegaDisplay { public: ESPMegaDisplay(HardwareSerial *displayAdapter); void begin(); void loop(); void reset(); void setBrightness(int value); void setVolume(int value); void jumpToPage(int page); void setString(const char* component, const char* value); void setNumber(const char* component, int value); const char* getString(const char* component); bool getStringToBuffer(const char* component, char* buffer, uint8_t buffer_size); uint32_t getNumber(const char* component); uint16_t registerTouchCallback(std::function callback); void deregisterTouchCallback(uint16_t handle); uint16_t registerPageChangeCallback(std::function callback); void deregisterPageChangeCallback(uint16_t handle); protected: uint8_t currentPage; uint8_t rx_buffer_index; char rx_buffer[256]; char tx_buffer[256]; bool recieveSerialCommand(); bool recieveSerialCommand(bool process); void processSerialCommand(); void processTouchPayload(); void processPageReportPayload(); void sendStopBytes(); void sendCommand(char* command); bool payloadIsValid(); bool waitForValidPayload(uint32_t timeout); HardwareSerial *displayAdapter; std::map> touch_callbacks; std::map> page_change_callbacks; };