From 6e55c1a428a6dbc7b7d731fb554c7759d2ab1fc0 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Thu, 24 Aug 2023 15:44:08 -0400 Subject: Update VehicleSignals usage Update usage of the VehicleSignals class from libqtappfw to work with its changes to switch to using the KUKSA.val databroker. Changes: - Update set calls to use appropriate type for the signal. - Remove authorized & disconnected signal handling, as they are no-ops now. Bug-AGL: SPEC-4762 Signed-off-by: Scott Murray Change-Id: I84f9d8fa5f0c516b2f2953f8ab61797484270c95 --- homescreen/src/mastervolume.cpp | 59 +++++++++++++++-------------------------- homescreen/src/mastervolume.h | 25 ++++++++--------- 2 files changed, 32 insertions(+), 52 deletions(-) diff --git a/homescreen/src/mastervolume.cpp b/homescreen/src/mastervolume.cpp index 8d7ecb4..d173ef2 100644 --- a/homescreen/src/mastervolume.cpp +++ b/homescreen/src/mastervolume.cpp @@ -27,45 +27,49 @@ MasterVolume::MasterVolume(QObject* parent) : 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(); } } +MasterVolume::~MasterVolume() +{ + delete m_vs; +} + qint32 MasterVolume::getVolume() const { return m_volume; } -void MasterVolume::setVolume(qint32 volume) +void MasterVolume::setVolume(quint32 volume) { if (m_volume == volume) return; m_volume = volume; - if (!(m_vs && m_connected)) - return; - - m_vs->set("Vehicle.Cabin.Infotainment.Media.Volume", QString::number(volume)); + if (m_vs) + m_vs->set("Vehicle.Cabin.Infotainment.Media.Volume", volume, true); } -void MasterVolume::onConnected() +void MasterVolume::updateVolume(QString value) { - if (!m_vs) - return; - - m_vs->authorize(); + 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::onAuthorized() +void MasterVolume::onConnected() { - if (!m_vs) - return; - - m_connected = true; + if (!m_vs) + return; QObject::connect(m_vs, &VehicleSignals::getSuccessResponse, this, &MasterVolume::onGetSuccessResponse); QObject::connect(m_vs, &VehicleSignals::signalNotification, this, &MasterVolume::onSignalNotification); @@ -74,27 +78,6 @@ void MasterVolume::onAuthorized() 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") { diff --git a/homescreen/src/mastervolume.h b/homescreen/src/mastervolume.h index fbbab4b..89d763b 100644 --- a/homescreen/src/mastervolume.h +++ b/homescreen/src/mastervolume.h @@ -21,29 +21,26 @@ class MasterVolume : public QObject { Q_OBJECT - Q_PROPERTY (uint32_t volume READ getVolume WRITE setVolume NOTIFY VolumeChanged) - -private: - qint32 m_volume; - VehicleSignals *m_vs; - bool m_connected; - - void updateVolume(QString value); public: MasterVolume(QObject* parent = nullptr); - ~MasterVolume() = default; + ~MasterVolume(); Q_INVOKABLE qint32 getVolume() const; - Q_INVOKABLE void setVolume(qint32 val); + Q_INVOKABLE void setVolume(quint32 val); + Q_PROPERTY (uint32_t volume READ getVolume WRITE setVolume NOTIFY VolumeChanged) + +signals: + void VolumeChanged(); private slots: void onConnected(); - void onAuthorized(); - void onDisconnected(); void onGetSuccessResponse(QString path, QString value, QString timestamp); void onSignalNotification(QString path, QString value, QString timestamp); -signals: - void VolumeChanged(); +private: + quint32 m_volume; + VehicleSignals *m_vs; + + void updateVolume(QString value); }; -- cgit 1.2.3-korg