diff --git a/Kconfig b/Kconfig index 6d34e896e..772a57247 100644 --- a/Kconfig +++ b/Kconfig @@ -750,6 +750,11 @@ menu "LVGL configuration" bool "Enable multi-thread render" default n depends on LV_USE_VG_LITE_THORVG + + config LV_USE_GESTURE_RECOGNITION + bool "Enable the multi-touch gesture recognition feature" + depends on LV_USE_FLOAT + default n endmenu endmenu diff --git a/examples/others/gestures/lv_example_gestures.c b/examples/others/gestures/lv_example_gestures.c index 68af3e100..30a26fa6b 100644 --- a/examples/others/gestures/lv_example_gestures.c +++ b/examples/others/gestures/lv_example_gestures.c @@ -20,8 +20,7 @@ *********************/ #include "../../lv_examples.h" -#if LV_USE_GESTURE_RECOGNITION && \ - LV_USE_FLOAT +#if LV_USE_GESTURE_RECOGNITION && LV_BUILD_EXAMPLES /********************* * DEFINES @@ -67,7 +66,6 @@ static float label_y; */ void lv_example_gestures(void) { - lv_obj_t * rectangle; lv_obj_t * root_view; label_width = RECT_INIT_WIDTH; @@ -127,7 +125,7 @@ static void label_scale(lv_event_t * gesture_event) initial_w = -1; initial_h = -1; - LV_LOG_TRACE("label end scale: %g %d\n", scale, state); + LV_LOG_USER("label end scale: %g, state: %d", scale, state); return; } @@ -137,10 +135,10 @@ static void label_scale(lv_event_t * gesture_event) /* Pinch gesture has been recognized - this is the first event in a series of recognized events */ /* The scaling is applied relative to the original width/height of the rectangle */ - initial_w = label_width; - initial_h = label_height; + initial_w = (int)label_width; + initial_h = (int)label_height; - LV_LOG_TRACE("label start scale: %g\n", scale); + LV_LOG_USER("label start scale: %g", scale); } /* The gesture has started or is on-going */ @@ -156,8 +154,8 @@ static void label_scale(lv_event_t * gesture_event) label_x = center_pnt.x - label_width / 2; label_y = center_pnt.y - label_height / 2; - LV_LOG_TRACE("label scale: %g label x: %g label y: %g w: %g h: %g\n", - scale, label_x, label_y, label_width, label_height); + LV_LOG_USER("label scale: %g label x: %g label y: %g w: %g h: %g", + scale, label_x, label_y, label_width, label_height); /* Update position and size */ lv_style_set_width(&label_style, (int)label_width); @@ -185,7 +183,7 @@ static void label_move(lv_event_t * event) return; } - LV_LOG_TRACE("label move %p x: %d y: %d\n", event, pnt.x, pnt.y); + LV_LOG_USER("label move x: %d, y: %d", pnt.x, pnt.y); label_x = pnt.x - label_width / 2; label_y = pnt.y - label_height / 2; diff --git a/src/drivers/wayland/lv_wayland.c b/src/drivers/wayland/lv_wayland.c index f2469d049..43aac245f 100644 --- a/src/drivers/wayland/lv_wayland.c +++ b/src/drivers/wayland/lv_wayland.c @@ -2377,11 +2377,7 @@ static void _lv_wayland_touch_read(lv_indev_t * drv, lv_indev_data_t * data) { struct window * window = lv_display_get_user_data(lv_indev_get_display(drv)); - lv_indev_touch_data_t * touch; - bool is_active; lv_indev_gesture_recognizer_t * recognizer; - uint8_t touch_cnt; - uint8_t i; if(!window || window->closed) { return; @@ -2389,7 +2385,6 @@ static void _lv_wayland_touch_read(lv_indev_t * drv, lv_indev_data_t * data) /* Collect touches if there are any - send them to the gesture recognizer */ recognizer = &window->body->input.recognizer; - touch = &window->body->input.touches[0]; LV_LOG_TRACE("collected touch events: %d", window->body->input.touch_event_cnt); diff --git a/src/indev/lv_indev_gesture.c b/src/indev/lv_indev_gesture.c index 9b71581c1..3777fb938 100644 --- a/src/indev/lv_indev_gesture.c +++ b/src/indev/lv_indev_gesture.c @@ -26,9 +26,9 @@ * DEFINES ********************/ -#define LV_GESTURE_PINCH_DOWN_THRESHOLD 0.75 /* Default value - start sending events when reached */ -#define LV_GESTURE_PINCH_UP_THRESHOLD 1.5 /* Default value - start sending events when reached */ -#define LV_GESTURE_PINCH_MAX_INITIAL_SCALE 2.5 /* Default value */ +#define LV_GESTURE_PINCH_DOWN_THRESHOLD 0.75f /* Default value - start sending events when reached */ +#define LV_GESTURE_PINCH_UP_THRESHOLD 1.5f /* Default value - start sending events when reached */ +#define LV_GESTURE_PINCH_MAX_INITIAL_SCALE 2.5f /* Default value */ /******************** @@ -40,7 +40,6 @@ ********************/ static lv_indev_gesture_t * init_gesture_info(void); -static void reset_gesture_info(lv_indev_gesture_t * info); static lv_indev_gesture_motion_t * get_motion(uint8_t id, lv_indev_gesture_t * info); static int8_t get_motion_idx(uint8_t id, lv_indev_gesture_t * info); static void process_touch_event(lv_indev_touch_data_t * touch, lv_indev_gesture_t * info); @@ -64,7 +63,7 @@ static lv_indev_gesture_recognizer_t * lv_indev_get_gesture_recognizer(lv_event_ void lv_indev_set_pinch_up_threshold(lv_indev_gesture_recognizer_t * recognizer, float threshold) { /* A up threshold MUST always be bigger than 1 */ - LV_ASSERT(threshold > 1.0); + LV_ASSERT(threshold > 1.0f); if(recognizer->config == NULL) { @@ -79,7 +78,7 @@ void lv_indev_set_pinch_up_threshold(lv_indev_gesture_recognizer_t * recognizer, void lv_indev_set_pinch_down_threshold(lv_indev_gesture_recognizer_t * recognizer, float threshold) { /* A down threshold MUST always be smaller than 1 */ - LV_ASSERT(threshold < 1.0); + LV_ASSERT(threshold < 1.0f); if(recognizer->config == NULL) { @@ -195,6 +194,9 @@ void lv_indev_set_gesture_data(lv_indev_data_t * data, lv_indev_gesture_recogniz data->gesture_type = LV_INDEV_GESTURE_PINCH; data->gesture_data = (void *) recognizer; break; + + default: + break; } } @@ -265,13 +267,13 @@ void lv_indev_gesture_detect_pinch(lv_indev_gesture_recognizer_t * recognizer, l if(r->info->scale > r->config->pinch_up_threshold || r->info->scale < r->config->pinch_down_threshold) { - if(r->info->scale > 1.0) { - r->scale = r->info->scale - (r->config->pinch_up_threshold - 1.0); + if(r->info->scale > 1.0f) { + r->scale = r->info->scale - (r->config->pinch_up_threshold - 1.0f); } - else if(r->info->scale < 1.0) { + else if(r->info->scale < 1.0f) { - r->scale = r->info->scale + (1.0 - r->config->pinch_down_threshold); + r->scale = r->info->scale + (1.0f - r->config->pinch_down_threshold); } r->type = LV_INDEV_GESTURE_PINCH; @@ -607,8 +609,8 @@ static void gesture_calculate_factors(lv_indev_gesture_t * gesture, int touch_po g->rotation = g->p_rotation + atan2f(b, a); g->scale = g->p_scale * sqrtf((a * a) + (b * b)); - g->center.x = center_x; - g->center.y = center_y; + g->center.x = (int32_t)center_x; + g->center.y = (int32_t)center_y; } diff --git a/tests/src/lv_test_conf_full.h b/tests/src/lv_test_conf_full.h index 4b1ea9583..5cd3ad2eb 100644 --- a/tests/src/lv_test_conf_full.h +++ b/tests/src/lv_test_conf_full.h @@ -163,4 +163,6 @@ #define LV_USE_DRAW_SW_COMPLEX_GRADIENTS 1 +#define LV_USE_GESTURE_RECOGNITION 1 + #endif /* LV_TEST_CONF_FULL_H */