aboutsummaryrefslogtreecommitdiffstats
path: root/homescreen/src/mastervolume.cpp
diff options
context:
space:
mode:
authorScott Murray <scott.murray@konsulko.com>2022-06-17 20:30:05 -0400
committerScott Murray <scott.murray@konsulko.com>2022-07-04 21:23:37 +0000
commite490ff1e1e31b4a837cb8063f7346dc65ffe073e (patch)
tree083e89ee22258db4c91fc8398a6cbbbd5aa14afb /homescreen/src/mastervolume.cpp
parentc35327b02a28a83536450a664326d183662e89e1 (diff)
Add VIS vehicle signal support
Update the volume control code to use to use VIS signalling instead of the previous agl-service-audiomixer binding usage. Bug-AGL: SPEC-4409 Signed-off-by: Scott Murray <scott.murray@konsulko.com> Change-Id: Ifc622a51991110c7786b80ee0af574ed6ca80561 (cherry picked from commit e3b392b8a0767f35e6dbbdb1e9d126294aebdcb5)
Diffstat (limited to 'homescreen/src/mastervolume.cpp')
-rw-r--r--homescreen/src/mastervolume.cpp122
1 files changed, 58 insertions, 64 deletions
diff --git a/homescreen/src/mastervolume.cpp b/homescreen/src/mastervolume.cpp
index de8d75d..8d7ecb4 100644
--- a/homescreen/src/mastervolume.cpp
+++ b/homescreen/src/mastervolume.cpp
@@ -18,25 +18,21 @@
#include <QTimer>
#include <QtDebug>
-#define MASTER_CONTROL "Master Playback"
-
-MasterVolume::MasterVolume(QObject* parent)
- : QObject(parent)
- , m_volume{50}
+MasterVolume::MasterVolume(QObject* parent) :
+ QObject(parent),
+ m_volume(50)
{
-#if 0
- connect(&m_client, SIGNAL(connected()), this, SLOT(onClientConnected()));
- connect(&m_client, SIGNAL(disconnected()), this, SLOT(onClientDisconnected()));
- connect(&m_client, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onClientError(QAbstractSocket::SocketError)));
- connect(&m_client, SIGNAL(eventReceived(QString, const QJsonValue&)), this, SLOT(onClientEventReceived(QString, const QJsonValue&)));
-#endif
-}
+ VehicleSignalsConfig vsConfig("homescreen");
+ m_vs = new VehicleSignals(vsConfig);
-#if 0
-void MasterVolume::open(const QUrl& url)
-{
+ if (m_vs) {
+ QObject::connect(m_vs, &VehicleSignals::connected, this, &MasterVolume::onConnected);
+ QObject::connect(m_vs, &VehicleSignals::authorized, this, &MasterVolume::onAuthorized);
+ QObject::connect(m_vs, &VehicleSignals::disconnected, this, &MasterVolume::onDisconnected);
+
+ m_vs->connect();
+ }
}
-#endif
qint32 MasterVolume::getVolume() const
{
@@ -45,72 +41,70 @@ qint32 MasterVolume::getVolume() const
void MasterVolume::setVolume(qint32 volume)
{
- if (m_volume != volume)
- {
- m_volume = volume;
-#if 0
- QJsonObject arg;
- arg.insert("control", MASTER_CONTROL);
- double v = (double) volume / 100.0;
- arg.insert("value", v);
- m_client.call("audiomixer", "volume", arg);
-#endif
- }
-}
+ if (m_volume == volume)
+ return;
-#if 0
+ m_volume = volume;
-void MasterVolume::onClientConnected()
-{
+ if (!(m_vs && m_connected))
+ return;
- QJsonObject arg;
- arg.insert("control", MASTER_CONTROL);
- m_client.call("audiomixer", "volume", arg, [this](bool r, const QJsonValue& v) {
- if (r && v.isObject()) {
- int volume = v.toObject()["response"].toObject()["volume"].toDouble() * 100;
- volume = qBound(0, volume, 100);
- if (m_volume != volume)
- {
- m_volume = volume;
- emit VolumeChanged();
- }
- }
-
- QJsonObject arg;
- arg.insert("event", "volume_changed");
- m_client.call("audiomixer", "subscribe", arg);
- });
+ m_vs->set("Vehicle.Cabin.Infotainment.Media.Volume", QString::number(volume));
}
-void MasterVolume::onClientDisconnected()
+void MasterVolume::onConnected()
{
- qDebug() << "MasterVolume::onClientDisconnected!";
- QTimer::singleShot(1000, this, SLOT(TryOpen()));
+ if (!m_vs)
+ return;
+
+ m_vs->authorize();
}
-void MasterVolume::onClientError(QAbstractSocket::SocketError se)
+void MasterVolume::onAuthorized()
{
- qDebug() << "MasterVolume::onClientError: " << se;
+ if (!m_vs)
+ return;
+
+ m_connected = true;
+
+ QObject::connect(m_vs, &VehicleSignals::getSuccessResponse, this, &MasterVolume::onGetSuccessResponse);
+ QObject::connect(m_vs, &VehicleSignals::signalNotification, this, &MasterVolume::onSignalNotification);
+
+ m_vs->subscribe("Vehicle.Cabin.Infotainment.Media.Volume");
+ m_vs->get("Vehicle.Cabin.Infotainment.Media.Volume");
}
-void MasterVolume::onClientEventReceived(QString name, const QJsonValue& data)
+void MasterVolume::onDisconnected()
{
- qDebug() << "MasterVolume::onClientEventReceived[" << name << "]: " << data;
- if (name == "audiomixer/volume_changed")
- {
- QString ctlName = data.toObject()["control"].toString();
+ QObject::disconnect(m_vs, &VehicleSignals::signalNotification, this, &MasterVolume::onGetSuccessResponse);
+ QObject::disconnect(m_vs, &VehicleSignals::signalNotification, this, &MasterVolume::onSignalNotification);
- if (ctlName != MASTER_CONTROL)
- return;
+ m_connected = false;
+}
- int volume = data.toObject()["value"].toDouble() * 100;
+void MasterVolume::updateVolume(QString value)
+{
+ bool ok;
+ qint32 volume = value.toInt(&ok);
+ if (ok) {
volume = qBound(0, volume, 100);
- if (m_volume != volume)
- {
+ if (m_volume != volume) {
m_volume = volume;
emit VolumeChanged();
}
}
}
-#endif
+void MasterVolume::onGetSuccessResponse(QString path, QString value, QString timestamp)
+{
+ if (path == "Vehicle.Cabin.Infotainment.Media.Volume") {
+ updateVolume(value);
+ emit VolumeChanged();
+ }
+}
+
+void MasterVolume::onSignalNotification(QString path, QString value, QString timestamp)
+{
+ if (path == "Vehicle.Cabin.Infotainment.Media.Volume")
+ updateVolume(value);
+}