From 3c47aadacfc5c6c41cd1af5463f5358dd5e5c8fe Mon Sep 17 00:00:00 2001 From: bjsylvia Date: Tue, 29 Aug 2023 02:51:32 +0800 Subject: [PATCH] feat(indev): add 'lv_indev_read' to allow read events from specified indev (#4494) Signed-off-by: XiaoweiYan Co-authored-by: XiaoweiYan --- docs/porting/indev.rst | 24 +++++++++++++++++++++++- src/indev/lv_indev.c | 22 +++++++++++++++------- src/indev/lv_indev.h | 3 +-- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/docs/porting/indev.rst b/docs/porting/indev.rst index e66b1be2a..ecd0568f9 100644 --- a/docs/porting/indev.rst +++ b/docs/porting/indev.rst @@ -201,7 +201,7 @@ The default value of the following parameters can be changed in :cpp:type:`lv_in - ``long_press_repeat_time`` Interval of sending :cpp:enumerator:`LV_EVENT_LONG_PRESSED_REPEAT` (in milliseconds) - ``read_timer`` pointer to the ``lv_timer`` which reads the input device. Its parameters can be changed by ``lv_timer_...()`` functions. :c:macro:`LV_DEF_REFR_PERIOD` - in ``lv_hal_disp.h`` sets the default read period. + in ``lv_conf.h`` sets the default read period. Feedback -------- @@ -232,6 +232,28 @@ data instead of directly reading the input device. Setting the ``data->continue_reading`` flag will tell LVGL there is more data to read and it should call ``read_cb`` again. +Decoupling the input device read timer +-------------------------------------- + +Normally the input event is read every :c:macro:`LV_DEF_REFR_PERIOD` +milliseconds (set in ``lv_conf.h``). However, in some cases, you might +need more control over when to read the input device. For example, you +might need to read it by polling file descriptor (fd). + +You can do this in the following way: + +.. code:: c + + /*Delete the original input device read timer*/ + lv_timer_del(indev->read_timer); + indev->read_timer = NULL; + + + /*Call this anywhere you want to read the input device*/ + lv_indev_read(indev); + +.. note:: that :cpp:func:`lv_indev_read`, :cpp:func:`lv_timer_handler` and :cpp:func:`_lv_disp_refr_timer` can not run at the same time. + Further reading *************** diff --git a/src/indev/lv_indev.c b/src/indev/lv_indev.c index a7afda10a..3ded65f0f 100644 --- a/src/indev/lv_indev.c +++ b/src/indev/lv_indev.c @@ -70,6 +70,7 @@ static void indev_proc_reset_query_handler(lv_indev_t * indev); static void indev_click_focus(lv_indev_t * indev); static void indev_gesture(lv_indev_t * indev); static bool indev_reset_check(lv_indev_t * indev); +static void indev_read_core(lv_indev_t * indev, lv_indev_data_t * data); /********************** * STATIC VARIABLES @@ -121,7 +122,7 @@ void lv_indev_delete(lv_indev_t * indev) { LV_ASSERT_NULL(indev); /*Clean up the read timer first*/ - lv_timer_del(indev->read_timer); + if(indev->read_timer) lv_timer_del(indev->read_timer); /*Remove the input device from the list*/ _lv_ll_remove(indev_ll_head, indev); /*Free the memory of the input device*/ @@ -136,7 +137,7 @@ lv_indev_t * lv_indev_get_next(lv_indev_t * indev) return _lv_ll_get_next(indev_ll_head, indev); } -void _lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data) +void indev_read_core(lv_indev_t * indev, lv_indev_data_t * data) { LV_PROFILER_BEGIN; lv_memzero(data, sizeof(lv_indev_data_t)); @@ -168,11 +169,16 @@ void _lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data) void lv_indev_read_timer_cb(lv_timer_t * timer) { + lv_indev_read(timer->user_data); +} + +void lv_indev_read(lv_indev_t * indev_p) +{ + if(!indev_p) return; + INDEV_TRACE("begin"); - lv_indev_data_t data; - - lv_indev_t * indev_p = indev_act = timer->user_data; + indev_act = indev_p; /*Read and process all indevs*/ if(indev_p->disp == NULL) return; /*Not assigned to any displays*/ @@ -186,9 +192,11 @@ void lv_indev_read_timer_cb(lv_timer_t * timer) LV_PROFILER_BEGIN; bool continue_reading; + lv_indev_data_t data; + do { /*Read the data*/ - _lv_indev_read(indev_p, &data); + indev_read_core(indev_p, &data); continue_reading = data.continue_reading; /*The active object might be deleted even in the read function*/ @@ -523,7 +531,7 @@ lv_obj_t * lv_indev_search_obj(lv_obj_t * obj, lv_point_t * point) static void indev_pointer_proc(lv_indev_t * i, lv_indev_data_t * data) { lv_disp_t * disp = i->disp; - /*Save the raw points so they can be used again in _lv_indev_read*/ + /*Save the raw points so they can be used again in indev_read_core*/ i->pointer.last_raw_point.x = data->point.x; i->pointer.last_raw_point.y = data->point.y; diff --git a/src/indev/lv_indev.h b/src/indev/lv_indev.h index 42a707c2a..93af4031b 100644 --- a/src/indev/lv_indev.h +++ b/src/indev/lv_indev.h @@ -82,9 +82,8 @@ lv_indev_t * lv_indev_get_next(lv_indev_t * indev); /** * Read data from an input device. * @param indev pointer to an input device - * @param data input device will write its data here */ -void _lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data); +void lv_indev_read(lv_indev_t * indev); /** * Called periodically to read the input devices