diff --git a/lv_core/lv_indev.c b/lv_core/lv_indev.c index 0972e36c6..8a5facd5f 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..222cf3b17 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_SIGNAL_FEEDBACK_SECTION_START && sign < _LV_SIGNAL_FEEDBACK_SECTION_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..bdb8b38a0 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_SIGNAL_FEEDBACK_SECTION_START, /*Input device related*/ LV_SIGNAL_PRESSED, LV_SIGNAL_PRESSING, @@ -106,6 +107,7 @@ enum LV_SIGNAL_FOCUS, LV_SIGNAL_DEFOCUS, LV_SIGNAL_CONTROLL, + _LV_SIGNAL_FEEDBACK_SECTION_END, LV_SIGNAL_GET_EDITABLE, }; typedef uint8_t lv_signal_t; 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*/