ui: reimplement "Screen Off" option to Onroad Brightness (#1732)

* ui: Add "Screen Off" option to Onroad Brightness

* migrate old value

* bruh

* fix algo

* comment

* no
This commit is contained in:
Jason Wen
2026-02-28 00:18:35 -05:00
committed by GitHub
parent 7eb65e878b
commit 29a3b3315f
8 changed files with 97 additions and 25 deletions

View File

@@ -170,6 +170,7 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
{"OffroadMode", {CLEAR_ON_MANAGER_START, BOOL}},
{"Offroad_TiciSupport", {CLEAR_ON_MANAGER_START, JSON}},
{"OnroadScreenOffBrightness", {PERSISTENT | BACKUP, INT, "0"}},
{"OnroadScreenOffBrightnessMigrated", {PERSISTENT | BACKUP, STRING, "0.0"}},
{"OnroadScreenOffTimer", {PERSISTENT | BACKUP, INT, "15"}},
{"OnroadUploads", {PERSISTENT | BACKUP, BOOL, "1"}},
{"QuickBootToggle", {PERSISTENT | BACKUP, BOOL, "0"}},

View File

@@ -19,6 +19,7 @@ ONROAD_BRIGHTNESS_TIMER_VALUES = {0: 15, 1: 30, **{i: (i - 1) * 60 for i in rang
class OnroadBrightness(IntEnum):
AUTO = 0
AUTO_DARK = 1
SCREEN_OFF = 2
class DisplayLayout(Widget):
@@ -35,7 +36,7 @@ class DisplayLayout(Widget):
title=lambda: tr("Onroad Brightness"),
description="",
min_value=0,
max_value=21,
max_value=22,
value_change_step=1,
label_callback=lambda value: self.update_onroad_brightness(value),
inline=True
@@ -79,7 +80,10 @@ class DisplayLayout(Widget):
if val == OnroadBrightness.AUTO_DARK:
return tr("Auto (Dark)")
return f"{(val - 1) * 5} %"
if val == OnroadBrightness.SCREEN_OFF:
return tr("Screen Off")
return f"{(val - 2) * 5} %"
def _update_state(self):
super()._update_state()

View File

@@ -162,14 +162,16 @@ class DeviceSP:
# For AUTO (Default) and Manual modes (while timer running), use standard brightness
return cur_brightness
# 0: Auto (Default), 1: Auto (Dark)
# 0: Auto (Default), 1: Auto (Dark), 2: Screen Off
if _ui_state.onroad_brightness == OnroadBrightness.AUTO:
return cur_brightness
elif _ui_state.onroad_brightness == OnroadBrightness.AUTO_DARK:
if _ui_state.onroad_brightness == OnroadBrightness.AUTO_DARK:
return cur_brightness
if _ui_state.onroad_brightness == OnroadBrightness.SCREEN_OFF:
return 0.0
# 2-21: 5% - 100%
return float((_ui_state.onroad_brightness - 1) * 5)
# 3-22: 5% - 100%
return float((_ui_state.onroad_brightness - 2) * 5)
@staticmethod
def set_min_onroad_brightness(_ui_state, min_brightness: int) -> int:

View File

@@ -845,86 +845,94 @@
},
{
"value": 2,
"label": "5 %"
"label": "Screen Off"
},
{
"value": 3,
"label": "10 %"
"label": "5 %"
},
{
"value": 4,
"label": "15 %"
"label": "10 %"
},
{
"value": 5,
"label": "20 %"
"label": "15 %"
},
{
"value": 6,
"label": "25 %"
"label": "20 %"
},
{
"value": 7,
"label": "30 %"
"label": "25 %"
},
{
"value": 8,
"label": "35 %"
"label": "30 %"
},
{
"value": 9,
"label": "40 %"
"label": "35 %"
},
{
"value": 10,
"label": "45 %"
"label": "40 %"
},
{
"value": 11,
"label": "50 %"
"label": "45 %"
},
{
"value": 12,
"label": "55 %"
"label": "50 %"
},
{
"value": 13,
"label": "60 %"
"label": "55 %"
},
{
"value": 14,
"label": "65 %"
"label": "60 %"
},
{
"value": 15,
"label": "70 %"
"label": "65 %"
},
{
"value": 16,
"label": "75 %"
"label": "70 %"
},
{
"value": 17,
"label": "80 %"
"label": "75 %"
},
{
"value": 18,
"label": "85 %"
"label": "80 %"
},
{
"value": 19,
"label": "90 %"
"label": "85 %"
},
{
"value": 20,
"label": "95 %"
"label": "90 %"
},
{
"value": 21,
"label": "95 %"
},
{
"value": 22,
"label": "100 %"
}
]
},
"OnroadScreenOffBrightnessMigrated": {
"title": "Onroad Brightness Migration Version",
"description": "This param is to track whether OnroadScreenOffBrightness needs to be migrated."
},
"OnroadScreenOffControl": {
"title": "Onroad Brightness",
"description": "Adjusts the screen brightness while it's in onroad state."

View File

@@ -53,9 +53,34 @@ def main():
print(f"Updated {METADATA_PATH}")
# update onroad screen brightness params
update_onroad_brightness_param()
# update torque versions param
update_torque_versions_param()
def update_onroad_brightness_param():
try:
with open(METADATA_PATH) as f:
params_metadata = json.load(f)
if "OnroadScreenOffBrightness" in params_metadata:
options = [
{"value": 0, "label": "Auto (Default)"},
{"value": 1, "label": "Auto (Dark)"},
{"value": 2, "label": "Screen Off"},
]
for i in range(3, 23):
options.append({"value": i, "label": f"{(i - 2) * 5} %"})
params_metadata["OnroadScreenOffBrightness"]["options"] = options
with open(METADATA_PATH, 'w') as f:
json.dump(params_metadata, f, indent=2)
f.write('\n')
print(f"Updated OnroadScreenOffBrightness options in params_metadata.json with {len(options)} options.")
except Exception as e:
print(f"Failed to update OnroadScreenOffBrightness versions in params_metadata.json: {e}")
def update_torque_versions_param():
with open(TORQUE_VERSIONS_JSON) as f:
current_versions = json.load(f)
@@ -81,5 +106,6 @@ def update_torque_versions_param():
except Exception as e:
print(f"Failed to update TorqueControlTune versions in params_metadata.json: {e}")
if __name__ == "__main__":
main()

View File

View File

@@ -0,0 +1,27 @@
"""
Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors.
This file is part of sunnypilot and is licensed under the MIT License.
See the LICENSE.md file in the root directory for more details.
"""
from openpilot.common.swaglog import cloudlog
ONROAD_BRIGHTNESS_MIGRATION_VERSION: str = "1.0"
def run_migration(_params):
# migrate OnroadScreenOffBrightness
if _params.get("OnroadScreenOffBrightnessMigrated") != ONROAD_BRIGHTNESS_MIGRATION_VERSION:
try:
val = _params.get("OnroadScreenOffBrightness")
if val >= 2: # old: 5%, new: Screen Off
new_val = val + 1
_params.put("OnroadScreenOffBrightness", new_val)
log_str = f"Successfully migrated OnroadScreenOffBrightness from {val} to {new_val}."
else:
log_str = "Migration not required for OnroadScreenOffBrightness."
_params.put("OnroadScreenOffBrightnessMigrated", ONROAD_BRIGHTNESS_MIGRATION_VERSION)
cloudlog.info(log_str + f" Setting OnroadScreenOffBrightnessMigrated to {ONROAD_BRIGHTNESS_MIGRATION_VERSION}")
except Exception as e:
cloudlog.exception(f"Error migrating OnroadScreenOffBrightness: {e}")

View File

@@ -22,6 +22,8 @@ from openpilot.system.version import get_build_metadata
from openpilot.system.hardware.hw import Paths
from openpilot.system.hardware import PC
from openpilot.sunnypilot.system.params_migration import run_migration
def manager_init() -> None:
save_bootlog()
@@ -49,6 +51,8 @@ def manager_init() -> None:
if params.get_bool("RecordFrontLock"):
params.put_bool("RecordFront", True)
run_migration(params)
# set unset params to their default value
for k in params.all_keys():
default_value = params.get_default_value(k)