From 4c0cd82d9ceccf733a2492ce7e15fc75446ccbc8 Mon Sep 17 00:00:00 2001 From: Themba Dube Date: Sun, 16 Dec 2018 20:16:48 -0500 Subject: [PATCH] Initial lv_indev_set_feedback support --- lv_core/lv_indev.c | 20 ++++++++++++++++++++ lv_core/lv_indev.h | 14 ++++++++++++++ lv_core/lv_obj.c | 8 ++++++++ lv_core/lv_obj.h | 2 ++ lv_hal/lv_hal_indev.h | 5 +++++ 5 files changed, 49 insertions(+) diff --git a/lv_core/lv_indev.c b/lv_core/lv_indev.c index 1955dea44..336d046fa 100644 --- a/lv_core/lv_indev.c +++ b/lv_core/lv_indev.c @@ -166,6 +166,16 @@ void lv_indev_set_button_points(lv_indev_t * indev, lv_point_t * points) if(indev->driver.type == LV_INDEV_TYPE_BUTTON) indev->btn_points = points; } +/** + * Set feedback callback for indev. + * @param indev pointer to an input device + * @param feedback feedback callback + */ +void lv_indev_set_feedback(lv_indev_t *indev, lv_indev_feedback_t feedback) +{ + indev->feedback = feedback; +} + /** * Get the last point of an input device (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON) * @param indev pointer to an input device @@ -249,6 +259,16 @@ uint32_t lv_indev_get_inactive_time(const lv_indev_t * indev) return t; } +/** + * Get feedback callback for indev. + * @param indev pointer to an input device + * @return feedback callback + */ +lv_indev_feedback_t lv_indev_get_feedback(const lv_indev_t *indev) +{ + return indev->feedback; +} + /** * Do nothing until the next release * @param indev pointer to an input device diff --git a/lv_core/lv_indev.h b/lv_core/lv_indev.h index 1e7fd6bb1..68cab9a92 100644 --- a/lv_core/lv_indev.h +++ b/lv_core/lv_indev.h @@ -91,6 +91,13 @@ void lv_indev_set_group(lv_indev_t *indev, lv_group_t *group); */ void lv_indev_set_button_points(lv_indev_t *indev, lv_point_t *points); +/** + * Set feedback callback for indev. + * @param indev pointer to an input device + * @param feedback feedback callback + */ +void lv_indev_set_feedback(lv_indev_t *indev, lv_indev_feedback_t feedback); + /** * Get the last point of an input device (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON) * @param indev pointer to an input device @@ -125,6 +132,13 @@ void lv_indev_get_vect(const lv_indev_t * indev, lv_point_t * point); */ uint32_t lv_indev_get_inactive_time(const lv_indev_t * indev); +/** + * Get feedback callback for indev. + * @param indev pointer to an input device + * @return feedback callback + */ +lv_indev_feedback_t lv_indev_get_feedback(const lv_indev_t *indev); + /** * Do nothing until the next release * @param indev pointer to an input device diff --git a/lv_core/lv_obj.c b/lv_core/lv_obj.c index 3e576d602..12bb9027e 100644 --- a/lv_core/lv_obj.c +++ b/lv_core/lv_obj.c @@ -1810,6 +1810,14 @@ static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param) lv_res_t res = LV_RES_OK; lv_style_t * style = lv_obj_get_style(obj); + + lv_indev_t *indev_act = lv_indev_get_act(); + + if(sign > LV_INDEV_SIGNAL_START && sign < LV_INDEV_SIGNAL_END) { + if(indev_act != NULL && indev_act->feedback != NULL) + indev_act->feedback(indev_act, sign); + } + if(sign == LV_SIGNAL_CHILD_CHG) { /*Return 'invalid' if the child change signal is not enabled*/ if(lv_obj_is_protected(obj, LV_PROTECT_CHILD_CHG) != false) res = LV_RES_INV; diff --git a/lv_core/lv_obj.h b/lv_core/lv_obj.h index 6ac7170fa..619dfe37c 100644 --- a/lv_core/lv_obj.h +++ b/lv_core/lv_obj.h @@ -92,6 +92,7 @@ enum LV_SIGNAL_REFR_EXT_SIZE, LV_SIGNAL_GET_TYPE, + LV_INDEV_SIGNAL_START, /*Input device related*/ LV_SIGNAL_PRESSED, LV_SIGNAL_PRESSING, @@ -101,6 +102,7 @@ enum LV_SIGNAL_LONG_PRESS_REP, LV_SIGNAL_DRAG_BEGIN, LV_SIGNAL_DRAG_END, + LV_INDEV_SIGNAL_END, /*Group related*/ LV_SIGNAL_FOCUS, diff --git a/lv_hal/lv_hal_indev.h b/lv_hal/lv_hal_indev.h index c16c55e15..c244da46c 100644 --- a/lv_hal/lv_hal_indev.h +++ b/lv_hal/lv_hal_indev.h @@ -19,6 +19,7 @@ extern "C" { #include #include "lv_hal.h" #include "../lv_misc/lv_area.h" +#include "../lv_core/lv_obj.h" /********************* * DEFINES @@ -98,6 +99,9 @@ typedef struct _lv_indev_proc_t { uint8_t disabled :1; } lv_indev_proc_t; +struct _lv_indev_t; + +typedef void (*lv_indev_feedback_t)(struct _lv_indev_t *, lv_signal_t); struct _lv_obj_t; struct _lv_group_t; @@ -106,6 +110,7 @@ struct _lv_group_t; typedef struct _lv_indev_t { lv_indev_drv_t driver; lv_indev_proc_t proc; + lv_indev_feedback_t feedback; uint32_t last_activity_time; union { struct _lv_obj_t *cursor; /*Cursor for LV_INPUT_TYPE_POINTER*/