• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Learn LVGL – Module 2.4 – Styling the Buttons

Q&A Forum › Category: ESP32 › Learn LVGL – Module 2.4 – Styling the Buttons
0 Vote Up Vote Down
Evan Suits asked 8 months ago

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
 

Question Tags: LVGL TFT event codes
5 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 8 months ago

Hi.
I’m sorry, but I don’t understand.
Can you tell me exactly which line are you referring to?
Regards,
Sara

0 Vote Up Vote Down
Evan Suits answered 8 months ago

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
 

0 Vote Up Vote Down
Sara Santos Staff answered 8 months ago

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

0 Vote Up Vote Down
Evan Suits answered 8 months ago

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
 

0 Vote Up Vote Down
Sara Santos Staff answered 8 months ago

Thank you.
I’ll mark this issue as resolved for now.
If you need further help, you just need to open a new question in our forum.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.