Hi, I am making an alarm clock and I want swipes to work only on the clock face that will take the UI to 4 different pages. Going back will be with a physical button or timeout. I am struggling how to check for a current page in a lambda. I am struggling reading the C++ documentation. LVGL api docs. I asked chatgpt to help me with that and first try it did not compile
- lambda: |-
if (lv_scr_act() == id(clock_page)) {
// Handle swipe gesture only on 'clock_page'
ESP_LOGD("swipe", "Swipe up detected on clock page!");
}
That threw this error:
error: comparison between distinct pointer types 'lv_obj_t*' {aka '_lv_obj_t*'} and 'esphome::lvgl::LvPageType*' lacks a cast
So I asked GPT again and it suggested this:
lambda:
- if (reinterpret_cast<lv_obj_t*>(lv_scr_act()) == reinterpret_cast<lv_obj_t*>(id(clock_page))) {
// Swipe actions will be here if 'clock_page' is the active screen
// Perform swipe handling code here
}
This compiles but it does not work. The if statement is resolved as False when it is supposed to be True.
In my LVGL I do have a clock_page defined like so:
lvgl:
pages:
- id: clock_page
scrollable: false
widgets:
- obj: # clock container
height: SIZE_CONTENT
...
If anyone could point me in the right direction, that would be greatly appreciated. The esphome LVGL documentation only mentions the yaml side of things and not the lambda in-line. Thank you in advance.