X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=homescreen%2Fsrc%2Fmastervolume.cpp;h=d173ef2bd30181a50051ef7e623d4b2f89a1ef84;hb=refs%2Fchanges%2F98%2F29598%2F1;hp=de8d75d14195fea651a5a6e694a4e06382dd73b1;hpb=2b7ca7a6eeb79e03507abb7a16b0503591d2b064;p=apps%2Fhomescreen.git diff --git a/homescreen/src/mastervolume.cpp b/homescreen/src/mastervolume.cpp index de8d75d..d173ef2 100644 --- a/homescreen/src/mastervolume.cpp +++ b/homescreen/src/mastervolume.cpp @@ -18,99 +18,76 @@ #include #include -#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 (m_vs) { + QObject::connect(m_vs, &VehicleSignals::connected, this, &MasterVolume::onConnected); + + m_vs->connect(); + } } -#if 0 -void MasterVolume::open(const QUrl& url) +MasterVolume::~MasterVolume() { + delete m_vs; } -#endif qint32 MasterVolume::getVolume() const { return m_volume; } -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 0 - -void MasterVolume::onClientConnected() +void MasterVolume::setVolume(quint32 volume) { + if (m_volume == volume) + 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(); - } - } + m_volume = volume; - QJsonObject arg; - arg.insert("event", "volume_changed"); - m_client.call("audiomixer", "subscribe", arg); - }); + if (m_vs) + m_vs->set("Vehicle.Cabin.Infotainment.Media.Volume", volume, true); } -void MasterVolume::onClientDisconnected() +void MasterVolume::updateVolume(QString value) { - qDebug() << "MasterVolume::onClientDisconnected!"; - QTimer::singleShot(1000, this, SLOT(TryOpen())); + bool ok; + quint32 volume = value.toUInt(&ok); + if (ok) { + volume = qBound(0U, volume, 100U); + if (m_volume != volume) { + m_volume = volume; + emit VolumeChanged(); + } + } } -void MasterVolume::onClientError(QAbstractSocket::SocketError se) +void MasterVolume::onConnected() { - qDebug() << "MasterVolume::onClientError: " << se; -} + if (!m_vs) + return; -void MasterVolume::onClientEventReceived(QString name, const QJsonValue& data) -{ - qDebug() << "MasterVolume::onClientEventReceived[" << name << "]: " << data; - if (name == "audiomixer/volume_changed") - { - QString ctlName = data.toObject()["control"].toString(); + QObject::connect(m_vs, &VehicleSignals::getSuccessResponse, this, &MasterVolume::onGetSuccessResponse); + QObject::connect(m_vs, &VehicleSignals::signalNotification, this, &MasterVolume::onSignalNotification); - if (ctlName != MASTER_CONTROL) - return; + m_vs->subscribe("Vehicle.Cabin.Infotainment.Media.Volume"); + m_vs->get("Vehicle.Cabin.Infotainment.Media.Volume"); +} - int volume = data.toObject()["value"].toDouble() * 100; - volume = qBound(0, volume, 100); - if (m_volume != volume) - { - m_volume = volume; - emit VolumeChanged(); - } +void MasterVolume::onGetSuccessResponse(QString path, QString value, QString timestamp) +{ + if (path == "Vehicle.Cabin.Infotainment.Media.Volume") { + updateVolume(value); + emit VolumeChanged(); } } -#endif +void MasterVolume::onSignalNotification(QString path, QString value, QString timestamp) +{ + if (path == "Vehicle.Cabin.Infotainment.Media.Volume") + updateVolume(value); +}