mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-06-20 01:02:07 +08:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 58d57f7e1a | |||
| 9cbc91d129 | |||
| 764ff0db6a | |||
| 8faedaa062 | |||
| 4cc43ae6f5 | |||
| 578e80855a | |||
| 66c335113e |
@@ -23,6 +23,7 @@ class UIStateSP:
|
||||
self.sunnylink_state = SunnylinkState()
|
||||
|
||||
self.custom_interactive_timeout: int = self.params.get("InteractivityTimeout", return_default=True)
|
||||
self.global_brightness_override: int = self.params.get("Brightness", return_default=True)
|
||||
|
||||
def update(self) -> None:
|
||||
if self.sunnylink_enabled:
|
||||
@@ -77,6 +78,7 @@ class UIStateSP:
|
||||
self.chevron_metrics = self.params.get("ChevronInfo")
|
||||
self.active_bundle = self.params.get("ModelManager_ActiveBundle")
|
||||
self.custom_interactive_timeout = self.params.get("InteractivityTimeout", return_default=True)
|
||||
self.global_brightness_override = self.params.get("Brightness", return_default=True)
|
||||
|
||||
|
||||
class DeviceSP:
|
||||
@@ -86,3 +88,22 @@ class DeviceSP:
|
||||
def _set_awake(self, on: bool):
|
||||
if on and self._params.get("DeviceBootMode", return_default=True) == 1:
|
||||
self._params.put_bool("OffroadMode", True)
|
||||
|
||||
@staticmethod
|
||||
def update_max_global_brightness(brightness_override: int) -> float:
|
||||
"""
|
||||
Updates the max global brightness by constraining the value to a predefined range.
|
||||
|
||||
The method takes an integer `brightness` value, adjusts it to ensure it is within the
|
||||
range of 30 to 100, inclusive, and returns the adjusted value as a float.
|
||||
|
||||
This method only runs if 0 (Auto) is not selected.
|
||||
|
||||
:param brightness_override: The desired brightness level. It is constrained between
|
||||
a minimum of 30 and a maximum of 100.
|
||||
:type brightness_override: int
|
||||
:return: The brightness value adjusted to fit within the allowable range,
|
||||
converted to a float.
|
||||
:rtype: float
|
||||
"""
|
||||
return float(min(max(brightness_override, 30), 100))
|
||||
|
||||
@@ -261,6 +261,10 @@ class Device(DeviceSP):
|
||||
clipped_brightness = float(np.interp(clipped_brightness, [0, 1], [30, 100]))
|
||||
|
||||
brightness = round(self._brightness_filter.update(clipped_brightness))
|
||||
|
||||
if gui_app.sunnypilot_ui() and ui_state.global_brightness_override != 0:
|
||||
brightness = DeviceSP.update_max_global_brightness(ui_state.global_brightness_override)
|
||||
|
||||
if not self._awake:
|
||||
brightness = 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user