2 * Copyright (C) 2017 Konsulko Group
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "mastervolume.h"
21 MasterVolume::MasterVolume(QObject* parent) :
25 VehicleSignalsConfig vsConfig("homescreen");
26 m_vs = new VehicleSignals(vsConfig);
29 QObject::connect(m_vs, &VehicleSignals::connected, this, &MasterVolume::onConnected);
30 QObject::connect(m_vs, &VehicleSignals::authorized, this, &MasterVolume::onAuthorized);
31 QObject::connect(m_vs, &VehicleSignals::disconnected, this, &MasterVolume::onDisconnected);
37 qint32 MasterVolume::getVolume() const
42 void MasterVolume::setVolume(qint32 volume)
44 if (m_volume == volume)
49 if (!(m_vs && m_connected))
52 m_vs->set("Vehicle.Cabin.Infotainment.Media.Volume", QString::number(volume));
55 void MasterVolume::onConnected()
63 void MasterVolume::onAuthorized()
70 QObject::connect(m_vs, &VehicleSignals::getSuccessResponse, this, &MasterVolume::onGetSuccessResponse);
71 QObject::connect(m_vs, &VehicleSignals::signalNotification, this, &MasterVolume::onSignalNotification);
73 m_vs->subscribe("Vehicle.Cabin.Infotainment.Media.Volume");
74 m_vs->get("Vehicle.Cabin.Infotainment.Media.Volume");
77 void MasterVolume::onDisconnected()
79 QObject::disconnect(m_vs, &VehicleSignals::signalNotification, this, &MasterVolume::onGetSuccessResponse);
80 QObject::disconnect(m_vs, &VehicleSignals::signalNotification, this, &MasterVolume::onSignalNotification);
85 void MasterVolume::updateVolume(QString value)
88 qint32 volume = value.toInt(&ok);
90 volume = qBound(0, volume, 100);
91 if (m_volume != volume) {
98 void MasterVolume::onGetSuccessResponse(QString path, QString value, QString timestamp)
100 if (path == "Vehicle.Cabin.Infotainment.Media.Volume") {
102 emit VolumeChanged();
106 void MasterVolume::onSignalNotification(QString path, QString value, QString timestamp)
108 if (path == "Vehicle.Cabin.Infotainment.Media.Volume")