Alert Volume Controller

Added toggle for "Alert Volume Controller" to customize the volume level for each individual sound in openpilot.
This commit is contained in:
FrogAi
2024-03-26 16:36:49 -07:00
parent 613ed4b64c
commit b58bc95a58
5 changed files with 54 additions and 3 deletions
+8
View File
@@ -212,18 +212,26 @@ std::unordered_map<std::string, uint32_t> keys = {
{"AccelerationPath", PERSISTENT},
{"AccelerationProfile", PERSISTENT},
{"AggressiveAcceleration", PERSISTENT},
{"AlertVolumeControl", PERSISTENT},
{"ApiCache_DriveStats", PERSISTENT},
{"CustomAlerts", PERSISTENT},
{"CustomPaths", PERSISTENT},
{"CustomUI", PERSISTENT},
{"DecelerationProfile", PERSISTENT},
{"DisengageVolume", PERSISTENT},
{"EngageVolume", PERSISTENT},
{"FrogPilotTogglesUpdated", PERSISTENT},
{"FrogsGoMoo", PERSISTENT},
{"LateralTune", PERSISTENT},
{"LongitudinalTune", PERSISTENT},
{"PromptDistractedVolume", PERSISTENT},
{"PromptVolume", PERSISTENT},
{"QOLControls", PERSISTENT},
{"QOLVisuals", PERSISTENT},
{"RefuseVolume", PERSISTENT},
{"StockTune", PERSISTENT},
{"WarningImmediateVolume", PERSISTENT},
{"WarningSoftVolume", PERSISTENT},
};
} // namespace
Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

@@ -2,6 +2,15 @@
FrogPilotVisualsPanel::FrogPilotVisualsPanel(SettingsWindow *parent) : FrogPilotListWidget(parent) {
const std::vector<std::tuple<QString, QString, QString, QString>> visualToggles {
{"AlertVolumeControl", tr("Alert Volume Controller"), tr("Control the volume level for each individual sound in openpilot."), "../frogpilot/assets/toggle_icons/icon_mute.png"},
{"DisengageVolume", tr("Disengage Volume"), tr("Related alerts:\n\nAdaptive Cruise Disabled\nParking Brake Engaged\nBrake Pedal Pressed\nSpeed too Low"), ""},
{"EngageVolume", tr("Engage Volume"), tr("Related alerts:\n\nNNFF Torque Controller loaded\nopenpilot engaged"), ""},
{"PromptVolume", tr("Prompt Volume"), tr("Related alerts:\n\nCar Detected in Blindspot\nSpeed too Low\nSteer Unavailable Below 'X'\nTake Control, Turn Exceeds Steering Limit"), ""},
{"PromptDistractedVolume", tr("Prompt Distracted Volume"), tr("Related alerts:\n\nPay Attention, Driver Distracted\nTouch Steering Wheel, Driver Unresponsive"), ""},
{"RefuseVolume", tr("Refuse Volume"), tr("Related alerts:\n\nopenpilot Unavailable"), ""},
{"WarningSoftVolume", tr("Warning Soft Volume"), tr("Related alerts:\n\nBRAKE!, Risk of Collision\nTAKE CONTROL IMMEDIATELY"), ""},
{"WarningImmediateVolume", tr("Warning Immediate Volume"), tr("Related alerts:\n\nDISENGAGE IMMEDIATELY, Driver Distracted\nDISENGAGE IMMEDIATELY, Driver Unresponsive"), ""},
{"CustomAlerts", tr("Custom Alerts"), tr("Enable custom alerts for openpilot events."), "../frogpilot/assets/toggle_icons/icon_green_light.png"},
{"CustomUI", tr("Custom Onroad UI"), tr("Customize the Onroad UI."), "../assets/offroad/icon_road.png"},
@@ -13,7 +22,23 @@ FrogPilotVisualsPanel::FrogPilotVisualsPanel(SettingsWindow *parent) : FrogPilot
for (const auto &[param, title, desc, icon] : visualToggles) {
ParamControl *toggle;
if (param == "CustomAlerts") {
if (param == "AlertVolumeControl") {
FrogPilotParamManageControl *alertVolumeControlToggle = new FrogPilotParamManageControl(param, title, desc, icon, this);
QObject::connect(alertVolumeControlToggle, &FrogPilotParamManageControl::manageButtonClicked, this, [this]() {
openParentToggle();
for (auto &[key, toggle] : toggles) {
toggle->setVisible(alertVolumeControlKeys.find(key.c_str()) != alertVolumeControlKeys.end());
}
});
toggle = alertVolumeControlToggle;
} else if (alertVolumeControlKeys.find(param) != alertVolumeControlKeys.end()) {
if (param == "WarningImmediateVolume") {
toggle = new FrogPilotParamValueControl(param, title, desc, icon, 25, 100, std::map<int, QString>(), this, false, "%");
} else {
toggle = new FrogPilotParamValueControl(param, title, desc, icon, 0, 100, std::map<int, QString>(), this, false, "%");
}
} else if (param == "CustomAlerts") {
FrogPilotParamManageControl *customAlertsToggle = new FrogPilotParamManageControl(param, title, desc, icon, this);
QObject::connect(customAlertsToggle, &FrogPilotParamManageControl::manageButtonClicked, this, [this]() {
openParentToggle();
@@ -22,7 +22,7 @@ private:
void updateState(const UIState &s);
void updateToggles();
std::set<QString> alertVolumeControlKeys = {};
std::set<QString> alertVolumeControlKeys = {"DisengageVolume", "EngageVolume", "PromptDistractedVolume", "PromptVolume", "RefuseVolume", "WarningImmediateVolume", "WarningSoftVolume"};
std::set<QString> customAlertsKeys = {};
std::set<QString> customOnroadUIKeys = {"CustomPaths"};
std::set<QString> customThemeKeys = {};
+19 -1
View File
@@ -150,10 +150,13 @@ class Soundd:
while True:
sm.update(0)
if sm.updated['microphone'] and self.current_alert == AudibleAlert.none: # only update volume filter when not playing alert
if sm.updated['microphone'] and self.current_alert == AudibleAlert.none and not self.alert_volume_control: # only update volume filter when not playing alert
self.spl_filter_weighted.update(sm["microphone"].soundPressureWeightedDb)
self.current_volume = self.calculate_volume(float(self.spl_filter_weighted.x))
elif self.alert_volume_control and self.current_alert in self.volume_map:
self.current_volume = self.volume_map[self.current_alert] / 100.0
self.get_audible_alert(sm)
rk.keep_time()
@@ -165,6 +168,21 @@ class Soundd:
self.update_frogpilot_params()
def update_frogpilot_params(self):
self.alert_volume_control = self.params.get_bool("AlertVolumeControl")
self.volume_map = {
AudibleAlert.engage: self.params.get_int("EngageVolume"),
AudibleAlert.disengage: self.params.get_int("DisengageVolume"),
AudibleAlert.refuse: self.params.get_int("RefuseVolume"),
AudibleAlert.prompt: self.params.get_int("PromptVolume"),
AudibleAlert.promptRepeat: self.params.get_int("PromptVolume"),
AudibleAlert.promptDistracted: self.params.get_int("PromptDistractedVolume"),
AudibleAlert.warningSoft: self.params.get_int("WarningSoftVolume"),
AudibleAlert.warningImmediate: self.params.get_int("WarningImmediateVolume"),
}
self.load_sounds()
def main():