From 810c2794f16e3f7424243bf4721aa99a7fb28000 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Thu, 11 Jan 2024 23:19:50 +0700 Subject: [PATCH] allow payload callback, allow boot status --- .vscode/launch.json | 4 +-- .../lib/ESPMegaPRO/ESPMegaDisplay.cpp | 30 +++++++++++++++++++ .../lib/ESPMegaPRO/ESPMegaDisplay.hpp | 3 ++ .../lib/ESPMegaPRO/InternalDisplay.cpp | 12 ++++++++ .../lib/ESPMegaPRO/InternalDisplay.hpp | 1 + 5 files changed, 48 insertions(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 7c46088..2c45abc 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,8 +8,8 @@ "args": [], "stopAtEntry": false, "externalConsole": true, - "cwd": "d:/Git/ESPMegaPRO-v3-SDK/ESPMegaPRO-OS-SDK/src", - "program": "d:/Git/ESPMegaPRO-v3-SDK/ESPMegaPRO-OS-SDK/src/build/Debug/outDebug", + "cwd": "d:/Git/ESPMegaPRO-v3-SDK/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO", + "program": "d:/Git/ESPMegaPRO-v3-SDK/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/build/Debug/outDebug", "MIMode": "gdb", "miDebuggerPath": "gdb", "setupCommands": [ diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaDisplay.cpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaDisplay.cpp index cec2c07..8ddeb0e 100644 --- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaDisplay.cpp +++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaDisplay.cpp @@ -58,6 +58,15 @@ void ESPMegaDisplay::processSerialCommand() { processPageReportPayload(); } + else { + // The payload does not match any of the expected payload types + // Pass the payload to the payload callbacks + // type, payload, length + for (auto const &callback : payload_callbacks) + { + callback.second(rx_buffer[0], reinterpret_cast(&rx_buffer[1]), rx_buffer_index - 4);; + } + } this->rx_buffer_index = 0; } @@ -495,3 +504,24 @@ void ESPMegaDisplay::unregisterPageChangeCallback(uint16_t handle) { page_change_callbacks.erase(handle); } + +/** + * @brief Registers a callback function for payloads. + * @param callback The callback function. + * @return The handle of the callback function. + */ +uint16_t ESPMegaDisplay::registerPayloadCallback(std::function callback) +{ + uint16_t handle = payload_callbacks.size(); + payload_callbacks[handle] = callback; + return handle; +} + +/** + * @brief Unregisters a callback function for payloads. + * @param handle The handle of the callback function. + */ +void ESPMegaDisplay::unregisterPayloadCallback(uint16_t handle) +{ + payload_callbacks.erase(handle); +} \ No newline at end of file diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaDisplay.hpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaDisplay.hpp index 5fd009b..df19d09 100644 --- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaDisplay.hpp +++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaDisplay.hpp @@ -30,6 +30,8 @@ class ESPMegaDisplay void unregisterTouchCallback(uint16_t handle); uint16_t registerPageChangeCallback(std::function callback); void unregisterPageChangeCallback(uint16_t handle); + uint16_t registerPayloadCallback(std::function callback); + void unregisterPayloadCallback(uint16_t handle); protected: uint8_t currentPage; @@ -48,4 +50,5 @@ class ESPMegaDisplay HardwareSerial *displayAdapter; std::map> touch_callbacks; std::map> page_change_callbacks; + std::map> payload_callbacks; }; \ No newline at end of file diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/InternalDisplay.cpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/InternalDisplay.cpp index bd8615e..e00c834 100644 --- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/InternalDisplay.cpp +++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/InternalDisplay.cpp @@ -871,4 +871,16 @@ void InternalDisplay::handleACStateChange(uint8_t mode, uint8_t fan_speed, uint8 this->sendStopBytes(); // Update the AC state this->refreshAC(); +} + +/** + * @brief Set the boot status text + * + * @param text The text to set + */ +void InternalDisplay::setBootStatus(const char *text) { + this->displayAdapter->print("boot_state.txt=\""); + this->displayAdapter->print(text); + this->displayAdapter->print("\""); + this->sendStopBytes(); } \ No newline at end of file diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/InternalDisplay.hpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/InternalDisplay.hpp index 21d7ff3..6532706 100644 --- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/InternalDisplay.hpp +++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/InternalDisplay.hpp @@ -121,6 +121,7 @@ class InternalDisplay : public ESPMegaDisplay { void refreshPWMAdjustmentId(); void refreshNetworkConfig(); void refreshMQTTConfig(); + void setBootStatus(const char* status); void sendIpToDisplay(IPAddress ip); uint8_t pmwAdjustmentPin; // Touch handlers