mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-04 19:43:49 +08:00
Refresh saved UI display flags once per second
This commit is contained in:
@@ -410,6 +410,8 @@ class RuntimeSnapshotAdapter:
|
||||
now_ns - self._appearance_read_ns >= 1_000_000_000):
|
||||
self._customization_value = read_customization(self.ui_state.params)
|
||||
self._appearance_value = onroad_appearance(self.ui_state.params)
|
||||
self._navigation_enabled = _flag(self.ui_state.params, "NavigationEnabled")
|
||||
self._show_curve_status = _flag(self.ui_state.params, "ShowCSCStatus")
|
||||
if self.appearance_override is not None:
|
||||
self._appearance_value = self.appearance_override(self._appearance_value)
|
||||
self._appearance_read_ns = now_ns
|
||||
@@ -462,7 +464,7 @@ class RuntimeSnapshotAdapter:
|
||||
from openpilot.starpilot.navigation.wire import navigation_state
|
||||
navigation = navigation_state(_message_at_age(sm, "starpilotNavigation", now_ns, after, 3_000_000_000)) if started else None
|
||||
displayed_navigation = navigation_display(navigation, now_ns=now_ns, drive_id=drive_id)
|
||||
if displayed_navigation is None and started and _flag(params, "NavigationEnabled"):
|
||||
if displayed_navigation is None and started and self._navigation_enabled:
|
||||
displayed_navigation = official_navigation_display(
|
||||
_message_at_age(sm, "navInstruction", now_ns, after, 3_000_000_000),
|
||||
_message_at_age(sm, "navRoute", now_ns, after, 30_000_000_000),
|
||||
@@ -709,7 +711,7 @@ class RuntimeSnapshotAdapter:
|
||||
stock_cruise_active=stock_cruise,
|
||||
slc_system_long_available=system_long,
|
||||
slc_wheel_confirmation_available=wheel_confirmation,
|
||||
curve=curve, show_curve_status=_flag(params, "ShowCSCStatus"),
|
||||
curve=curve, show_curve_status=self._show_curve_status,
|
||||
conditional_configured=self._conditional_choice, conditional_effective=conditional,
|
||||
conditional_perception=perception,
|
||||
conditional_lead=conditional_lead_from_message(display_radar) if display_car_valid else None,
|
||||
|
||||
@@ -101,6 +101,35 @@ def ui_fake():
|
||||
|
||||
|
||||
class TestRuntimeSnapshot(unittest.TestCase):
|
||||
|
||||
def test_onroad_saved_display_flags_share_the_settings_refresh(self):
|
||||
ui = ui_fake()
|
||||
ui.params.values.update(NavigationEnabled="1", ShowCSCStatus="1")
|
||||
original = ui.params.get_bool
|
||||
reads = []
|
||||
def get_bool(key):
|
||||
if key in ("NavigationEnabled", "ShowCSCStatus"):
|
||||
reads.append(key)
|
||||
return original(key)
|
||||
ui.params.get_bool = get_bool
|
||||
adapter = RuntimeSnapshotAdapter(ui)
|
||||
self.assertTrue(adapter.build(ShellMode.ONROAD, now_ns=NOW).onroad.show_curve_status)
|
||||
self.assertEqual(reads, ["NavigationEnabled", "ShowCSCStatus"])
|
||||
ui.params.values.update(NavigationEnabled="0", ShowCSCStatus="0")
|
||||
for tick in range(1, 60):
|
||||
ui.sm.frame += 1
|
||||
self.assertTrue(adapter.build(ShellMode.ONROAD, now_ns=NOW + tick * 16_000_000).onroad.show_curve_status)
|
||||
self.assertEqual(reads, ["NavigationEnabled", "ShowCSCStatus"])
|
||||
self.assertFalse(adapter.build(ShellMode.ONROAD, now_ns=NOW + 1_000_000_000).onroad.show_curve_status)
|
||||
self.assertEqual(reads, ["NavigationEnabled", "ShowCSCStatus"] * 2)
|
||||
ui.params.values.update(NavigationEnabled="1", ShowCSCStatus="1")
|
||||
self.assertTrue(adapter.build(ShellMode.ONROAD, now_ns=NOW - 1).onroad.show_curve_status)
|
||||
self.assertEqual(reads, ["NavigationEnabled", "ShowCSCStatus"] * 3)
|
||||
ui.params.values.update(NavigationEnabled="0", ShowCSCStatus="0")
|
||||
adapter.invalidate_appearance()
|
||||
self.assertFalse(adapter.build(ShellMode.ONROAD, now_ns=NOW).onroad.show_curve_status)
|
||||
self.assertEqual(reads, ["NavigationEnabled", "ShowCSCStatus"] * 4)
|
||||
|
||||
def test_switchback_display_uses_payload_reader_with_original_source_metadata(self):
|
||||
from opendbc.car.structs import CarParams
|
||||
ui = ui_fake()
|
||||
@@ -446,7 +475,7 @@ class TestRuntimeSnapshot(unittest.TestCase):
|
||||
reads.clear()
|
||||
ui.params.values['UpdaterState'] = 'downloading'
|
||||
same_second = adapter.build(ShellMode.ONROAD, now_ns=NOW + 10_000_000)
|
||||
self.assertEqual(len(reads), 3)
|
||||
self.assertEqual(reads, ['LongitudinalPersonality'])
|
||||
self.assertEqual(same_second.software, first.software)
|
||||
refreshed = adapter.build(ShellMode.ONROAD, now_ns=NOW + 1_000_000_000)
|
||||
self.assertNotEqual(refreshed.software, first.software)
|
||||
|
||||
Reference in New Issue
Block a user