diff --git a/main/bobbybuttons.h b/main/bobbybuttons.h index 7424b98..a6e8c56 100644 --- a/main/bobbybuttons.h +++ b/main/bobbybuttons.h @@ -21,7 +21,8 @@ enum BobbyButton Extra3, Extra4, Confirm = espgui::Button::Right, - Back = espgui::Button::Left + Back = espgui::Button::Left, + ButtonMax = Back }; [[nodiscard]] std::optional translateRawButton(uint8_t button); diff --git a/main/cloud.cpp b/main/cloud.cpp index 867a0ef..2c240c9 100644 --- a/main/cloud.cpp +++ b/main/cloud.cpp @@ -983,6 +983,64 @@ void cloudEventHandler(void *event_handler_arg, esp_event_base_t event_base, int { send_ota_status(); } + else if (type == "rawBtnPrssd") + { + uint8_t button; + JsonVariant btn_id = doc["btn"]; + if (btn_id.isNull()) + { + ESP_LOGE(TAG, "btnPressed: btn is null"); + return; + } + + if (auto parsed = cpputils::fromString(btn_id.as())) + { + button = *parsed; + } + else + { + ESP_LOGE(TAG, "btnPressed: btn is not a number"); + return; + } + + if (!espgui::currentDisplay) + { + ESP_LOGW(TAG, "espgui::currentDisplay is null"); + return; + } + + espgui::currentDisplay->rawButtonPressed(button); + espgui::currentDisplay->rawButtonReleased(button); + } + else if (type == "btnPressed") + { + espgui::Button button; + JsonVariant btn_id = doc["btn"]; + if (btn_id.isNull()) + { + ESP_LOGE(TAG, "btnPressed: btn is null"); + return; + } + + if (auto parsed = cpputils::fromString>(btn_id.as())) + { + button = espgui::Button(*parsed); + } + else + { + ESP_LOGE(TAG, "btnPressed: btn is not a number"); + return; + } + + if (!espgui::currentDisplay) + { + ESP_LOGW(TAG, "espgui::currentDisplay is null"); + return; + } + + espgui::currentDisplay->buttonPressed(button); + espgui::currentDisplay->buttonReleased(button); + } else { ESP_LOGE(TAG, "unknown type: %s", type.c_str());