EasyManua.ls Logo

Espressif ESP32-S2 - Page 438

Espressif ESP32-S2
1695 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Chapter 2. API Reference
3. To configure dispatch method by calling touch_xxxx_subscribe_event(), there are two dis-
patch methods in Touch Element library, one is TOUCH_ELEM_DISP_EVENT, the other one is
TOUCH_ELEM_DISP_CALLBACK, it means that user could use two methods to obtain the touch element
message and handle it.
Events Processing If TOUCH_ELEM_DISP_EVENT dispatch method is configured, user need to startup an
event handler task to obtain the touch element message, all the elements raw message could be obtained by calling
touch_element_message_receive(), then extract the element-class-specific message by calling the cor-
responding message decoder (touch_xxxx_get_message()) to get the touch elements extracted message;
If TOUCH_ELEM_DISP_CALLBACK dispatch method is configured, user need to pass an event handler by calling
touch_xxxx_set_callback() before the touch elem starts working, all the elements extracted message
will be passed to the event handler function.
Warning: Since the event handler function runs on the library driver core(The context located in esp-timer
callback routine), user should not do something that attempts to block or delay, such as call vTaskDelay().
In code, the events handle procedure may look like as follows:
/* ---------------------------------------------- TOUCH_ELEM_DISP_EVENT -----------
,------------------------------------ */
void element_handler_task(void *arg)
{
touch_elem_message_t element_message;
while(1) {
if (touch_element_message_receive(&element_message, Timeout) == ESP_OK) {
const touch_xxxx_message_t *extracted_message = touch_xxxx_get_
,message(&element_message); //Decode message
... //Event handler logic
}
}
}
void app_main()
{
...
touch_xxxx_set_dispatch_method(element_handle, TOUCH_ELEM_DISP_EVENT); //Set
,TOUCH_ELEM_DISP_EVENT as the dispatch method
xTaskCreate(&element_handler_task, "element_handler_task", 2048, NULL, 5,
,NULL); //Create a handler task
...
}
/* --------------------------------------------------------------------------------
,------------------------------ */
...
/* ---------------------------------------------- TOUCH_ELEM_DISP_CALLBACK --------
,--------------------------------------- */
void element_handler(touch_xxxx_handle_t out_handle, touch_xxxx_message_t out_
,message, void *arg)
{
//Event handler logic
}
void app_main()
{
...
touch_xxxx_set_dispatch_method(element_handle, TOUCH_ELEM_DISP_CALLBACK); //
,Set TOUCH_ELEM_DISP_CALLBACK as the dispatch method
(continues on next page)
Espressif Systems 427
Submit Document Feedback
Release v4.4

Table of Contents