Skip to content

Commit

Permalink
implement Hardware::set_volume using pactl
Browse files Browse the repository at this point in the history
  • Loading branch information
incognitojam committed Nov 30, 2022
1 parent 05d5c66 commit c442c34
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
4 changes: 3 additions & 1 deletion selfdrive/ui/soundd/sound.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ void Sound::update() {

// scale volume with speed
if (sm.updated("carState")) {
Hardware::set_volume(util::map_val(sm["carState"].getCarState().getVEgo(), 11.f, 20.f, 0.f, 1.f));
float volume = util::map_val(sm["carState"].getCarState().getVEgo(), 11.f, 20.f, 0.f, 1.f);
volume = QAudio::convertVolume(volume, QAudio::LogarithmicVolumeScale, QAudio::LinearVolumeScale);
Hardware::set_volume(volume);
}

setAlert(Alert::get(sm, started_frame));
Expand Down
10 changes: 9 additions & 1 deletion system/hardware/base.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#pragma once

#include <cmath>
#include <cstdlib>
#include <fstream>

#include "cereal/messaging/messaging.h"
#include "common/util.h"

// no-op base hw class
class HardwareNone {
Expand All @@ -20,12 +23,17 @@ class HardwareNone {
static void poweroff() {}
static void set_brightness(int percent) {}
static void set_display_power(bool on) {}
static void set_volume(float percent) {}
static void set_volume(float volume) {}

static bool get_ssh_enabled() { return false; }
static void set_ssh_enabled(bool enabled) {}

static bool PC() { return false; }
static bool TICI() { return false; }
static bool AGNOS() { return false; }

protected:
static float map_volume(float volume) {
return util::map_val(volume, 0.f, 1.f, MIN_VOLUME, MAX_VOLUME);
}
};
5 changes: 4 additions & 1 deletion system/hardware/pc/hardware.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include "common/util.h"
#include "system/hardware/base.h"

class HardwarePC : public HardwareNone {
Expand All @@ -11,4 +10,8 @@ class HardwarePC : public HardwareNone {
static bool PC() { return true; }
static bool TICI() { return util::getenv("TICI", 0) == 1; }
static bool AGNOS() { return util::getenv("TICI", 0) == 1; }

static void set_volume(float volume) {
std::system(std::format("pactl set-sink-volume 1 %.3f &", map_volume(volume)).c_str());
}
};
3 changes: 3 additions & 0 deletions system/hardware/tici/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class HardwareTici : public HardwareNone {
bl_power_control.close();
}
};
static void set_volume(float volume) {
std::system(std::format("pactl set-sink-volume 1 %.3f &", map_volume(volume)).c_str());
}

static bool get_ssh_enabled() { return Params().getBool("SshEnabled"); };
static void set_ssh_enabled(bool enabled) { Params().putBool("SshEnabled", enabled); };
Expand Down

0 comments on commit c442c34

Please sign in to comment.