mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-10-01 03:43:46 +08:00
ui: override default interactive timeout (#36898)
* impl * fix one place * don't need in setup * fix onboarding * need here too
This commit is contained in:
@@ -96,7 +96,6 @@ class TrainingGuideDMTutorial(Widget):
|
|||||||
# Wrap the continue callback to restore settings
|
# Wrap the continue callback to restore settings
|
||||||
def wrapped_continue_callback():
|
def wrapped_continue_callback():
|
||||||
device.set_offroad_brightness(None)
|
device.set_offroad_brightness(None)
|
||||||
device.reset_interactive_timeout()
|
|
||||||
continue_callback()
|
continue_callback()
|
||||||
|
|
||||||
self._dialog = DriverCameraSetupDialog(wrapped_continue_callback)
|
self._dialog = DriverCameraSetupDialog(wrapped_continue_callback)
|
||||||
@@ -112,7 +111,6 @@ class TrainingGuideDMTutorial(Widget):
|
|||||||
self._dialog.show_event()
|
self._dialog.show_event()
|
||||||
|
|
||||||
device.set_offroad_brightness(100)
|
device.set_offroad_brightness(100)
|
||||||
device.reset_interactive_timeout(300) # 5 minutes
|
|
||||||
|
|
||||||
def _update_state(self):
|
def _update_state(self):
|
||||||
super()._update_state()
|
super()._update_state()
|
||||||
@@ -223,6 +221,14 @@ class TrainingGuide(Widget):
|
|||||||
TrainingGuideRecordFront(continue_callback=on_continue),
|
TrainingGuideRecordFront(continue_callback=on_continue),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def show_event(self):
|
||||||
|
super().show_event()
|
||||||
|
device.set_override_interactive_timeout(300)
|
||||||
|
|
||||||
|
def hide_event(self):
|
||||||
|
super().hide_event()
|
||||||
|
device.set_override_interactive_timeout(None)
|
||||||
|
|
||||||
def _advance_step(self):
|
def _advance_step(self):
|
||||||
if self._step < len(self._steps) - 1:
|
if self._step < len(self._steps) - 1:
|
||||||
self._step += 1
|
self._step += 1
|
||||||
@@ -319,6 +325,14 @@ class OnboardingWindow(Widget):
|
|||||||
self._training_guide = TrainingGuide(completed_callback=self._on_completed_training)
|
self._training_guide = TrainingGuide(completed_callback=self._on_completed_training)
|
||||||
self._decline_page = DeclinePage(back_callback=self._on_decline_back)
|
self._decline_page = DeclinePage(back_callback=self._on_decline_back)
|
||||||
|
|
||||||
|
def show_event(self):
|
||||||
|
super().show_event()
|
||||||
|
device.set_override_interactive_timeout(300)
|
||||||
|
|
||||||
|
def hide_event(self):
|
||||||
|
super().hide_event()
|
||||||
|
device.set_override_interactive_timeout(None)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def completed(self) -> bool:
|
def completed(self) -> bool:
|
||||||
return self._accepted_terms and self._training_done
|
return self._accepted_terms and self._training_done
|
||||||
|
|||||||
@@ -51,14 +51,14 @@ class DriverCameraDialog(NavWidget):
|
|||||||
super().show_event()
|
super().show_event()
|
||||||
ui_state.params.put_bool("IsDriverViewEnabled", True)
|
ui_state.params.put_bool("IsDriverViewEnabled", True)
|
||||||
self._publish_alert_sound(None)
|
self._publish_alert_sound(None)
|
||||||
device.reset_interactive_timeout(300)
|
device.set_override_interactive_timeout(300)
|
||||||
ui_state.params.remove("DriverTooDistracted")
|
ui_state.params.remove("DriverTooDistracted")
|
||||||
self._pm = messaging.PubMaster(['selfdriveState'])
|
self._pm = messaging.PubMaster(['selfdriveState'])
|
||||||
|
|
||||||
def hide_event(self):
|
def hide_event(self):
|
||||||
super().hide_event()
|
super().hide_event()
|
||||||
ui_state.params.put_bool("IsDriverViewEnabled", False)
|
ui_state.params.put_bool("IsDriverViewEnabled", False)
|
||||||
device.reset_interactive_timeout()
|
device.set_override_interactive_timeout(None)
|
||||||
|
|
||||||
def _handle_mouse_release(self, _):
|
def _handle_mouse_release(self, _):
|
||||||
ui_state.params.remove("DriverTooDistracted")
|
ui_state.params.remove("DriverTooDistracted")
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ class Device:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._ignition = False
|
self._ignition = False
|
||||||
self._interaction_time: float = -1
|
self._interaction_time: float = -1
|
||||||
|
self._override_interactive_timeout: int | None = None
|
||||||
self._interactive_timeout_callbacks: list[Callable] = []
|
self._interactive_timeout_callbacks: list[Callable] = []
|
||||||
self._prev_timed_out = False
|
self._prev_timed_out = False
|
||||||
self._awake: bool = True
|
self._awake: bool = True
|
||||||
@@ -200,11 +201,21 @@ class Device:
|
|||||||
def awake(self) -> bool:
|
def awake(self) -> bool:
|
||||||
return self._awake
|
return self._awake
|
||||||
|
|
||||||
def reset_interactive_timeout(self, timeout: int = -1) -> None:
|
def set_override_interactive_timeout(self, timeout: int | None) -> None:
|
||||||
if timeout == -1:
|
# Override the interactive timeout duration temporarily
|
||||||
ignition_timeout = 10 if gui_app.big_ui() else 5
|
self._override_interactive_timeout = timeout
|
||||||
timeout = ignition_timeout if ui_state.ignition else 30
|
self._reset_interactive_timeout()
|
||||||
self._interaction_time = time.monotonic() + timeout
|
|
||||||
|
@property
|
||||||
|
def interactive_timeout(self) -> int:
|
||||||
|
if self._override_interactive_timeout is not None:
|
||||||
|
return self._override_interactive_timeout
|
||||||
|
|
||||||
|
ignition_timeout = 10 if gui_app.big_ui() else 5
|
||||||
|
return ignition_timeout if ui_state.ignition else 30
|
||||||
|
|
||||||
|
def _reset_interactive_timeout(self) -> None:
|
||||||
|
self._interaction_time = time.monotonic() + self.interactive_timeout
|
||||||
|
|
||||||
def add_interactive_timeout_callback(self, callback: Callable):
|
def add_interactive_timeout_callback(self, callback: Callable):
|
||||||
self._interactive_timeout_callbacks.append(callback)
|
self._interactive_timeout_callbacks.append(callback)
|
||||||
@@ -212,7 +223,7 @@ class Device:
|
|||||||
def update(self):
|
def update(self):
|
||||||
# do initial reset
|
# do initial reset
|
||||||
if self._interaction_time <= 0:
|
if self._interaction_time <= 0:
|
||||||
self.reset_interactive_timeout()
|
self._reset_interactive_timeout()
|
||||||
|
|
||||||
self._update_brightness()
|
self._update_brightness()
|
||||||
self._update_wakefulness()
|
self._update_wakefulness()
|
||||||
@@ -252,7 +263,7 @@ class Device:
|
|||||||
self._ignition = ui_state.ignition
|
self._ignition = ui_state.ignition
|
||||||
|
|
||||||
if ignition_just_turned_off or any(ev.left_down for ev in gui_app.mouse_events):
|
if ignition_just_turned_off or any(ev.left_down for ev in gui_app.mouse_events):
|
||||||
self.reset_interactive_timeout()
|
self._reset_interactive_timeout()
|
||||||
|
|
||||||
interaction_timeout = time.monotonic() > self._interaction_time
|
interaction_timeout = time.monotonic() > self._interaction_time
|
||||||
if interaction_timeout and not self._prev_timed_out:
|
if interaction_timeout and not self._prev_timed_out:
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ from openpilot.common.utils import run_cmd
|
|||||||
from openpilot.system.hardware import HARDWARE
|
from openpilot.system.hardware import HARDWARE
|
||||||
from openpilot.system.ui.lib.application import gui_app, FontWeight
|
from openpilot.system.ui.lib.application import gui_app, FontWeight
|
||||||
from openpilot.system.ui.lib.wifi_manager import WifiManager
|
from openpilot.system.ui.lib.wifi_manager import WifiManager
|
||||||
from openpilot.selfdrive.ui.ui_state import device
|
|
||||||
from openpilot.system.ui.lib.scroll_panel2 import GuiScrollPanel2
|
from openpilot.system.ui.lib.scroll_panel2 import GuiScrollPanel2
|
||||||
from openpilot.system.ui.widgets import Widget, DialogResult
|
from openpilot.system.ui.widgets import Widget, DialogResult
|
||||||
from openpilot.system.ui.widgets.button import (IconButton, SmallButton, WideRoundedButton, SmallerRoundedButton,
|
from openpilot.system.ui.widgets.button import (IconButton, SmallButton, WideRoundedButton, SmallerRoundedButton,
|
||||||
@@ -226,10 +225,6 @@ class TermsPage(Widget):
|
|||||||
self._back_button.set_opacity(0.0)
|
self._back_button.set_opacity(0.0)
|
||||||
self._scroll_down_indicator.set_opacity(1.0)
|
self._scroll_down_indicator.set_opacity(1.0)
|
||||||
|
|
||||||
def show_event(self):
|
|
||||||
super().show_event()
|
|
||||||
device.reset_interactive_timeout(300)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def _content_height(self):
|
def _content_height(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user