From 9ba025e1361f3252dc2be8c1aafcf69746544fd1 Mon Sep 17 00:00:00 2001 From: xuxin Date: Wed, 4 Dec 2024 11:01:43 +0800 Subject: [PATCH 1/4] Fix: knob loses diff event --- components/esp_lvgl_port/idf_component.yml | 2 +- components/esp_lvgl_port/src/lvgl8/esp_lvgl_port_knob.c | 4 +++- components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_knob.c | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/components/esp_lvgl_port/idf_component.yml b/components/esp_lvgl_port/idf_component.yml index fb7e7619..aed2f92d 100644 --- a/components/esp_lvgl_port/idf_component.yml +++ b/components/esp_lvgl_port/idf_component.yml @@ -1,4 +1,4 @@ -version: "2.4.3" +version: "2.4.4" description: ESP LVGL port url: https://github.com/espressif/esp-bsp/tree/master/components/esp_lvgl_port dependencies: diff --git a/components/esp_lvgl_port/src/lvgl8/esp_lvgl_port_knob.c b/components/esp_lvgl_port/src/lvgl8/esp_lvgl_port_knob.c index 328e405a..d230c12f 100644 --- a/components/esp_lvgl_port/src/lvgl8/esp_lvgl_port_knob.c +++ b/components/esp_lvgl_port/src/lvgl8/esp_lvgl_port_knob.c @@ -128,8 +128,10 @@ static void lvgl_port_encoder_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *d knob_event_t event = iot_knob_get_event(ctx->knob_handle); if (last_v ^ invd) { + data->enc_diff = (event == KNOB_LEFT) ? -1 : + (event == KNOB_RIGHT) ? 1 : + (int32_t)((uint32_t)invd - (uint32_t)last_v); last_v = invd; - data->enc_diff = (KNOB_LEFT == event) ? (-1) : ((KNOB_RIGHT == event) ? (1) : (0)); } else { data->enc_diff = 0; } diff --git a/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_knob.c b/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_knob.c index 81157182..e361365b 100644 --- a/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_knob.c +++ b/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_knob.c @@ -139,8 +139,10 @@ static void lvgl_port_encoder_read(lv_indev_t *indev_drv, lv_indev_data_t *data) knob_event_t event = iot_knob_get_event(ctx->knob_handle); if (last_v ^ invd) { + data->enc_diff = (event == KNOB_LEFT) ? -1 : + (event == KNOB_RIGHT) ? 1 : + (int32_t)((uint32_t)invd - (uint32_t)last_v); last_v = invd; - data->enc_diff = (KNOB_LEFT == event) ? (-1) : ((KNOB_RIGHT == event) ? (1) : (0)); } else { data->enc_diff = 0; } From 96eff84ac5b1ae4c4b090e2b615e265689154d2a Mon Sep 17 00:00:00 2001 From: xuxin Date: Tue, 7 Jan 2025 14:24:37 +0800 Subject: [PATCH 2/4] fix: knob lost event --- .../src/lvgl8/esp_lvgl_port_knob.c | 46 ++++++++++++++--- .../src/lvgl9/esp_lvgl_port_knob.c | 50 +++++++++++++++---- 2 files changed, 79 insertions(+), 17 deletions(-) diff --git a/components/esp_lvgl_port/src/lvgl8/esp_lvgl_port_knob.c b/components/esp_lvgl_port/src/lvgl8/esp_lvgl_port_knob.c index d230c12f..ab52e8c3 100644 --- a/components/esp_lvgl_port/src/lvgl8/esp_lvgl_port_knob.c +++ b/components/esp_lvgl_port/src/lvgl8/esp_lvgl_port_knob.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -19,7 +19,8 @@ typedef struct { knob_handle_t knob_handle; /* Encoder knob handlers */ button_handle_t btn_handle; /* Encoder button handlers */ lv_indev_drv_t indev_drv; /* LVGL input device driver */ - bool btn_enter; /* Encoder button enter state */ + bool btn_enter; /* Encoder button enter state */ + knob_event_t event; /* Encoder event */ } lvgl_port_encoder_ctx_t; /******************************************************************************* @@ -29,6 +30,8 @@ typedef struct { static void lvgl_port_encoder_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data); static void lvgl_port_encoder_btn_down_handler(void *arg, void *arg2); static void lvgl_port_encoder_btn_up_handler(void *arg, void *arg2); +static void lvgl_port_encoder_left_handler(void *arg, void *arg2); +static void lvgl_port_encoder_right_handler(void *arg, void *arg2); /******************************************************************************* * Public API functions @@ -54,6 +57,9 @@ lv_indev_t *lvgl_port_add_encoder(const lvgl_port_encoder_cfg_t *encoder_cfg) ESP_GOTO_ON_FALSE(encoder_ctx->knob_handle, ESP_ERR_NO_MEM, err, TAG, "Not enough memory for knob create!"); } + ESP_ERROR_CHECK(iot_knob_register_cb(encoder_ctx->knob_handle, KNOB_LEFT, lvgl_port_encoder_left_handler, encoder_ctx)); + ESP_ERROR_CHECK(iot_knob_register_cb(encoder_ctx->knob_handle, KNOB_RIGHT, lvgl_port_encoder_right_handler, encoder_ctx)); + /* Encoder Enter */ if (encoder_cfg->encoder_enter != NULL) { encoder_ctx->btn_handle = iot_button_create(encoder_cfg->encoder_enter); @@ -125,12 +131,16 @@ static void lvgl_port_encoder_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *d assert(ctx); int32_t invd = iot_knob_get_count_value(ctx->knob_handle); - knob_event_t event = iot_knob_get_event(ctx->knob_handle); + knob_event_t event = ctx->event; if (last_v ^ invd) { - data->enc_diff = (event == KNOB_LEFT) ? -1 : - (event == KNOB_RIGHT) ? 1 : - (int32_t)((uint32_t)invd - (uint32_t)last_v); + + int32_t diff = (int32_t)((uint32_t)invd - (uint32_t)last_v); + + diff += (event == KNOB_RIGHT && invd < last_v) ? CONFIG_KNOB_HIGH_LIMIT : + (event == KNOB_LEFT && invd > last_v) ? CONFIG_KNOB_LOW_LIMIT : 0; + + data->enc_diff = diff; last_v = invd; } else { data->enc_diff = 0; @@ -161,3 +171,27 @@ static void lvgl_port_encoder_btn_up_handler(void *arg, void *arg2) } } } + +static void lvgl_port_encoder_left_handler(void *arg, void *arg2) +{ + lvgl_port_encoder_ctx_t *ctx = (lvgl_port_encoder_ctx_t *) arg2; + knob_handle_t knob = (knob_handle_t)arg; + if (ctx && knob) { + /* LEFT */ + if (knob == ctx->knob_handle) { + ctx->event = KNOB_LEFT; + } + } +} + +static void lvgl_port_encoder_right_handler(void *arg, void *arg2) +{ + lvgl_port_encoder_ctx_t *ctx = (lvgl_port_encoder_ctx_t *) arg2; + knob_handle_t knob = (knob_handle_t)arg; + if (ctx && knob) { + /* RIGHT */ + if (knob == ctx->knob_handle) { + ctx->event = KNOB_RIGHT; + } + } +} diff --git a/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_knob.c b/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_knob.c index e361365b..33efe5c6 100644 --- a/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_knob.c +++ b/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_knob.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -20,6 +20,7 @@ typedef struct { button_handle_t btn_handle; /* Encoder button handlers */ lv_indev_t *indev; /* LVGL input device driver */ bool btn_enter; /* Encoder button enter state */ + knob_event_t event; /* Encoder event */ } lvgl_port_encoder_ctx_t; /******************************************************************************* @@ -29,7 +30,8 @@ typedef struct { static void lvgl_port_encoder_read(lv_indev_t *indev_drv, lv_indev_data_t *data); static void lvgl_port_encoder_btn_down_handler(void *arg, void *arg2); static void lvgl_port_encoder_btn_up_handler(void *arg, void *arg2); -static void lvgl_port_encoder_knob_handler(void *arg, void *arg2); +static void lvgl_port_encoder_left_handler(void *arg, void *arg2); +static void lvgl_port_encoder_right_handler(void *arg, void *arg2); /******************************************************************************* * Public API functions @@ -54,8 +56,8 @@ lv_indev_t *lvgl_port_add_encoder(const lvgl_port_encoder_cfg_t *encoder_cfg) encoder_ctx->knob_handle = iot_knob_create(encoder_cfg->encoder_a_b); ESP_GOTO_ON_FALSE(encoder_ctx->knob_handle, ESP_ERR_NO_MEM, err, TAG, "Not enough memory for knob create!"); - ESP_ERROR_CHECK(iot_knob_register_cb(encoder_ctx->knob_handle, KNOB_LEFT, lvgl_port_encoder_knob_handler, encoder_ctx)); - ESP_ERROR_CHECK(iot_knob_register_cb(encoder_ctx->knob_handle, KNOB_RIGHT, lvgl_port_encoder_knob_handler, encoder_ctx)); + ESP_ERROR_CHECK(iot_knob_register_cb(encoder_ctx->knob_handle, KNOB_LEFT, lvgl_port_encoder_left_handler, encoder_ctx)); + ESP_ERROR_CHECK(iot_knob_register_cb(encoder_ctx->knob_handle, KNOB_RIGHT, lvgl_port_encoder_right_handler, encoder_ctx)); } /* Encoder Enter */ @@ -131,17 +133,22 @@ esp_err_t lvgl_port_remove_encoder(lv_indev_t *encoder) static void lvgl_port_encoder_read(lv_indev_t *indev_drv, lv_indev_data_t *data) { static int32_t last_v = 0; + assert(indev_drv); lvgl_port_encoder_ctx_t *ctx = (lvgl_port_encoder_ctx_t *)lv_indev_get_user_data(indev_drv); assert(ctx); int32_t invd = iot_knob_get_count_value(ctx->knob_handle); - knob_event_t event = iot_knob_get_event(ctx->knob_handle); + knob_event_t event = ctx->event; if (last_v ^ invd) { - data->enc_diff = (event == KNOB_LEFT) ? -1 : - (event == KNOB_RIGHT) ? 1 : - (int32_t)((uint32_t)invd - (uint32_t)last_v); + + int32_t diff = (int32_t)((uint32_t)invd - (uint32_t)last_v); + + diff += (event == KNOB_RIGHT && invd < last_v) ? CONFIG_KNOB_HIGH_LIMIT : + (event == KNOB_LEFT && invd > last_v) ? CONFIG_KNOB_LOW_LIMIT : 0; + + data->enc_diff = diff; last_v = invd; } else { data->enc_diff = 0; @@ -179,9 +186,30 @@ static void lvgl_port_encoder_btn_up_handler(void *arg, void *arg2) lvgl_port_task_wake(LVGL_PORT_EVENT_TOUCH, ctx->indev); } -static void lvgl_port_encoder_knob_handler(void *arg, void *arg2) +static void lvgl_port_encoder_left_handler(void *arg, void *arg2) { lvgl_port_encoder_ctx_t *ctx = (lvgl_port_encoder_ctx_t *) arg2; - /* Wake LVGL task, if needed */ - lvgl_port_task_wake(LVGL_PORT_EVENT_TOUCH, ctx->indev); + knob_handle_t knob = (knob_handle_t)arg; + if (ctx && knob) { + /* LEFT */ + if (knob == ctx->knob_handle) { + ctx->event = KNOB_LEFT; + } + /* Wake LVGL task, if needed */ + lvgl_port_task_wake(LVGL_PORT_EVENT_TOUCH, ctx->indev); + } +} + +static void lvgl_port_encoder_right_handler(void *arg, void *arg2) +{ + lvgl_port_encoder_ctx_t *ctx = (lvgl_port_encoder_ctx_t *) arg2; + knob_handle_t knob = (knob_handle_t)arg; + if (ctx && knob) { + /* RIGHT */ + if (knob == ctx->knob_handle) { + ctx->event = KNOB_RIGHT; + } + /* Wake LVGL task, if needed */ + lvgl_port_task_wake(LVGL_PORT_EVENT_TOUCH, ctx->indev); + } } From 6a508325914ee459182ac044fe9943dd95162e63 Mon Sep 17 00:00:00 2001 From: xuxin Date: Thu, 9 Jan 2025 11:33:46 +0800 Subject: [PATCH 3/4] fix: calculate diff in callback --- .../src/lvgl8/esp_lvgl_port_knob.c | 45 ++++++++++-------- .../src/lvgl9/esp_lvgl_port_knob.c | 46 +++++++++++-------- 2 files changed, 51 insertions(+), 40 deletions(-) diff --git a/components/esp_lvgl_port/src/lvgl8/esp_lvgl_port_knob.c b/components/esp_lvgl_port/src/lvgl8/esp_lvgl_port_knob.c index ab52e8c3..3ecbaf34 100644 --- a/components/esp_lvgl_port/src/lvgl8/esp_lvgl_port_knob.c +++ b/components/esp_lvgl_port/src/lvgl8/esp_lvgl_port_knob.c @@ -20,7 +20,7 @@ typedef struct { button_handle_t btn_handle; /* Encoder button handlers */ lv_indev_drv_t indev_drv; /* LVGL input device driver */ bool btn_enter; /* Encoder button enter state */ - knob_event_t event; /* Encoder event */ + int32_t diff; /* Encoder diff */ } lvgl_port_encoder_ctx_t; /******************************************************************************* @@ -32,6 +32,7 @@ static void lvgl_port_encoder_btn_down_handler(void *arg, void *arg2); static void lvgl_port_encoder_btn_up_handler(void *arg, void *arg2); static void lvgl_port_encoder_left_handler(void *arg, void *arg2); static void lvgl_port_encoder_right_handler(void *arg, void *arg2); +static int32_t lvgl_port_calculate_diff(knob_handle_t knob, knob_event_t event); /******************************************************************************* * Public API functions @@ -70,6 +71,7 @@ lv_indev_t *lvgl_port_add_encoder(const lvgl_port_encoder_cfg_t *encoder_cfg) ESP_ERROR_CHECK(iot_button_register_cb(encoder_ctx->btn_handle, BUTTON_PRESS_UP, lvgl_port_encoder_btn_up_handler, encoder_ctx)); encoder_ctx->btn_enter = false; + encoder_ctx->diff = 0; /* Register a encoder input device */ lv_indev_drv_init(&encoder_ctx->indev_drv); @@ -124,28 +126,13 @@ esp_err_t lvgl_port_remove_encoder(lv_indev_t *encoder) static void lvgl_port_encoder_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data) { - static int32_t last_v = 0; - assert(indev_drv); lvgl_port_encoder_ctx_t *ctx = (lvgl_port_encoder_ctx_t *)indev_drv->user_data; assert(ctx); - int32_t invd = iot_knob_get_count_value(ctx->knob_handle); - knob_event_t event = ctx->event; - - if (last_v ^ invd) { - - int32_t diff = (int32_t)((uint32_t)invd - (uint32_t)last_v); - - diff += (event == KNOB_RIGHT && invd < last_v) ? CONFIG_KNOB_HIGH_LIMIT : - (event == KNOB_LEFT && invd > last_v) ? CONFIG_KNOB_LOW_LIMIT : 0; - - data->enc_diff = diff; - last_v = invd; - } else { - data->enc_diff = 0; - } + data->enc_diff = ctx->diff; data->state = (true == ctx->btn_enter) ? LV_INDEV_STATE_PRESSED : LV_INDEV_STATE_RELEASED; + ctx->diff = 0; } static void lvgl_port_encoder_btn_down_handler(void *arg, void *arg2) @@ -179,7 +166,7 @@ static void lvgl_port_encoder_left_handler(void *arg, void *arg2) if (ctx && knob) { /* LEFT */ if (knob == ctx->knob_handle) { - ctx->event = KNOB_LEFT; + ctx->diff += lvgl_port_calculate_diff(knob, KNOB_LEFT); } } } @@ -191,7 +178,25 @@ static void lvgl_port_encoder_right_handler(void *arg, void *arg2) if (ctx && knob) { /* RIGHT */ if (knob == ctx->knob_handle) { - ctx->event = KNOB_RIGHT; + ctx->diff += lvgl_port_calculate_diff(knob, KNOB_RIGHT); } } } + +static int32_t lvgl_port_calculate_diff(knob_handle_t knob, knob_event_t event) +{ + static int32_t last_v = 0; + + int32_t diff = 0; + int32_t invd = iot_knob_get_count_value(knob); + + if (last_v ^ invd) { + + diff = (int32_t)((uint32_t)invd - (uint32_t)last_v); + diff += (event == KNOB_RIGHT && invd < last_v) ? CONFIG_KNOB_HIGH_LIMIT : + (event == KNOB_LEFT && invd > last_v) ? CONFIG_KNOB_LOW_LIMIT : 0; + last_v = invd; + } + + return diff; +} diff --git a/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_knob.c b/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_knob.c index 33efe5c6..691c3d94 100644 --- a/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_knob.c +++ b/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_knob.c @@ -20,7 +20,7 @@ typedef struct { button_handle_t btn_handle; /* Encoder button handlers */ lv_indev_t *indev; /* LVGL input device driver */ bool btn_enter; /* Encoder button enter state */ - knob_event_t event; /* Encoder event */ + int32_t diff; /* Encoder diff */ } lvgl_port_encoder_ctx_t; /******************************************************************************* @@ -32,6 +32,7 @@ static void lvgl_port_encoder_btn_down_handler(void *arg, void *arg2); static void lvgl_port_encoder_btn_up_handler(void *arg, void *arg2); static void lvgl_port_encoder_left_handler(void *arg, void *arg2); static void lvgl_port_encoder_right_handler(void *arg, void *arg2); +static int32_t lvgl_port_calculate_diff(knob_handle_t knob, knob_event_t event); /******************************************************************************* * Public API functions @@ -70,6 +71,7 @@ lv_indev_t *lvgl_port_add_encoder(const lvgl_port_encoder_cfg_t *encoder_cfg) ESP_ERROR_CHECK(iot_button_register_cb(encoder_ctx->btn_handle, BUTTON_PRESS_UP, lvgl_port_encoder_btn_up_handler, encoder_ctx)); encoder_ctx->btn_enter = false; + encoder_ctx->diff = 0; lvgl_port_lock(0); /* Register a encoder input device */ @@ -132,28 +134,13 @@ esp_err_t lvgl_port_remove_encoder(lv_indev_t *encoder) static void lvgl_port_encoder_read(lv_indev_t *indev_drv, lv_indev_data_t *data) { - static int32_t last_v = 0; - assert(indev_drv); lvgl_port_encoder_ctx_t *ctx = (lvgl_port_encoder_ctx_t *)lv_indev_get_user_data(indev_drv); assert(ctx); - int32_t invd = iot_knob_get_count_value(ctx->knob_handle); - knob_event_t event = ctx->event; - - if (last_v ^ invd) { - - int32_t diff = (int32_t)((uint32_t)invd - (uint32_t)last_v); - - diff += (event == KNOB_RIGHT && invd < last_v) ? CONFIG_KNOB_HIGH_LIMIT : - (event == KNOB_LEFT && invd > last_v) ? CONFIG_KNOB_LOW_LIMIT : 0; - - data->enc_diff = diff; - last_v = invd; - } else { - data->enc_diff = 0; - } + data->enc_diff = ctx->diff; data->state = (true == ctx->btn_enter) ? LV_INDEV_STATE_PRESSED : LV_INDEV_STATE_RELEASED; + ctx->diff = 0; } static void lvgl_port_encoder_btn_down_handler(void *arg, void *arg2) @@ -193,7 +180,7 @@ static void lvgl_port_encoder_left_handler(void *arg, void *arg2) if (ctx && knob) { /* LEFT */ if (knob == ctx->knob_handle) { - ctx->event = KNOB_LEFT; + ctx->diff += lvgl_port_calculate_diff(knob, KNOB_LEFT); } /* Wake LVGL task, if needed */ lvgl_port_task_wake(LVGL_PORT_EVENT_TOUCH, ctx->indev); @@ -207,9 +194,28 @@ static void lvgl_port_encoder_right_handler(void *arg, void *arg2) if (ctx && knob) { /* RIGHT */ if (knob == ctx->knob_handle) { - ctx->event = KNOB_RIGHT; + ctx->diff += lvgl_port_calculate_diff(knob, KNOB_RIGHT); } /* Wake LVGL task, if needed */ lvgl_port_task_wake(LVGL_PORT_EVENT_TOUCH, ctx->indev); } } + + +static int32_t lvgl_port_calculate_diff(knob_handle_t knob, knob_event_t event) +{ + static int32_t last_v = 0; + + int32_t diff = 0; + int32_t invd = iot_knob_get_count_value(knob); + + if (last_v ^ invd) { + + diff = (int32_t)((uint32_t)invd - (uint32_t)last_v); + diff += (event == KNOB_RIGHT && invd < last_v) ? CONFIG_KNOB_HIGH_LIMIT : + (event == KNOB_LEFT && invd > last_v) ? CONFIG_KNOB_LOW_LIMIT : 0; + last_v = invd; + } + + return diff; +} From f5ff636059ab70a928d799378637513033d0ccd2 Mon Sep 17 00:00:00 2001 From: xuxin Date: Thu, 9 Jan 2025 12:09:44 +0800 Subject: [PATCH 4/4] fix: If the direction is reversed, clear the count --- components/esp_lvgl_port/src/lvgl8/esp_lvgl_port_knob.c | 6 ++++-- components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_knob.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/components/esp_lvgl_port/src/lvgl8/esp_lvgl_port_knob.c b/components/esp_lvgl_port/src/lvgl8/esp_lvgl_port_knob.c index 3ecbaf34..dfbc9ecf 100644 --- a/components/esp_lvgl_port/src/lvgl8/esp_lvgl_port_knob.c +++ b/components/esp_lvgl_port/src/lvgl8/esp_lvgl_port_knob.c @@ -166,7 +166,8 @@ static void lvgl_port_encoder_left_handler(void *arg, void *arg2) if (ctx && knob) { /* LEFT */ if (knob == ctx->knob_handle) { - ctx->diff += lvgl_port_calculate_diff(knob, KNOB_LEFT); + int32_t diff = lvgl_port_calculate_diff(knob, KNOB_LEFT); + ctx->diff = (ctx->diff > 0) ? diff : ctx->diff + diff; } } } @@ -178,7 +179,8 @@ static void lvgl_port_encoder_right_handler(void *arg, void *arg2) if (ctx && knob) { /* RIGHT */ if (knob == ctx->knob_handle) { - ctx->diff += lvgl_port_calculate_diff(knob, KNOB_RIGHT); + int32_t diff = lvgl_port_calculate_diff(knob, KNOB_RIGHT); + ctx->diff = (ctx->diff < 0) ? diff : ctx->diff + diff; } } } diff --git a/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_knob.c b/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_knob.c index 691c3d94..cf461eed 100644 --- a/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_knob.c +++ b/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_knob.c @@ -180,7 +180,8 @@ static void lvgl_port_encoder_left_handler(void *arg, void *arg2) if (ctx && knob) { /* LEFT */ if (knob == ctx->knob_handle) { - ctx->diff += lvgl_port_calculate_diff(knob, KNOB_LEFT); + int32_t diff = lvgl_port_calculate_diff(knob, KNOB_LEFT); + ctx->diff = (ctx->diff > 0) ? diff : ctx->diff + diff; } /* Wake LVGL task, if needed */ lvgl_port_task_wake(LVGL_PORT_EVENT_TOUCH, ctx->indev); @@ -194,7 +195,8 @@ static void lvgl_port_encoder_right_handler(void *arg, void *arg2) if (ctx && knob) { /* RIGHT */ if (knob == ctx->knob_handle) { - ctx->diff += lvgl_port_calculate_diff(knob, KNOB_RIGHT); + int32_t diff = lvgl_port_calculate_diff(knob, KNOB_RIGHT); + ctx->diff = (ctx->diff < 0) ? diff : ctx->diff + diff; } /* Wake LVGL task, if needed */ lvgl_port_task_wake(LVGL_PORT_EVENT_TOUCH, ctx->indev);