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

69 lines
2.8 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
2024-01-14 07:09:20 +00:00
#define DISPLAY_MUTEX_TAKE_TIMEOUT 1000 // ms
#define OTA_WAIT_TIMEOUT 1000 // ms
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:
ESPMegaDisplay(HardwareSerial *displayAdapter, uint32_t baudRate, uint32_t uploadBaudRate, uint8_t txPin, uint8_t rxPin);
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);
2024-01-15 09:44:36 +00:00
bool takeSerialMutex();
2024-01-14 07:09:20 +00:00
void giveSerialMutex();
2024-01-15 09:44:36 +00:00
SemaphoreHandle_t serialMutex;
2024-01-14 17:39:12 +00:00
bool beginUpdate(size_t size);
bool beginUpdate(size_t size, uint32_t baudRate);
2024-01-14 17:39:12 +00:00
bool writeUpdate(uint8_t* data, size_t size);
void endUpdate();
2024-01-16 15:08:13 +00:00
size_t getUpdateBytesWritten();
2023-12-29 13:04:25 +00:00
protected:
uint32_t baudRate;
uint32_t uploadBaudRate;
2024-01-16 15:08:13 +00:00
uint8_t txPin;
uint8_t rxPin;
2024-01-15 08:19:49 +00:00
size_t otaBytesWritten;
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
};