From 9099efccd8686f888acebca2c529b40e7d3f01bb Mon Sep 17 00:00:00 2001 From: Rick Lan Date: Sat, 13 Jul 2024 18:15:49 +0800 Subject: [PATCH] Audible Alert Mode Toggle --- CHANGELOGS.md | 7 ++++--- common/params.cc | 1 + selfdrive/ui/soundd.py | 14 +++++++++++++- system/manager/manager.py | 1 + 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOGS.md b/CHANGELOGS.md index ccb451d08..077023343 100644 --- a/CHANGELOGS.md +++ b/CHANGELOGS.md @@ -3,11 +3,12 @@ dragonpilot [latest] * Up to comma.ai openpilot master branch commit 01c2174d5968266b87f1d1fecefce5affaeaa624 (2024-07-02) * DP HIGHLIGHT: * (TESTING) Tē-Tôo / Map Module - * Road Name Display (Online OpenStreetMap) - * Speed Camera Warning (Online OpenstreetMap: Untested) - * Dedicated Speed Camera Warning (Taiwan) + * Road Name Display (Online using OSM) + * Speed Camera Warning (Online using OSM: Untested) + * Speed Camera Warning (Taiwan, Offline) * Dynamic End-to-End w/ Toggleable Road Condition Detection. * Device Auto Shutdown Toggle. + * Device Audible Alert Mode Toggle. dragonpilot [2024.07.01] ======================= diff --git a/common/params.cc b/common/params.cc index cc185b596..c98af8a1b 100644 --- a/common/params.cc +++ b/common/params.cc @@ -245,6 +245,7 @@ std::unordered_map keys = { {"dp_long_de2e_road_condition", PERSISTENT}, {"dp_device_auto_shutdown", PERSISTENT}, {"dp_device_auto_shutdown_in", PERSISTENT}, + {"dp_device_audible_alert_mode", PERSISTENT}, }; } // namespace diff --git a/selfdrive/ui/soundd.py b/selfdrive/ui/soundd.py index 0550a7db9..e0cd7abd6 100644 --- a/selfdrive/ui/soundd.py +++ b/selfdrive/ui/soundd.py @@ -12,6 +12,7 @@ from openpilot.common.retry import retry from openpilot.common.swaglog import cloudlog from openpilot.system import micd +from openpilot.common.params import Params SAMPLE_RATE = 48000 SAMPLE_BUFFER = 4096 # (approx 100ms) @@ -62,6 +63,10 @@ class Soundd: self.spl_filter_weighted = FirstOrderFilter(0, 2.5, FILTER_DT, initialized=False) + params = Params() + self._dp_device_audible_alert_mode = int(params.get("dp_device_audible_alert_mode")) + + def load_sounds(self): self.loaded_sounds: dict[int, np.ndarray] = {} @@ -82,6 +87,13 @@ class Soundd: ret = np.zeros(frames, dtype=np.float32) + # dp - set vol to 0 instead + mute = False + if self._dp_device_audible_alert_mode == 2: + mute = True + elif self._dp_device_audible_alert_mode == 1 and self.current_alert in [AudibleAlert.engage, AudibleAlert.disengage]: + mute = True + if self.current_alert != AudibleAlert.none: num_loops = sound_list[self.current_alert][1] sound_data = self.loaded_sounds[self.current_alert] @@ -97,7 +109,7 @@ class Soundd: written_frames += frames_to_write self.current_sound_frame += frames_to_write - return ret * self.current_volume + return ret * (self.current_volume if not mute else 0) def callback(self, data_out: np.ndarray, frames: int, time, status) -> None: if status: diff --git a/system/manager/manager.py b/system/manager/manager.py index d01cd958c..560cd9fb2 100755 --- a/system/manager/manager.py +++ b/system/manager/manager.py @@ -83,6 +83,7 @@ def manager_init() -> None: ("dp_long_de2e_road_condition", "1"), # on by default, depends on dp_long_de2e ("dp_device_auto_shutdown", "0"), ("dp_device_auto_shutdown_in", "30"), + ("dp_device_audible_alert_mode", "0"), ] if not PC: default_params.append(("LastUpdateTime", datetime.datetime.now(datetime.UTC).replace(tzinfo=None).isoformat().encode('utf8')))