mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-09-30 10:33:42 +08:00
Onroad Brightness reimpl
This commit is contained in:
@@ -7,6 +7,7 @@ See the LICENSE.md file in the root directory for more details.
|
||||
from cereal import messaging, log, custom
|
||||
from openpilot.common.params import Params
|
||||
from openpilot.sunnypilot.sunnylink.sunnylink_state import SunnylinkState
|
||||
from openpilot.system.ui.lib.application import gui_app
|
||||
|
||||
OpenpilotState = log.SelfdriveState.OpenpilotState
|
||||
MADSState = custom.ModularAssistiveDrivingSystem.ModularAssistiveDrivingSystemState
|
||||
@@ -22,12 +23,30 @@ class UIStateSP:
|
||||
|
||||
self.sunnylink_state = SunnylinkState()
|
||||
|
||||
# Onroad Screen Brightness
|
||||
self.onroad_brightness_timer: int = 0
|
||||
|
||||
def update(self) -> None:
|
||||
if self.sunnylink_enabled:
|
||||
self.sunnylink_state.start()
|
||||
else:
|
||||
self.sunnylink_state.stop()
|
||||
|
||||
def update_onroad_brightness(self, sm, started: bool) -> None:
|
||||
if started and self.onroad_brightness_toggle:
|
||||
ss = sm["selfdriveState"]
|
||||
if ss.alertSize != log.SelfdriveState.AlertSize.none and \
|
||||
ss.alertStatus != log.SelfdriveState.AlertStatus.normal:
|
||||
self.reset_onroad_sleep_timer()
|
||||
elif self.onroad_brightness_timer > 0:
|
||||
self.onroad_brightness_timer -= 1
|
||||
|
||||
def reset_onroad_sleep_timer(self) -> None:
|
||||
if self.onroad_brightness_toggle >= 0 and self.onroad_brightness_toggle:
|
||||
self.onroad_brightness_timer = self.onroad_brightness_timer_param * gui_app.target_fps
|
||||
else:
|
||||
self.onroad_brightness_timer = -1
|
||||
|
||||
@staticmethod
|
||||
def update_status(ss, ss_sp, onroad_evt) -> str:
|
||||
state = ss.state
|
||||
@@ -75,6 +94,11 @@ class UIStateSP:
|
||||
self.chevron_metrics = self.params.get("ChevronInfo")
|
||||
self.active_bundle = self.params.get("ModelManager_ActiveBundle")
|
||||
|
||||
# Onroad Screen Brightness
|
||||
self.onroad_brightness_toggle = self.params.get_bool("OnroadScreenOffControl")
|
||||
self.onroad_brightness = self.params.get("OnroadScreenOffBrightness", return_default=True)
|
||||
self.onroad_brightness_timer_param = self.params.get("OnroadScreenOffTimer", return_default=True)
|
||||
|
||||
|
||||
class DeviceSP:
|
||||
def __init__(self):
|
||||
|
||||
@@ -117,6 +117,7 @@ class UIState(UIStateSP):
|
||||
self.update_params()
|
||||
device.update()
|
||||
UIStateSP.update(self)
|
||||
UIStateSP.update_onroad_brightness(self, self.sm, self.started)
|
||||
|
||||
def _update_state(self) -> None:
|
||||
# Handle panda states updates
|
||||
@@ -261,6 +262,10 @@ class Device(DeviceSP):
|
||||
if not self._awake:
|
||||
brightness = 0
|
||||
|
||||
if gui_app.sunnypilot_ui():
|
||||
if self._awake and ui_state.started and ui_state.onroad_brightness_toggle and ui_state.onroad_brightness_timer == 0:
|
||||
brightness = ui_state.onroad_brightness * 0.01 * brightness
|
||||
|
||||
if brightness != self._last_brightness:
|
||||
if self._brightness_thread is None or not self._brightness_thread.is_alive():
|
||||
self._brightness_thread = threading.Thread(target=HARDWARE.set_screen_brightness, args=(brightness,))
|
||||
|
||||
Reference in New Issue
Block a user