In Learn LVGL Module 2.4, the Button Styles example, there’s an apparent disconnect between the event codes used by the TFT touchscreen_read callback function, and the LVGL button_event callback. The touchscreen_read callback detects the ‘touch change’ and sets data->state to either LV_INDEV_STATE_PRESSED (value 1) or LV_INDEV_STATE_RELEASED (value 0).
Later on, button_event_cb is called with an lv_event object and tests the code field for LV_EVENT_PRESSED (value 1), or LV_EVENT_RELEASED (value 8)?
What I expected was equivalence between the two PRESSED codes – which appears to be so – and the two RELEASED codes, which isn’t so. At least not unless your numbering system asserts 1 == 8.
Is there some reason for the RELEASED codes being different? Is there some invisible entity which sits between TFT and LVGL that maps event codes back and forth? This could be a problem for applications which want to detect and act on events other than PRESSED and RELEASED.
Thanks in advance for any info.
– Evan
Hi.
I’m sorry, but I don’t understand.
Can you tell me exactly which line are you referring to?
Regards,
Sara
In “Learn LVGL” Module 2.4 “Styling the Buttons” sample code:
touchscreen_read( … ) begins at line 53:
In this callback function, data->state is set to LV_INDEV_STATE_PRESSED at line 86, or is set to LV_INDEV_STATE_RELEASED at line 102. These two LV_INDEV_STATE values are defined in lv_indev.h – PRESSED as 1 and RELEASED as 0 – presumably to indicate whether the button was just pressed or just released.
My assumption is that the ‘data’ object thus updated will be used to create the ‘event’ object which is passed to the button_event_cb( ) callback function.
The button_event_cb( ) callback function begins at line 114.
button_event_cb( ) tests the event code for values LV_EVENT_PRESSED (at line 119) or LV_EVENT_RELEASED (at line 123). LV_EVENT_PRESSED and LV_EVENT_RELEASED are also defined in lv_event.h, with values 1 and 8, respectively.
It seems that the PRESSED value in both cases is the same (1), but the RELEASED value is different (either 0 or 8). So, for a RELEASE event, the touchscreen_read( ) function sets the data->state to 0, but the button_event_cb receives a value of 8 that indicates a RELEASE action.
What I’m not understanding is the connection between the two callback functions. My expectation was that the (comparatively low level) touchscreen_read( ) function would set values in the data object for use by the (comparatively high level) button_event_cb( ) function, but this does not appear to be the case, at least not in a straightforward manner.
Apologies for spoiling your Monday with such a confusing mess. The example code works just fine so If this level of detail is beyond the scope of an ‘Introduction” to LVGL, please so indicate and I’ll withdraw the question.
– Evan
Hi.
I think those are two completely different things.
One thing is the callback function for the touchscreen. It needs to detect whether the touchscreen was touched or not and in which coordinates.
Another completly different thing is the event associated with a button, which is independent of the state of the input device.
At least, this is my understanding of the situation.
Regards,
Sara
If I get any deeper into LVGL/TFT, I’ll try to work out the connection … if any.
Meanwhile, thanks for your patience and you time.
– Evan