fix v long_press + // - == 5 kph

This commit is contained in:
betashepherd
2021-11-17 10:56:43 +08:00
parent c2e8d24f9e
commit 38616df48b
+8 -3
View File
@@ -69,7 +69,7 @@ def update_v_cruise(v_cruise_kph, buttonEvents, button_timers, enabled, metric):
long_press = False
button_type = None
v_cruise_delta = 1 if metric else 1.6
v_cruise_delta = 1 if metric else 1.609344
for b in buttonEvents:
if b.type.raw in button_timers and not b.pressed:
@@ -85,9 +85,14 @@ def update_v_cruise(v_cruise_kph, buttonEvents, button_timers, enabled, metric):
break
if button_type:
v_cruise_kph = math.floor(v_cruise_kph)
v_cruise_delta = v_cruise_delta * (5 if long_press else 1)
if long_press and v_cruise_kph % v_cruise_delta != 0: # partial interval
v_cruise_kph = CRUISE_NEAREST_FUNC[button_type](v_cruise_kph / v_cruise_delta) * v_cruise_delta
if long_press:
remainder = v_cruise_kph % v_cruise_delta
if remainder > 0:
v_cruise_kph += (v_cruise_delta - remainder) * CRUISE_INTERVAL_SIGN[button_type]
else:
v_cruise_kph += v_cruise_delta * CRUISE_INTERVAL_SIGN[button_type]
else:
v_cruise_kph += v_cruise_delta * CRUISE_INTERVAL_SIGN[button_type]
v_cruise_kph = clip(round(v_cruise_kph, 1), V_CRUISE_MIN, V_CRUISE_MAX)