mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-08-24 06:33:48 +08:00
quiet mode back
This commit is contained in:
@@ -13,7 +13,7 @@ from openpilot.common.swaglog import cloudlog
|
||||
|
||||
from openpilot.system import micd
|
||||
|
||||
from openpilot.selfdrive.ui.sunnypilot.quiet_mode import QuietMode
|
||||
from openpilot.sunnypilot.selfdrive.ui.quiet_mode import QuietMode
|
||||
|
||||
SAMPLE_RATE = 48000
|
||||
SAMPLE_BUFFER = 4096 # (approx 100ms)
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
"""
|
||||
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
|
||||
Reference in New Issue
Block a user