From 22ad8cbaad00d89361cbd92023dd20a807bcf5cb Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Tue, 3 Jan 2023 00:58:28 -0500 Subject: 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 Change-Id: I642f9b9b62d6981cf5231ecea4caddba713f493a --- radio/RadioClient.cpp | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 radio/RadioClient.cpp (limited to 'radio/RadioClient.cpp') 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 +#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); + } +} -- cgit 1.2.3-korg