mirror of
https://github.com/lvgl/lvgl.git
synced 2025-02-04 07:13:00 +08:00
feat(indev): add 'lv_indev_read' to allow read events from specified indev (#4494)
Signed-off-by: XiaoweiYan <yanxiaowei@xiaomi.com> Co-authored-by: XiaoweiYan <yanxiaowei@xiaomi.com>
This commit is contained in:
parent
538bae5de8
commit
3c47aadacf
@ -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)
|
- ``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
|
- ``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`
|
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
|
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
|
``data->continue_reading`` flag will tell LVGL there is more data to
|
||||||
read and it should call ``read_cb`` again.
|
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
|
Further reading
|
||||||
***************
|
***************
|
||||||
|
|
||||||
|
@ -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_click_focus(lv_indev_t * indev);
|
||||||
static void indev_gesture(lv_indev_t * indev);
|
static void indev_gesture(lv_indev_t * indev);
|
||||||
static bool indev_reset_check(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
|
* STATIC VARIABLES
|
||||||
@ -121,7 +122,7 @@ void lv_indev_delete(lv_indev_t * indev)
|
|||||||
{
|
{
|
||||||
LV_ASSERT_NULL(indev);
|
LV_ASSERT_NULL(indev);
|
||||||
/*Clean up the read timer first*/
|
/*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*/
|
/*Remove the input device from the list*/
|
||||||
_lv_ll_remove(indev_ll_head, indev);
|
_lv_ll_remove(indev_ll_head, indev);
|
||||||
/*Free the memory of the input device*/
|
/*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);
|
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_PROFILER_BEGIN;
|
||||||
lv_memzero(data, sizeof(lv_indev_data_t));
|
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)
|
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");
|
INDEV_TRACE("begin");
|
||||||
|
|
||||||
lv_indev_data_t data;
|
indev_act = indev_p;
|
||||||
|
|
||||||
lv_indev_t * indev_p = indev_act = timer->user_data;
|
|
||||||
|
|
||||||
/*Read and process all indevs*/
|
/*Read and process all indevs*/
|
||||||
if(indev_p->disp == NULL) return; /*Not assigned to any displays*/
|
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;
|
LV_PROFILER_BEGIN;
|
||||||
|
|
||||||
bool continue_reading;
|
bool continue_reading;
|
||||||
|
lv_indev_data_t data;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
/*Read the data*/
|
/*Read the data*/
|
||||||
_lv_indev_read(indev_p, &data);
|
indev_read_core(indev_p, &data);
|
||||||
continue_reading = data.continue_reading;
|
continue_reading = data.continue_reading;
|
||||||
|
|
||||||
/*The active object might be deleted even in the read function*/
|
/*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)
|
static void indev_pointer_proc(lv_indev_t * i, lv_indev_data_t * data)
|
||||||
{
|
{
|
||||||
lv_disp_t * disp = i->disp;
|
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.x = data->point.x;
|
||||||
i->pointer.last_raw_point.y = data->point.y;
|
i->pointer.last_raw_point.y = data->point.y;
|
||||||
|
|
||||||
|
@ -82,9 +82,8 @@ lv_indev_t * lv_indev_get_next(lv_indev_t * indev);
|
|||||||
/**
|
/**
|
||||||
* Read data from an input device.
|
* Read data from an input device.
|
||||||
* @param indev pointer to 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
|
* Called periodically to read the input devices
|
||||||
|
Loading…
x
Reference in New Issue
Block a user