From ae23300c07e3218d96f627fdc41b2412a6d3738c Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Mon, 11 Dec 2017 12:53:58 +0100 Subject: [PATCH] indev: add inactivity timer --- lv_core/lv_indev.c | 24 ++++++++++++++++++++---- lv_core/lv_indev.h | 2 +- lv_hal/lv_hal_indev.h | 3 ++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lv_core/lv_indev.c b/lv_core/lv_indev.c index c475a52f8..811c0f2c4 100644 --- a/lv_core/lv_indev.c +++ b/lv_core/lv_indev.c @@ -175,12 +175,24 @@ void lv_indev_get_vect(lv_indev_t * indev, lv_point_t * point) /** * Get elapsed time since last press - * @param indev pointer to an input device + * @param indev pointer to an input device (NULL to get the overall smallest inactivity) * @return Elapsed ticks (milliseconds) since last press */ uint32_t lv_indev_get_inactive_time(lv_indev_t * indev) { - return indev->proc.pr_timestamp; + uint32_t t; + + if(indev) return t = lv_tick_elaps(indev->last_activity_time); + + lv_indev_t *i; + t = UINT16_MAX; + i = lv_indev_next(NULL); + while(i) { + t = LV_MATH_MIN(t, lv_tick_elaps(i->last_activity_time)); + i = lv_indev_next(i); + } + + return t; } /** @@ -229,7 +241,11 @@ static void indev_proc_task(void * param) if(i->proc.disabled == 0) { /*Read the data*/ lv_indev_read(i, &data); - i->proc.event = data.state; + i->proc.state = data.state; + + if(i->proc.state == LV_INDEV_STATE_PR) { + i->last_activity_time = lv_tick_get(); + } /*Move the cursor if set and moved*/ if(i->driver.type == LV_INDEV_TYPE_POINTER && @@ -296,7 +312,7 @@ static void indev_proc_task(void * param) */ static void indev_proc_point(lv_indev_proc_t * indev) { - if(indev->event == LV_INDEV_STATE_PR){ + if(indev->state == LV_INDEV_STATE_PR){ #if LV_INDEV_POINT_MARKER != 0 area_t area; area.x1 = indev->act_point.x - (LV_INDEV_POINT_MARKER >> 1); diff --git a/lv_core/lv_indev.h b/lv_core/lv_indev.h index 7bd497348..bf81bb6cd 100644 --- a/lv_core/lv_indev.h +++ b/lv_core/lv_indev.h @@ -96,7 +96,7 @@ void lv_indev_get_vect(lv_indev_t * indev, lv_point_t * point); /** * Get elapsed time since last press - * @param indev pointer to an input device + * @param indev pointer to an input device (NULL to get the overall smallest inactivity) * @return Elapsed ticks (milliseconds) since last press */ uint32_t lv_indev_get_inactive_time(lv_indev_t * indev); diff --git a/lv_hal/lv_hal_indev.h b/lv_hal/lv_hal_indev.h index c6e082914..fe1afc6c2 100644 --- a/lv_hal/lv_hal_indev.h +++ b/lv_hal/lv_hal_indev.h @@ -59,7 +59,7 @@ typedef struct { struct _lv_obj_t; typedef struct _lv_indev_state_t { - lv_indev_state_t event; + lv_indev_state_t state; union { struct { /*Pointer data*/ lv_point_t act_point; @@ -95,6 +95,7 @@ struct _lv_group_t; typedef struct _lv_indev_t { lv_indev_drv_t driver; lv_indev_proc_t proc; + uint32_t last_activity_time; union { struct _lv_obj_t *cursor; struct _lv_group_t *group; /*Keypad destination group*/