diff --git a/src/lv_widgets/lv_rotary.c b/src/lv_widgets/lv_rotary.c index 668a6a40e..7dc88d4cc 100644 --- a/src/lv_widgets/lv_rotary.c +++ b/src/lv_widgets/lv_rotary.c @@ -332,31 +332,31 @@ static lv_res_t lv_rotary_signal(lv_obj_t * rotary, lv_signal_t sign, void * par } else if(sign == LV_SIGNAL_PRESSING) { lv_indev_get_point(param, &p); + lv_coord_t drag_x_diff = p.x -ext->last_drag_x; + + if (abs(drag_x_diff) > abs(ext->sensitivity)) { + if (drag_x_diff > 0) drag_x_diff = ext->sensitivity; + else drag_x_diff = -ext->sensitivity; + } + ext->last_drag_x = p.x; - if (ext->last_drag_x == -1) { - ext->last_drag_x = p.x; - } else { - lv_coord_t drag_x_diff = p.x - ext->last_drag_x; - ext->last_drag_x = p.x; - - if (ext->knob_area.y1 < p.y && p.y < ext->knob_area.y2) { - if (drag_x_diff > 0 && p.x < ext->knob_area.x2) { - lv_rotary_set_value(rotary, lv_rotary_get_value(rotary) + drag_x_diff * ext->sensitivity, LV_ANIM_ON); - res = lv_event_send(rotary, LV_EVENT_VALUE_CHANGED, NULL); - if(res != LV_RES_OK) return res; - } - else if (drag_x_diff < 0 && p.x > ext->knob_area.x1) { - ext->last_drag_x = p.x; - lv_rotary_set_value(rotary, lv_rotary_get_value(rotary) + drag_x_diff * ext->sensitivity, LV_ANIM_ON); - res = lv_event_send(rotary, LV_EVENT_VALUE_CHANGED, NULL); - if(res != LV_RES_OK) return res; - } + if (ext->knob_area.y1 < p.y && p.y < ext->knob_area.y2) { + if (drag_x_diff > 0 && p.x < ext->knob_area.x2) { + lv_rotary_set_value(rotary, lv_rotary_get_value(rotary) + drag_x_diff * ext->sensitivity, LV_ANIM_ON); + res = lv_event_send(rotary, LV_EVENT_VALUE_CHANGED, NULL); + if(res != LV_RES_OK) return res; + } + else if (drag_x_diff < 0 && p.x > ext->knob_area.x1) { + ext->last_drag_x = p.x; + lv_rotary_set_value(rotary, lv_rotary_get_value(rotary) + drag_x_diff * ext->sensitivity, LV_ANIM_ON); + res = lv_event_send(rotary, LV_EVENT_VALUE_CHANGED, NULL); + if(res != LV_RES_OK) return res; } } + } else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) { ext->dragging = false; - ext->last_drag_x = -1; /** Reset drag diff calc */ #if LV_USE_GROUP /*Leave edit mode if released. (No need to wait for LONG_PRESS) */