diff options
author | Scott Murray <scott.murray@konsulko.com> | 2023-01-03 00:58:28 -0500 |
---|---|---|
committer | Scott Murray <scott.murray@konsulko.com> | 2023-01-19 00:36:27 +0000 |
commit | 9a7e2c5420cae0669c149d5dddbcd99a8fac0038 (patch) | |
tree | 7793553de5d8359c8dfdb2a204df41b0288a3a81 /radio/RadioClient.cpp | |
parent | 888eca5ba20672448624a418ebad573dd4d640e6 (diff) |
Rework radio support for new gRPC API
Update the stubbed out radio support library to use the new gRPC API.
The "Radio" Qt wrapper object has been renamed to "RadioClient" to
avoid conflicting with the generated gRPC API code. This somewhat
aligns with the naming that has been used with the AppLauncher
support.
Bug-AGL: SPEC-4665
Signed-off-by: Scott Murray <scott.murray@konsulko.com>
Change-Id: I642f9b9b62d6981cf5231ecea4caddba713f493a
(cherry picked from commit 22ad8cbaad00d89361cbd92023dd20a807bcf5cb)
Diffstat (limited to 'radio/RadioClient.cpp')
-rw-r--r-- | radio/RadioClient.cpp | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/radio/RadioClient.cpp b/radio/RadioClient.cpp new file mode 100644 index 0000000..a142d22 --- /dev/null +++ b/radio/RadioClient.cpp @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2018-2020,2022 Konsulko Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <QDebug> +#include "RadioClient.h" +#include "RadioGrpcClient.h" + +RadioClient::RadioClient(QQmlContext *context, QObject * parent) : + QObject(parent), + m_band(1), + m_frequency(0), + m_minFrequency(0), + m_maxFrequency(0), + m_playing(false), + m_scanning(false) +{ + m_radio = new RadioGrpcClient(this); + + if (m_radio) { + m_radio->GetBandParameters(m_band, m_minFrequency, m_maxFrequency, m_frequencyStep); + emit minFrequencyChanged(m_minFrequency); + emit maxFrequencyChanged(m_maxFrequency); + emit frequencyStepChanged(m_frequencyStep); + + // Handle start up + if (!m_frequency) { + m_frequency = m_minFrequency; + emit frequencyChanged(m_frequency); + } + } +} + +RadioClient::~RadioClient() +{ + delete m_radio; +} + +void RadioClient::setBand(int band) +{ + if (m_radio) + m_radio->SetBand(band); +} + +void RadioClient::setFrequency(int frequency) +{ + if (!m_radio) + return; + + m_radio->SetFrequency(frequency); + + // To improve UI responsiveness, signal the change here immediately + // This fixes visual glitchiness in the slider caused by the frequency + // update event taking long enough that the QML engine gets a chance + // to update the slider with the current value before the event with + // the new value comes. + m_frequency = frequency; + emit frequencyChanged(m_frequency); +} + +// control related methods + +void RadioClient::start() +{ + if (m_radio) + m_radio->Start(); +} + +void RadioClient::stop() +{ + if (m_radio) + m_radio->Stop(); +} + +void RadioClient::scanForward() +{ + if (!m_radio || m_scanning) + return; + + m_radio->ScanForward(); + + m_scanning = true; + emit scanningChanged(m_scanning); +} + +void RadioClient::scanBackward() +{ + if (!m_radio || m_scanning) + return; + + m_radio->ScanBackward(); + + m_scanning = true; + emit scanningChanged(m_scanning); +} + +void RadioClient::scanStop() +{ + if (m_radio) + m_radio->ScanStop(); + + m_scanning = false; + emit scanningChanged(m_scanning); +} + +void RadioClient::updateBand(int band) +{ + m_band = band; + emit bandChanged(m_band); +} + +void RadioClient::updateFrequency(int frequency) +{ + m_frequency = frequency; + emit frequencyChanged(m_frequency); +} + +void RadioClient::updatePlaying(bool status) +{ + m_playing = status; + emit playingChanged(m_playing); +} + +void RadioClient::updateScanning(int station_found) +{ + if (station_found && m_scanning) { + m_scanning = false; + emit scanningChanged(m_scanning); + } +} |