allow payload callback, allow boot status

This commit is contained in:
Siwat Sirichai 2024-01-11 23:19:50 +07:00
parent ffe55fd978
commit 810c2794f1
5 changed files with 48 additions and 2 deletions

4
.vscode/launch.json vendored
View File

@ -8,8 +8,8 @@
"args": [], "args": [],
"stopAtEntry": false, "stopAtEntry": false,
"externalConsole": true, "externalConsole": true,
"cwd": "d:/Git/ESPMegaPRO-v3-SDK/ESPMegaPRO-OS-SDK/src", "cwd": "d:/Git/ESPMegaPRO-v3-SDK/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO",
"program": "d:/Git/ESPMegaPRO-v3-SDK/ESPMegaPRO-OS-SDK/src/build/Debug/outDebug", "program": "d:/Git/ESPMegaPRO-v3-SDK/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/build/Debug/outDebug",
"MIMode": "gdb", "MIMode": "gdb",
"miDebuggerPath": "gdb", "miDebuggerPath": "gdb",
"setupCommands": [ "setupCommands": [

View File

@ -58,6 +58,15 @@ void ESPMegaDisplay::processSerialCommand()
{ {
processPageReportPayload(); 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<unsigned char*>(&rx_buffer[1]), rx_buffer_index - 4);;
}
}
this->rx_buffer_index = 0; this->rx_buffer_index = 0;
} }
@ -495,3 +504,24 @@ void ESPMegaDisplay::unregisterPageChangeCallback(uint16_t handle)
{ {
page_change_callbacks.erase(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<void(uint8_t, uint8_t*, uint8_t)> 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);
}

View File

@ -30,6 +30,8 @@ class ESPMegaDisplay
void unregisterTouchCallback(uint16_t handle); void unregisterTouchCallback(uint16_t handle);
uint16_t registerPageChangeCallback(std::function<void(uint8_t)> callback); uint16_t registerPageChangeCallback(std::function<void(uint8_t)> callback);
void unregisterPageChangeCallback(uint16_t handle); void unregisterPageChangeCallback(uint16_t handle);
uint16_t registerPayloadCallback(std::function<void(uint8_t, uint8_t*, uint8_t)> callback);
void unregisterPayloadCallback(uint16_t handle);
protected: protected:
uint8_t currentPage; uint8_t currentPage;
@ -48,4 +50,5 @@ class ESPMegaDisplay
HardwareSerial *displayAdapter; HardwareSerial *displayAdapter;
std::map<uint16_t, std::function<void(uint8_t, uint8_t, uint8_t)>> touch_callbacks; 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)>> page_change_callbacks;
std::map<uint16_t, std::function<void(uint8_t, uint8_t*, uint8_t)>> payload_callbacks;
}; };

View File

@ -871,4 +871,16 @@ void InternalDisplay::handleACStateChange(uint8_t mode, uint8_t fan_speed, uint8
this->sendStopBytes(); this->sendStopBytes();
// Update the AC state // Update the AC state
this->refreshAC(); 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();
} }

View File

@ -121,6 +121,7 @@ class InternalDisplay : public ESPMegaDisplay {
void refreshPWMAdjustmentId(); void refreshPWMAdjustmentId();
void refreshNetworkConfig(); void refreshNetworkConfig();
void refreshMQTTConfig(); void refreshMQTTConfig();
void setBootStatus(const char* status);
void sendIpToDisplay(IPAddress ip); void sendIpToDisplay(IPAddress ip);
uint8_t pmwAdjustmentPin; uint8_t pmwAdjustmentPin;
// Touch handlers // Touch handlers