Skip to content

Commit

Permalink
chore(indev_gesture): add missing config and fix warning (#7461)
Browse files Browse the repository at this point in the history
Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com>
Co-authored-by: pengyiqiang <pengyiqiang@xiaomi.com>
  • Loading branch information
FASTSHIFT and pengyiqiang authored Dec 16, 2024
1 parent 33fc317 commit 6decbb7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 27 deletions.
5 changes: 5 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 8 additions & 10 deletions examples/others/gestures/lv_example_gestures.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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 */
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions src/drivers/wayland/lv_wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -2377,19 +2377,14 @@ 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;
}

/* 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);

Expand Down
26 changes: 14 additions & 12 deletions src/indev/lv_indev_gesture.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */


/********************
Expand All @@ -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);
Expand All @@ -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) {

Expand All @@ -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) {

Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

}

Expand Down
2 changes: 2 additions & 0 deletions tests/src/lv_test_conf_full.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,6 @@

#define LV_USE_DRAW_SW_COMPLEX_GRADIENTS 1

#define LV_USE_GESTURE_RECOGNITION 1

#endif /* LV_TEST_CONF_FULL_H */

0 comments on commit 6decbb7

Please sign in to comment.