From 0ea99a01286fc0b48d57a402149dd7d1102d9bee Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Mon, 23 Nov 2026 11:21:05 -0600 Subject: [PATCH] Add Toggle Screen Off to Wheel Controls --- opendbc_repo/opendbc/car/gm/cancel_remap.py | 2 +- .../conditional_mode/button_actions.py | 2 +- .../starpilot/conditional_mode/manual.py | 2 +- .../controllers/tests/test_wheel_actions.py | 23 +++++++++++++--- .../starpilot/controllers/wheel_actions.py | 8 +++--- openpilot/starpilot/ui/runtime_app.py | 4 ++- .../ui/tests/test_screen_off_wheel.py | 26 ++++++++++++++++++- openpilot/starpilot/ui/wheel_feature.py | 8 +++--- prebuilt.json | 2 +- 9 files changed, 62 insertions(+), 15 deletions(-) diff --git a/opendbc_repo/opendbc/car/gm/cancel_remap.py b/opendbc_repo/opendbc/car/gm/cancel_remap.py index abe79f6fd7..b13ba2d1d0 100644 --- a/opendbc_repo/opendbc/car/gm/cancel_remap.py +++ b/opendbc_repo/opendbc/car/gm/cancel_remap.py @@ -50,7 +50,7 @@ def migrate_assignments(params, cp): ('LongDistanceButtonControl', 'LongCancelButtonControl', 5), ('VeryLongDistanceButtonControl', 'VeryLongCancelButtonControl', 6)) pending = [] - valid = tuple(str(value).encode() for value in range(15)) + valid = tuple(str(value).encode() for value in range(16)) for source, target, default in pairs: raw, readable = read_saved(params, target, 8) previous, source_readable = read_saved(params, source, 8) diff --git a/openpilot/starpilot/conditional_mode/button_actions.py b/openpilot/starpilot/conditional_mode/button_actions.py index 3ec5e7d2e6..3adef5afdb 100644 --- a/openpilot/starpilot/conditional_mode/button_actions.py +++ b/openpilot/starpilot/conditional_mode/button_actions.py @@ -22,7 +22,7 @@ SAFE_KEY = "SafeMode" MAX_SCALAR_BYTES = 8 CHOICES = {"Off": b"0", "Cycle conditional mode": str(EXPERIMENTAL_MODE_ACTION).encode(), "Toggle traffic mode": str(TRAFFIC_MODE_ACTION).encode(), "Switchback Mode": b"7"} -_CANONICAL_ACTIONS = frozenset(str(value).encode() for value in range(15)) +_CANONICAL_ACTIONS = frozenset(str(value).encode() for value in range(16)) @dataclass(frozen=True) diff --git a/openpilot/starpilot/conditional_mode/manual.py b/openpilot/starpilot/conditional_mode/manual.py index 772c0748ae..b5fe5f662b 100644 --- a/openpilot/starpilot/conditional_mode/manual.py +++ b/openpilot/starpilot/conditional_mode/manual.py @@ -108,7 +108,7 @@ def _action(params, key: str) -> int | None: if raw is None: return 0 # Registered INT defaults and Params::put values are canonical decimal. - if raw not in tuple(str(value).encode() for value in range(15)): + if raw not in tuple(str(value).encode() for value in range(16)): return None return int(raw) diff --git a/openpilot/starpilot/controllers/tests/test_wheel_actions.py b/openpilot/starpilot/controllers/tests/test_wheel_actions.py index adb146d39d..90cf98a25b 100644 --- a/openpilot/starpilot/controllers/tests/test_wheel_actions.py +++ b/openpilot/starpilot/controllers/tests/test_wheel_actions.py @@ -9,7 +9,7 @@ from openpilot.selfdrive.car.card import Car from openpilot.selfdrive.car.tests.publication_fixture import initialize_publication_sources from openpilot.selfdrive.car.cruise import CRUISE_LONG_PRESS, VCruiseHelper from openpilot.selfdrive.car.tests.test_hyundai_aol import candidate -from openpilot.starpilot.controllers.wheel_actions import ACTIONS, KEYS, WheelConsumer, WheelPublisher, capture +from openpilot.starpilot.controllers.wheel_actions import ACTIONS, KEYS, SCREEN_OFF_ACTION, WheelConsumer, WheelPublisher, capture TYPE = car.CarState.ButtonEvent.Type @@ -53,7 +53,8 @@ def context(tmp_path): def test_exact_catalog_and_missing_vs_saved_off(context): params, _ = context - assert sorted(ACTIONS.values()) == list(range(15)) + assert sorted(ACTIONS.values()) == list(range(16)) + assert ACTIONS["Toggle Screen Off"] == SCREEN_OFF_ACTION assert len(KEYS) == 15 assert capture(params)['DistanceButtonControl'] == 1 assert capture(params)['LongDistanceButtonControl'] == 5 @@ -62,7 +63,23 @@ def test_exact_catalog_and_missing_vs_saved_off(context): assert capture(params)['DistanceButtonControl'] == 0 -@pytest.mark.parametrize('key,code', [('DistanceButtonControl', code) for code in (1, 2, 5, 6, 7, 8, 11, 12, 13, 14)]) +def test_screen_off_is_directly_assignable_without_longitudinal_control(context): + from openpilot.starpilot.ui.feature_settings_state import FeatureSettingsRequest + from openpilot.starpilot.ui.wheel_feature import PREFIX, WheelFeature + + params, cp = context + owner = NS(params=params, vehicle_params=lambda: cp, configuration_vehicle=lambda: False, + configuration_longitudinal=lambda: False, longitudinal_available=lambda: False, + authority=lambda _: True) + wheel = WheelFeature(owner) + key = 'DistanceButtonControl' + assert 'Toggle Screen Off' in wheel.choices(key) + request = FeatureSettingsRequest(PREFIX + key, None, 'Toggle Screen Off', capability=wheel.capability()) + assert wheel.apply(request) + assert capture(params)[key] == SCREEN_OFF_ACTION + + +@pytest.mark.parametrize('key,code', [('DistanceButtonControl', code) for code in (1, 2, 5, 6, 7, 8, 11, 12, 13, 14, SCREEN_OFF_ACTION)]) def test_real_distance_short_delivers_once_and_claims_serialized_release(context, key, code): params, cp = context params.put(key, code, block=True) diff --git a/openpilot/starpilot/controllers/wheel_actions.py b/openpilot/starpilot/controllers/wheel_actions.py index 73ab5002e5..3fbb8abaca 100644 --- a/openpilot/starpilot/controllers/wheel_actions.py +++ b/openpilot/starpilot/controllers/wheel_actions.py @@ -10,12 +10,14 @@ from openpilot.starpilot.saved_source import read_saved from openpilot.starpilot.conditional_mode.ui_action import fresh_service +SCREEN_OFF_ACTION = 15 ACTIONS = { "Off": 0, "Cycle personality": 1, "Force coast": 2, "Pause steering": 3, "Pause longitudinal": 4, "Experimental override": 5, "Traffic mode": 6, "Switchback Mode": 7, "Bookmark": 8, "Toggle AOL": 9, "Adopt speed limit": 10, "Quick Select 1": 11, "Quick Select 2": 12, - "Quick Select 3": 13, "Pulse and glide": 14, + "Quick Select 3": 13, "Pulse and glide": 14, "Toggle Screen Off": SCREEN_OFF_ACTION, } +ACTION_VALUES = frozenset(str(value).encode() for value in ACTIONS.values()) KEYS = ("LKASButtonControl", "MainCruiseButtonControl", "DistanceButtonControl", "LongDistanceButtonControl", "VeryLongDistanceButtonControl", "CancelButtonControl", "LongCancelButtonControl", "VeryLongCancelButtonControl", "ModeButtonControl", "LongModeButtonControl", "VeryLongModeButtonControl", "StarButtonControl", @@ -23,7 +25,7 @@ KEYS = ("LKASButtonControl", "MainCruiseButtonControl", "DistanceButtonControl", PADDLE_KEY = "LeftPaddleButtonControl" LIFETIME_NS = 250_000_000 SESSION = re.compile(r"[0-9a-f]{32}\Z") -DELIVERED_ACTIONS = frozenset((1, 2, 5, 6, 7, 8, 10, 11, 12, 13, 14)) +DELIVERED_ACTIONS = frozenset((1, 2, 5, 6, 7, 8, 10, 11, 12, 13, 14, SCREEN_OFF_ACTION)) DEFAULTS = {"DistanceButtonControl": 1, "LongDistanceButtonControl": 5, "VeryLongDistanceButtonControl": 6} BUTTON_KEYS = { Button.LKAS: (KEYS[0],), Button.DISTANCE: KEYS[2:5], Button.MODE: KEYS[8:11], Button.CUSTOM: KEYS[11:14], @@ -119,7 +121,7 @@ def capture(params): result = {} for key in KEYS: raw, readable = read_saved(params, key, 8) - if not readable or raw is not None and raw not in tuple(str(value).encode() for value in range(15)): + if not readable or raw is not None and raw not in ACTION_VALUES: return None result[key] = int(raw) if raw is not None else DEFAULTS.get(key, 0) return result diff --git a/openpilot/starpilot/ui/runtime_app.py b/openpilot/starpilot/ui/runtime_app.py index 6d46b60a20..4ae20705f0 100644 --- a/openpilot/starpilot/ui/runtime_app.py +++ b/openpilot/starpilot/ui/runtime_app.py @@ -81,7 +81,7 @@ from openpilot.starpilot.ui.onroad_favorites import OnroadFavorites from openpilot.starpilot.ui.onroad_dm import DriverMonitorLayer from openpilot.starpilot.favorites.owner import FavoritesOwner from openpilot.starpilot.controllers.cruise_action import CruiseActionPublisher, ui_authority as cruise_action_authority -from openpilot.starpilot.controllers.wheel_actions import WheelConsumer +from openpilot.starpilot.controllers.wheel_actions import SCREEN_OFF_ACTION, WheelConsumer from openpilot.starpilot.ui.wheel_input import onroad_action_context from openpilot.starpilot.system.starport.projection_bookmark import BookmarkReceiver from openpilot.starpilot.system.starport.projection_slc_action import SlcActionReceiver @@ -613,6 +613,8 @@ class StarShellSession: slot = self.favorites_owner.snapshot().slots[command.action - 11] if slot.available and slot.request is not None: self.favorites_owner.invoke(slot.request) + elif command.action == SCREEN_OFF_ACTION: + native_device.toggle_screen_off() except (OSError, RuntimeError, ValueError, TypeError): pass diff --git a/openpilot/starpilot/ui/tests/test_screen_off_wheel.py b/openpilot/starpilot/ui/tests/test_screen_off_wheel.py index 23b7e9e521..04c5a501c8 100644 --- a/openpilot/starpilot/ui/tests/test_screen_off_wheel.py +++ b/openpilot/starpilot/ui/tests/test_screen_off_wheel.py @@ -15,7 +15,7 @@ from openpilot.starpilot.controllers.tests.test_native_wheel_callbacks import ( personality_session as personality_session, ) from openpilot.starpilot.controllers.tests.test_wheel_actions import Publisher, DRIVE -from openpilot.starpilot.controllers.wheel_actions import WheelPublisher +from openpilot.starpilot.controllers.wheel_actions import SCREEN_OFF_ACTION, WheelPublisher from openpilot.starpilot.ui.appearance_preferences import CameraViewChoice from openpilot.starpilot.ui.onroad_state import AlertSize, OnroadAlert from openpilot.starpilot.ui.presentation import Profile @@ -75,6 +75,30 @@ def sleeping_wheel(personality_session, monkeypatch): panel=panel, poll=lambda: caller.update_frame(star=session)) +@pytest.mark.parametrize('profile', ['c3', 'c4']) +def test_direct_screen_off_action_toggles_asleep_and_awake(sleeping_wheel, profile): + test = sleeping_wheel + test.panel(profile) + test.ui.params.put('DistanceButtonControl', SCREEN_OFF_ACTION, block=True) + + def toggle(): + test.device.awake = not test.device.awake + return True + + test.device.toggle_screen_off = toggle + event = test.emit(action=SCREEN_OFF_ACTION) + test.poll() + assert test.device.awake + test.session._mode = ShellMode.ONROAD + test.queue.append(event) + test.session._poll_wheel(test.clock[0]) + assert test.device.awake + test.clock[0] += 100_000_000 + test.emit(action=SCREEN_OFF_ACTION) + test.session._poll_wheel(test.clock[0]) + assert not test.device.awake + + @pytest.mark.parametrize('profile', ['c3', 'c4']) @pytest.mark.parametrize('vehicle', ['civic', 'ranger']) @pytest.mark.parametrize('last_mode', [ShellMode.HOME, ShellMode.SETTINGS, ShellMode.ONROAD]) diff --git a/openpilot/starpilot/ui/wheel_feature.py b/openpilot/starpilot/ui/wheel_feature.py index 59cdd7c87d..c9084af444 100644 --- a/openpilot/starpilot/ui/wheel_feature.py +++ b/openpilot/starpilot/ui/wheel_feature.py @@ -3,7 +3,9 @@ import hashlib from openpilot.starpilot.aol.vehicle import policy_for from openpilot.starpilot.conditional_mode.manual import ioniq6_media_eligible from openpilot.starpilot.feature_capabilities import lateral_supported -from openpilot.starpilot.controllers.wheel_actions import ACTIONS, DEFAULTS, KEYS, PADDLE_KEY, button_reported, eligible, paddle_bookmark_available +from openpilot.starpilot.controllers.wheel_actions import ( + ACTIONS, ACTION_VALUES, DEFAULTS, KEYS, PADDLE_KEY, SCREEN_OFF_ACTION, button_reported, eligible, paddle_bookmark_available, +) from openpilot.starpilot.saved_document import commit_exact from openpilot.starpilot.saved_source import read_saved from openpilot.starpilot.ui.feature_settings_state import FeatureRow @@ -79,7 +81,7 @@ class WheelFeature: return () if key in KEYS[8:] and not media: return () - codes = {0, 8, 11, 12, 13} + codes = {0, 8, 11, 12, 13, SCREEN_OFF_ACTION} if self.owner.longitudinal_available(): codes.update((1, 2, 5, 10, 14)) codes.add(6) @@ -115,7 +117,7 @@ class WheelFeature: if not choices: continue raw, readable = read_saved(self.owner.params, key, 8) - number = DEFAULTS.get(key, 0) if raw is None else int(raw) if raw in tuple(str(i).encode() for i in range(15)) else -1 + number = DEFAULTS.get(key, 0) if raw is None else int(raw) if raw in ACTION_VALUES else -1 selected = next((name for name, code in ACTIONS.items() if code == number), None) implicit_toggle = False if cp.brand == 'hyundai' and policy.explicit_latch and key in KEYS[:2]: diff --git a/prebuilt.json b/prebuilt.json index ae0f884a67..888dc3b13d 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "1efe2f5823e938e6f9a5653478363ad60b64c3bb47a13f9ac42ad1f2d5b521f6", "schema_version": 1} +{"protected_inventory_sha256": "c260d1d070482207be9ff251611e2d869e5ed8673f90e7355df4cacbec18641e", "schema_version": 1}