Skip to content

Commit f5ff636

Browse files
committed
fix: If the direction is reversed, clear the count
1 parent 6a50832 commit f5ff636

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

components/esp_lvgl_port/src/lvgl8/esp_lvgl_port_knob.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ static void lvgl_port_encoder_left_handler(void *arg, void *arg2)
166166
if (ctx && knob) {
167167
/* LEFT */
168168
if (knob == ctx->knob_handle) {
169-
ctx->diff += lvgl_port_calculate_diff(knob, KNOB_LEFT);
169+
int32_t diff = lvgl_port_calculate_diff(knob, KNOB_LEFT);
170+
ctx->diff = (ctx->diff > 0) ? diff : ctx->diff + diff;
170171
}
171172
}
172173
}
@@ -178,7 +179,8 @@ static void lvgl_port_encoder_right_handler(void *arg, void *arg2)
178179
if (ctx && knob) {
179180
/* RIGHT */
180181
if (knob == ctx->knob_handle) {
181-
ctx->diff += lvgl_port_calculate_diff(knob, KNOB_RIGHT);
182+
int32_t diff = lvgl_port_calculate_diff(knob, KNOB_RIGHT);
183+
ctx->diff = (ctx->diff < 0) ? diff : ctx->diff + diff;
182184
}
183185
}
184186
}

components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_knob.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ static void lvgl_port_encoder_left_handler(void *arg, void *arg2)
180180
if (ctx && knob) {
181181
/* LEFT */
182182
if (knob == ctx->knob_handle) {
183-
ctx->diff += lvgl_port_calculate_diff(knob, KNOB_LEFT);
183+
int32_t diff = lvgl_port_calculate_diff(knob, KNOB_LEFT);
184+
ctx->diff = (ctx->diff > 0) ? diff : ctx->diff + diff;
184185
}
185186
/* Wake LVGL task, if needed */
186187
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)
194195
if (ctx && knob) {
195196
/* RIGHT */
196197
if (knob == ctx->knob_handle) {
197-
ctx->diff += lvgl_port_calculate_diff(knob, KNOB_RIGHT);
198+
int32_t diff = lvgl_port_calculate_diff(knob, KNOB_RIGHT);
199+
ctx->diff = (ctx->diff < 0) ? diff : ctx->diff + diff;
198200
}
199201
/* Wake LVGL task, if needed */
200202
lvgl_port_task_wake(LVGL_PORT_EVENT_TOUCH, ctx->indev);

0 commit comments

Comments
 (0)