mici: retouch lead car and distance indicator (#39456)

This commit is contained in:
Nick
2026-11-28 16:43:36 -06:00
committed by firestar5683
parent 450c522d0d
commit a7c451a837
6 changed files with 32 additions and 7 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 312 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 338 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 371 B

@@ -16,6 +16,7 @@ class PersonalityWidget:
self.fonts = fonts
self._lead_car = None
self._distance = []
self._compact_art: list[tuple[rl.Texture, int, int]] = []
self._alpha_filter = FirstOrderFilter(0.0, 0.05, 1 / gui_app.target_fps)
self._lead_car_filters = tuple(FirstOrderFilter(0.0, 0.1, 1 / gui_app.target_fps) for _ in range(2))
self._distance_filters = [(FirstOrderFilter(0.0, 0.1, 1 / gui_app.target_fps),
@@ -54,10 +55,26 @@ class PersonalityWidget:
self._draw_centered((texture, 56, 48), rect, 126, 0.9 if state.stock_cruise_active else 0.32)
return
driver_feedback = profile == Profile.LARGE or state.appearance.wheel_pedal_feedback
if not driver_feedback and not (state.traffic_selected or state.traffic_mode):
self._draw_compact_distance(rect, state, routine)
return
self.draw(rect, personality=state.personality, has_lead=state.lead_detected and (state.cruise_active or driver_feedback),
longitudinal_active=state.cruise_active, traffic_mode=state.traffic_selected or state.traffic_mode,
gas_override=state.gas_pressed_override and driver_feedback, visible=routine)
def _draw_compact_distance(self, rect: rl.Rectangle, state: OnroadState, visible: bool) -> None:
if not self._compact_art:
self._compact_art = [(gui_app.texture(f'icons_mici/longitudinal/{name}.png'), width, height)
for name, width, height in (('car', 40, 31), ('compact_distance_1', 33, 8),
('compact_distance_2', 40, 9), ('compact_distance_3', 48, 10))]
alpha = self._alpha_filter.update(visible)
active = state.cruise_active
lit_alpha = .9 if active else .63
for i, (art, y, intensity) in enumerate(zip(self._compact_art, (96, 123, 138, 155),
(self._lead_car_filters[0], *(f for f, _ in self._distance_filters)), strict=True)):
selected = state.lead_detected and active if i == 0 else i <= 1 + state.personality
self._draw_centered(art, rect, y, (.35 + (lit_alpha - .35) * intensity.update(selected)) * alpha)
def draw(self, rect: rl.Rectangle, *, personality: int, has_lead: bool, longitudinal_active: bool,
traffic_mode: bool = False, gas_override: bool = False, visible: bool = True, fit: bool = True) -> None:
self._prepare()
@@ -17,7 +17,8 @@ from openpilot.starpilot.ui.traffic_status import TrafficDisplay
def road(**changes):
return replace(OnroadState(True, False, 15, 80, SpeedLimitObservation(),
longitudinal_active=True, lead_detected=True), **changes)
longitudinal_active=True, lead_detected=True,
appearance=OnroadAppearance(wheel_pedal_feedback=True)), **changes)
@pytest.fixture
@@ -45,8 +46,7 @@ def test_same_selected_bars_and_lead_on_both_profiles(display, profile, personal
assert all(draws[2 + 2*i].args[3] == pytest.approx(.9 if i <= personality else .35, abs=.001) for i in range(3))
for has_lead, active, white, green in ((False, True, .35, 0), (True, False, 1, 0), (True, True, 0, 1)):
draws = settle(display, road(lead_detected=has_lead, longitudinal_active=active))
expected_white = .35 if profile == Profile.COMPACT and not active else white
assert draws[0].args[3] == pytest.approx(expected_white, abs=.001)
assert draws[0].args[3] == pytest.approx(white, abs=.001)
assert draws[1].args[3] == pytest.approx(green, abs=.001)
@@ -87,10 +87,11 @@ def test_selection_highlight_waits_for_alert_and_then_expires(display, monkeypat
def test_gas_override_blinks_only_selected_bars_and_clears_on_disengagement(display, monkeypatch):
monkeypatch.setattr(rl, 'get_time', lambda: 1.1)
state = road(personality=1, gas_pressed_override=True)
draws = settle(display, state)
state = road(personality=1, gas_pressed_override=True, appearance=OnroadAppearance())
settle(display, state)
draws = display._draw_centered.call_args_list[-4:]
assert draws[1].args[3] == pytest.approx(.9, abs=.001)
assert draws[2].args[3] == pytest.approx(.9, abs=.001)
assert draws[4].args[3] == pytest.approx(.9, abs=.001)
state = replace(state, appearance=OnroadAppearance(wheel_pedal_feedback=True))
draws = settle(display, state)
assert draws[2].args[3] == pytest.approx(.35, abs=.001)
@@ -229,3 +230,10 @@ def test_compact_configured_stock_cruise_keeps_the_dim_dial_before_engagement(di
display._draw_centered.assert_called_once()
args = display._draw_centered.call_args.args
assert args[0][0].path.endswith('/speed_dial.png') and args[3] == .32
def test_default_compact_distance_draws_the_four_stock_images(display):
settle(display, road(personality=1, appearance=OnroadAppearance()))
calls = display._draw_centered.call_args_list[-4:]
assert [call.args[0][0].path.split('/')[-1] for call in calls] == [
'car.png', 'compact_distance_1.png', 'compact_distance_2.png', 'compact_distance_3.png']
assert [call.args[3] for call in calls] == pytest.approx([.9, .9, .9, .35], abs=.001)
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "eb7213db70dcdcd2251b994d591c92df37423d8c09d8f8fd94e04d3c3bc1f80d", "schema_version": 1}
{"protected_inventory_sha256": "0fb8dc9cea76aaca11e94d1aa327ddcba10edf0de16826b11e8ddc5c31c1f1ce", "schema_version": 1}