ESPMegaPRO-v3-SDK/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaDisplay.hpp

54 lines
2.2 KiB
C++
Raw Normal View History

2023-12-29 18:08:35 +00:00
#pragma once
2023-12-28 19:36:18 +00:00
#include <Arduino.h>
2023-12-30 15:50:19 +00:00
#include <map>
2023-12-29 04:55:59 +00:00
2023-12-29 13:04:25 +00:00
#define DISPLAY_FETCH_TIMEOUT 100 // ms
2023-12-30 15:50:19 +00:00
#define DISPLAY_FETCH_RETRY_COUNT 5
2023-12-29 04:55:59 +00:00
/**
* @brief The ESPMegaDisplay class is a class for controlling the ESPMegaDisplay.
*
* @note The ESPMegaDisplay is a UART controlled display.
* @note Connect the Display's TX pin to the ESPMega's RX pin and the Display's RX pin to the ESPMega's TX pin.
*/
2023-12-28 19:36:18 +00:00
class ESPMegaDisplay
{
public:
2023-12-29 13:04:25 +00:00
ESPMegaDisplay(HardwareSerial *displayAdapter);
2023-12-28 19:36:18 +00:00
void begin();
void loop();
void reset();
void setBrightness(int value);
2023-12-29 13:04:25 +00:00
void setVolume(int value);
2023-12-28 19:36:18 +00:00
void jumpToPage(int page);
2023-12-29 17:49:09 +00:00
void setString(const char* component, const char* value);
void setNumber(const char* component, int value);
2023-12-29 18:08:35 +00:00
const char* getString(const char* component);
2023-12-29 17:49:09 +00:00
bool getStringToBuffer(const char* component, char* buffer, uint8_t buffer_size);
uint32_t getNumber(const char* component);
2023-12-30 15:50:19 +00:00
uint16_t registerTouchCallback(std::function<void(uint8_t, uint8_t, uint8_t)> callback);
2023-12-31 06:41:48 +00:00
void unregisterTouchCallback(uint16_t handle);
2023-12-30 15:50:19 +00:00
uint16_t registerPageChangeCallback(std::function<void(uint8_t)> callback);
2023-12-31 06:41:48 +00:00
void unregisterPageChangeCallback(uint16_t handle);
uint16_t registerPayloadCallback(std::function<void(uint8_t, uint8_t*, uint8_t)> callback);
void unregisterPayloadCallback(uint16_t handle);
2023-12-30 15:50:19 +00:00
2023-12-29 13:04:25 +00:00
protected:
2023-12-28 19:36:18 +00:00
uint8_t currentPage;
uint8_t rx_buffer_index;
char rx_buffer[256];
char tx_buffer[256];
2023-12-29 04:55:59 +00:00
bool recieveSerialCommand();
bool recieveSerialCommand(bool process);
2023-12-28 19:36:18 +00:00
void processSerialCommand();
void processTouchPayload();
void processPageReportPayload();
void sendStopBytes();
void sendCommand(char* command);
2023-12-29 04:55:59 +00:00
bool payloadIsValid();
bool waitForValidPayload(uint32_t timeout);
2023-12-28 19:36:18 +00:00
HardwareSerial *displayAdapter;
2023-12-30 15:50:19 +00:00
std::map<uint16_t, std::function<void(uint8_t, uint8_t, uint8_t)>> touch_callbacks;
std::map<uint16_t, std::function<void(uint8_t)>> page_change_callbacks;
std::map<uint16_t, std::function<void(uint8_t, uint8_t*, uint8_t)>> payload_callbacks;
2023-12-28 19:36:18 +00:00
};