mirror of
https://github.com/infiniteCable2/openpilot.git
synced 2026-08-05 00:05:57 +08:00
029a601674
* init quiet mode * only for sunny * static * toggle * let's back this up * review sugg * oh okay * review * fix: ensure boolean conversion for QuietDrive parameter * Refactor return statement to use boolean conversion for clarity in quiet mode logic * Update selfdrive/ui/sunnypilot/quietmode.py * rename * sunny * Revert "sunny" This reverts commit 6ac4cf4b8d3b0f8576cdec0146f3815a662a01a5. * sunny * Revert "sunny" This reverts commit c2bffddc052bdc2e269f3f7070934037c490810a. * sunny * ui: support dynamic state updates for `PushButtonSP` * test btn * override mouse release events * Revert "test btn" This reverts commit cd9c9dde9a37a8b2c7de7ad123cbb53f80e9e5e6. * Reapply "test btn" This reverts commit 9b36b2e08500d81cecb95f6c47a66a43e2dcd1b4. * abstract param flipping * Revert "Reapply "test btn"" This reverts commit 8104a262b02303b1c6fe2df00b2d65408fa010ea. * use new button state for PushButtonSP * Quiet Drive -> Quiet Mode * driver camera btn moved --------- Co-authored-by: Jason Wen <haibin.wen3@gmail.com>
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
"""
|
|
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 cereal import car
|
|
|
|
from openpilot.common.params import Params
|
|
|
|
AudibleAlert = car.CarControl.HUDControl.AudibleAlert
|
|
|
|
ALERTS_ALWAYS_PLAY = {
|
|
AudibleAlert.warningSoft,
|
|
AudibleAlert.warningImmediate,
|
|
AudibleAlert.promptDistracted,
|
|
AudibleAlert.promptRepeat,
|
|
}
|
|
|
|
class QuietMode:
|
|
def __init__(self):
|
|
self.params = Params()
|
|
self.enabled: bool = self.params.get_bool("QuietMode")
|
|
self._frame = 0
|
|
|
|
def load_param(self) -> None:
|
|
self._frame += 1
|
|
if self._frame % 50 == 0: # 2.5 seconds
|
|
self.enabled = self.params.get_bool("QuietMode")
|
|
|
|
def should_play_sound(self, current_alert: int) -> bool:
|
|
"""
|
|
Check if a sound should be played based on the Quiet Mode setting
|
|
and the current alert.
|
|
"""
|
|
if not self.enabled:
|
|
return bool(current_alert != AudibleAlert.none)
|
|
|
|
return current_alert in ALERTS_ALWAYS_PLAY
|