X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=homescreen%2Fsrc%2Fmastervolume.cpp;h=8d7ecb419b62dfae325d20613afcc16c1f27ae84;hb=refs%2Fchanges%2F55%2F27655%2F1;hp=9fb92a9de1b6084b0b67b65fbea8c327f9658807;hpb=7a78d97346aad35b1ad023fe8d3a369e45b61ee8;p=apps%2Fhomescreen.git diff --git a/homescreen/src/mastervolume.cpp b/homescreen/src/mastervolume.cpp index 9fb92a9..8d7ecb4 100644 --- a/homescreen/src/mastervolume.cpp +++ b/homescreen/src/mastervolume.cpp @@ -15,17 +15,96 @@ */ #include "mastervolume.h" +#include +#include -void MasterVolume::setVolume(int volume) +MasterVolume::MasterVolume(QObject* parent) : + QObject(parent), + m_volume(50) { - int volume_delta = volume - m_volume; - m_volume = volume; - emit sliderVolumeChanged(volume_delta); + VehicleSignalsConfig vsConfig("homescreen"); + m_vs = new VehicleSignals(vsConfig); + + 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(); + } +} +qint32 MasterVolume::getVolume() const +{ + return m_volume; } -void MasterVolume::changeExternalVolume(int volume) +void MasterVolume::setVolume(qint32 volume) { + if (m_volume == volume) + return; + m_volume = volume; - emit volumeChanged(); + + if (!(m_vs && m_connected)) + return; + + m_vs->set("Vehicle.Cabin.Infotainment.Media.Volume", QString::number(volume)); +} + +void MasterVolume::onConnected() +{ + if (!m_vs) + return; + + m_vs->authorize(); +} + +void MasterVolume::onAuthorized() +{ + 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::onDisconnected() +{ + QObject::disconnect(m_vs, &VehicleSignals::signalNotification, this, &MasterVolume::onGetSuccessResponse); + QObject::disconnect(m_vs, &VehicleSignals::signalNotification, this, &MasterVolume::onSignalNotification); + + m_connected = false; +} + +void MasterVolume::updateVolume(QString value) +{ + bool ok; + qint32 volume = value.toInt(&ok); + if (ok) { + 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(); + } +} + +void MasterVolume::onSignalNotification(QString path, QString value, QString timestamp) +{ + if (path == "Vehicle.Cabin.Infotainment.Media.Volume") + updateVolume(value); }