mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-02 20:12:07 +08:00
Qt UI: scale volume with speed (#20441)
* Qt UI: scale volume with speed * for all hw * way too loud for tici * set volume * volume * swap old-commit-hash: f1da1f9cb2731f5dc762e7780d79146e2a8f8e20
This commit is contained in:
+18
-4
@@ -2,8 +2,11 @@
|
||||
|
||||
#include <cstdio>
|
||||
#include <csignal>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <atomic>
|
||||
@@ -11,9 +14,7 @@
|
||||
#include <fstream>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <cassert>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <algorithm>
|
||||
|
||||
#ifndef sighandler_t
|
||||
typedef void (*sighandler_t)(int sig);
|
||||
@@ -38,6 +39,19 @@ int set_core_affinity(int core);
|
||||
|
||||
namespace util {
|
||||
|
||||
// ***** math helpers *****
|
||||
|
||||
// map x from [a1, a2] to [b1, b2]
|
||||
template<typename T>
|
||||
T map_val(T x, T a1, T a2, T b1, T b2) {
|
||||
x = std::clamp(x, a1, a2);
|
||||
T ra = a2 - a1;
|
||||
T rb = b2 - b1;
|
||||
return (x - a1)*rb / ra + b1;
|
||||
}
|
||||
|
||||
// ***** string helpers *****
|
||||
|
||||
inline bool starts_with(const std::string &s, const std::string &prefix) {
|
||||
return s.compare(0, prefix.size(), prefix) == 0;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
// no-op base hw class
|
||||
class HardwareNone {
|
||||
public:
|
||||
static constexpr float MAX_VOLUME = 0;
|
||||
static constexpr float MIN_VOLUME = 0;
|
||||
|
||||
static std::string get_os_version() { return "openpilot for PC"; };
|
||||
|
||||
static void reboot() {};
|
||||
@@ -29,6 +32,9 @@ public:
|
||||
|
||||
class HardwareEon : public HardwareNone {
|
||||
public:
|
||||
static constexpr float MAX_VOLUME = 1.0;
|
||||
static constexpr float MIN_VOLUME = 0.5;
|
||||
|
||||
static std::string get_os_version() {
|
||||
return "NEOS " + util::read_file("/VERSION");
|
||||
};
|
||||
@@ -54,6 +60,9 @@ public:
|
||||
|
||||
class HardwareTici : public HardwareNone {
|
||||
public:
|
||||
static constexpr float MAX_VOLUME = 0.5;
|
||||
static constexpr float MIN_VOLUME = 0.4;
|
||||
|
||||
static std::string get_os_version() {
|
||||
return "AGNOS " + util::read_file("/VERSION");
|
||||
};
|
||||
|
||||
@@ -278,6 +278,10 @@ void GLWindow::timerUpdate() {
|
||||
|
||||
handle_display_state(&ui_state, false);
|
||||
|
||||
// scale volume with speed
|
||||
sound.volume = util::map_val(ui_state.scene.car_state.getVEgo(), 0.f, 20.f,
|
||||
Hardware::MIN_VOLUME, Hardware::MAX_VOLUME);
|
||||
|
||||
ui_update(&ui_state);
|
||||
repaint();
|
||||
watchdog_kick();
|
||||
|
||||
@@ -11,7 +11,7 @@ QtSound::QtSound() {
|
||||
bool QtSound::play(AudibleAlert alert) {
|
||||
int loops = sound_map[alert].second> - 1 ? sound_map[alert].second : QSoundEffect::Infinite;
|
||||
sounds[alert].setLoopCount(loops);
|
||||
sounds[alert].setVolume(0.45);
|
||||
sounds[alert].setVolume(volume);
|
||||
sounds[alert].play();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ public:
|
||||
bool play(AudibleAlert alert);
|
||||
void stop();
|
||||
void setVolume(int volume);
|
||||
float volume = 0;
|
||||
|
||||
private:
|
||||
std::map<AudibleAlert, QSoundEffect> sounds;
|
||||
|
||||
Reference in New Issue
Block a user