add param, timeout

This commit is contained in:
nayan
2025-12-04 15:03:31 -05:00
parent 3fe8e155b6
commit 465daf323c
3 changed files with 22 additions and 4 deletions
+2
View File
@@ -170,6 +170,8 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
{"QuickBootToggle", {PERSISTENT | BACKUP, BOOL, "0"}},
{"QuietMode", {PERSISTENT | BACKUP, BOOL, "0"}},
{"RainbowMode", {PERSISTENT | BACKUP, BOOL, "0"}},
{"ScreenSaverEnabled", {PERSISTENT | BACKUP, BOOL, "0"}},
{"ScreenSaverTimeout", {PERSISTENT | BACKUP, INT, "300"}},
{"ShowAdvancedControls", {PERSISTENT | BACKUP, BOOL, "0"}},
{"ShowTurnSignals", {PERSISTENT | BACKUP, BOOL, "0"}},
{"StandstillTimer", {PERSISTENT | BACKUP, BOOL, "0"}},
+8 -3
View File
@@ -271,13 +271,18 @@ class Device:
def _set_awake(self, on: bool):
if on != self._awake:
self._awake = on
if gui_app.sunnypilot_ui() and not on:
gui_app.set_modal_overlay(ScreenSaverSP())
else:
def set_display_power():
cloudlog.debug(f"setting display power {int(on)}")
HARDWARE.set_display_power(on)
gui_app.set_should_render(on)
screensaver_enabled = True #ui_state.params.get_bool("ScreenSaverEnabled")
if gui_app.sunnypilot_ui() and not on and screensaver_enabled:
gui_app.set_modal_overlay(ScreenSaverSP(dismiss_callback=lambda: set_display_power()))
else:
set_display_power()
# Global instance
ui_state = UIState()
+12 -1
View File
@@ -1,16 +1,22 @@
import os
import time
from collections.abc import Callable
import pyray as rl
from openpilot.common.params import Params
from openpilot.system.hardware import HARDWARE
from openpilot.system.ui.lib.application import gui_app, FontWeight
from openpilot.system.ui.lib.text_measure import measure_text_cached
from openpilot.system.ui.widgets import Widget
SCREENSAVER_TIMEOUT = Params().get("ScreenSaverTimeout") or 5
class ScreenSaverSP(Widget):
def __init__(self):
def __init__(self, dismiss_callback: Callable):
super().__init__()
self.dismiss_callback = dismiss_callback
self.set_rect(rl.Rectangle(0, 0, gui_app.width, gui_app.height))
self._is_mici = HARDWARE.get_device_type() == 'mici' or (HARDWARE.get_device_type() == "pc" and os.getenv("BIG") != "1")
@@ -20,6 +26,7 @@ class ScreenSaverSP(Widget):
text_size = measure_text_cached(self.font, self.text, self.font_size, 0)
self.logo_width = text_size.x
self.logo_height = text_size.y
self._start_time = time.monotonic()
self.x = 0.0
self.y = 100.0
@@ -36,6 +43,9 @@ class ScreenSaverSP(Widget):
def _update_state(self):
super()._update_state()
if time.monotonic() - self._start_time > SCREENSAVER_TIMEOUT:
self._dismiss = True
dt = rl.get_frame_time()
self.x += self.vx * dt
@@ -65,6 +75,7 @@ class ScreenSaverSP(Widget):
def _render(self, rect: rl.Rectangle):
if self._dismiss:
self.dismiss_callback()
return 0
self.set_rect(rect)