1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
|
// Copyright (C) 2021 The Qt Company Ltd.
// Copyright (C) 2019 Luxoft Sweden AB
// Copyright (C) 2018 Pelagicore AG
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qifamfmtuner.h"
#include "qifamfmtuner_p.h"
#include <QtInterfaceFramework/QIfServiceObject>
#include <QtDebug>
using namespace Qt::StringLiterals;
QT_BEGIN_NAMESPACE
QIfAmFmTunerPrivate::QIfAmFmTunerPrivate(const QString &interface, QIfAmFmTuner *parent)
: QIfAbstractFeaturePrivate(interface, parent)
, q_ptr(parent)
, m_frequency(-1)
, m_minimumFrequency(-1)
, m_maximumFrequency(-1)
, m_stepSize(-1)
, m_band(QIfAmFmTuner::FMBand)
, m_scanRunning(false)
{
qRegisterMetaType<QIfTunerStation>();
qRegisterMetaType<QIfAmFmTunerStation>();
}
void QIfAmFmTunerPrivate::clearToDefaults()
{
onFrequencyChanged(-1);
onMinimumFrequencyChanged(-1);
onMaximumFrequencyChanged(-1);
onStepSizeChanged(-1);
onBandChanged(QIfAmFmTuner::FMBand);
onStationChanged(QIfAmFmTunerStation());
onScanStatusChanged(false);
}
void QIfAmFmTunerPrivate::onFrequencyChanged(int frequency)
{
if (m_frequency == frequency)
return;
Q_Q(QIfAmFmTuner);
m_frequency = frequency;
emit q->frequencyChanged(frequency);
}
void QIfAmFmTunerPrivate::onMinimumFrequencyChanged(int frequency)
{
if (m_minimumFrequency == frequency)
return;
Q_Q(QIfAmFmTuner);
m_minimumFrequency = frequency;
emit q->minimumFrequencyChanged(frequency);
}
void QIfAmFmTunerPrivate::onMaximumFrequencyChanged(int frequency)
{
if (m_maximumFrequency == frequency)
return;
Q_Q(QIfAmFmTuner);
m_maximumFrequency = frequency;
emit q->maximumFrequencyChanged(frequency);
}
void QIfAmFmTunerPrivate::onStepSizeChanged(int stepSize)
{
if (m_stepSize == stepSize)
return;
Q_Q(QIfAmFmTuner);
m_stepSize = stepSize;
emit q->stepSizeChanged(stepSize);
}
void QIfAmFmTunerPrivate::onBandChanged(QIfAmFmTuner::Band band)
{
if (m_band == band)
return;
Q_Q(QIfAmFmTuner);
m_band = band;
emit q->bandChanged(band);
}
void QIfAmFmTunerPrivate::onStationChanged(const QIfAmFmTunerStation &station)
{
if (m_station == station)
return;
Q_Q(QIfAmFmTuner);
m_station = station;
emit q->stationChanged(station);
}
void QIfAmFmTunerPrivate::onScanStatusChanged(bool scanRunning)
{
if (m_scanRunning == scanRunning)
return;
Q_Q(QIfAmFmTuner);
m_scanRunning = scanRunning;
emit q->scanRunningChanged(scanRunning);
if (scanRunning)
emit q->scanStarted();
else
emit q->scanStopped();
}
QIfAmFmTunerBackendInterface *QIfAmFmTunerPrivate::tunerBackend() const
{
return backend<QIfAmFmTunerBackendInterface*>();
}
/*!
\class QIfAmFmTuner
\inmodule QtIfMedia
\brief Provides a interface to control the AM/FM tuner.
The QIfAmFmTuner provides the methods to control a AM/FM tuner.
Uses \c qtifmedia as configurationId for \l QIfConfiguration based settings.
*/
/*!
\qmltype AmFmTuner
\instantiates QIfAmFmTuner
\inqmlmodule QtInterfaceFramework.Media
\inherits AbstractFeature
\brief Provides a interface to control the AM/FM tuner.
The AmFmTuner provides the methods to control a AM/FM tuner.
Uses \c qtifmedia as configurationId for \l InterfaceFrameworkConfiguration based settings.
*/
/*!
\enum QIfAmFmTuner::Band
\value AMBand
The AM Band is based on the Amplitude Modulation technique and can range from 520 to 1610 kHz (1710 kHz).
The step size is usually between 9 or 10 kHz.
\value FMBand
The FM Band is based on the Frequency Modulation technique and can range from 87.5 to 108.0 MHz.
The step size is usually 100 kHz.
*/
/*!
Constructs a QIfAmFmTuner.
The \a parent argument is passed on to the \l QIfAbstractFeature base class.
*/
QIfAmFmTuner::QIfAmFmTuner(QObject *parent)
: QIfAbstractFeature(*new QIfAmFmTunerPrivate(QLatin1String(QIfAmFmTuner_iid), this), parent)
{
setConfigurationId(u"qtifmedia"_s);
}
/*!
\qmlproperty int AmFmTuner::frequency
\brief The current frequency of the tuner.
*/
/*!
\property QIfAmFmTuner::frequency
\brief The current frequency of the tuner.
*/
int QIfAmFmTuner::frequency() const
{
Q_D(const QIfAmFmTuner);
return d->m_frequency;
}
/*!
\qmlproperty int AmFmTuner::minimumFrequency
\brief The minimum frequency of the current band.
*/
/*!
\property QIfAmFmTuner::minimumFrequency
\brief The minimum frequency of the current band.
*/
int QIfAmFmTuner::minimumFrequency() const
{
Q_D(const QIfAmFmTuner);
return d->m_minimumFrequency;
}
/*!
\qmlproperty int AmFmTuner::maximumFrequency
\brief The maximum frequency of the current band.
*/
/*!
\property QIfAmFmTuner::maximumFrequency
\brief The maximum frequency of the current band.
*/
int QIfAmFmTuner::maximumFrequency() const
{
Q_D(const QIfAmFmTuner);
return d->m_maximumFrequency;
}
/*!
\qmlproperty int AmFmTuner::stepSize
\brief The frequency step size of the current band.
\sa stepUp() stepDown()
*/
/*!
\property QIfAmFmTuner::stepSize
\brief The frequency step size of the current band.
\sa stepUp() stepDown()
*/
int QIfAmFmTuner::stepSize() const
{
Q_D(const QIfAmFmTuner);
return d->m_stepSize;
}
/*!
\qmlproperty enumeration AmFmTuner::band
\brief The current band of the tuner.
Available values are:
\value AMBand
The AM Band is based on the Amplitude Modulation technique and can range from 520 to 1610 kHz (1710 kHz).
The step size is usually between 9 or 10 kHz.
\value FMBand
The FM Band is based on the Frequency Modulation technique and can range from 87.5 to 108.0 MHz.
The step size is usually 100 kHz.
*/
/*!
\property QIfAmFmTuner::band
\brief The current band of the tuner.
*/
QIfAmFmTuner::Band QIfAmFmTuner::band() const
{
Q_D(const QIfAmFmTuner);
return d->m_band;
}
/*!
\qmlproperty AmFmTunerStation AmFmTuner::station
\brief The currently tuned station.
*/
/*!
\property QIfAmFmTuner::station
\brief The currently tuned station.
*/
QIfAmFmTunerStation QIfAmFmTuner::station() const
{
Q_D(const QIfAmFmTuner);
return d->m_station;
}
/*!
\qmlproperty bool AmFmTuner::scanRunning
\c true while a scan is in progress, \c false otherwise.
\sa startScan() stopScan() scanStarted() scanStopped()
*/
/*!
\property QIfAmFmTuner::scanRunning
\c true while a scan is in progress, \c false otherwise.
\sa startScan() stopScan() scanStarted() scanStopped()
*/
bool QIfAmFmTuner::isScanRunning() const
{
Q_D(const QIfAmFmTuner);
return d->m_scanRunning;
}
/*!
\qmlmethod AmFmTuner::tune(AmFmTunerStation station)
Tunes to the provided \a station.
*/
/*!
\fn void QIfAmFmTuner::tune(const QIfAmFmTunerStation &station)
Tunes to the provided \a station.
*/
void QIfAmFmTuner::tune(const QIfAmFmTunerStation &station)
{
Q_D(QIfAmFmTuner);
if (station.band() != d->m_band)
setBand(station.band());
if (station.frequency() != d->m_frequency)
setFrequency(station.frequency());
}
void QIfAmFmTuner::setFrequency(int frequency)
{
Q_IF_BACKEND(QIfAmFmTuner, d->tunerBackend(), "Can't set the frequency without a connected backend");
//TODO Check the minimum/maximum Frequency here ? Add a convention how things like this are done this is also used in the vehicle functions module.
backend->setFrequency(frequency);
}
void QIfAmFmTuner::setBand(QIfAmFmTuner::Band band)
{
Q_IF_BACKEND(QIfAmFmTuner, d->tunerBackend(), "Can't set the band without a connected backend");
//TODO Check the minimum/maximum Frequency here ? Add a convention how things like this are done this is also used in the vehicle functions module.
backend->setBand(band);
}
/*!
\qmlmethod AmFmTuner::stepUp()
Increases the frequency by the current bands step size.
*/
/*!
\fn void QIfAmFmTuner::stepUp()
Increases the frequency by the current bands step size.
*/
void QIfAmFmTuner::stepUp()
{
Q_IF_BACKEND(QIfAmFmTuner, d->tunerBackend(), "Can't step up without a connected backend");
//TODO Should we pass this down or use setFrequency instead ?
backend->stepUp();
}
/*!
\qmlmethod AmFmTuner::stepDown()
Decreases the frequency by the current bands step size.
*/
/*!
\fn void QIfAmFmTuner::stepDown()
Decreases the frequency by the current bands step size.
*/
void QIfAmFmTuner::stepDown()
{
Q_IF_BACKEND(QIfAmFmTuner, d->tunerBackend(), "Can't step down without a connected backend");
//TODO Should we pass this down or use setFrequency instead ?
backend->stepDown();
}
/*!
\qmlmethod AmFmTuner::seekUp()
Seeks the next available Station in upwards direction and tunes it.
If the end of the band where hit without finding a station, the search will be continued from the beginning of the band.
*/
/*!
\fn void QIfAmFmTuner::seekUp()
Seeks the next available Station in upwards direction and tunes it.
If the end of the band where hit without finding a station, the search will be continued from the beginning of the band.
*/
void QIfAmFmTuner::seekUp()
{
Q_IF_BACKEND(QIfAmFmTuner, d->tunerBackend(), "Can't seek up without a connected backend");
backend->seekUp();
}
/*!
\qmlmethod AmFmTuner::seekDown()
Seeks the next available Station in downwards direction and tunes it.
If the beginning of the band where hit without finding a station, the search will be continued from the end of the band.
*/
/*!
\fn void QIfAmFmTuner::seekDown()
Seeks the next available Station in downwards direction and tunes it.
If the beginning of the band where hit without finding a station, the search will be continued from the end of the band.
*/
void QIfAmFmTuner::seekDown()
{
Q_IF_BACKEND(QIfAmFmTuner, d->tunerBackend(), "Can't seek down without a connected backend");
backend->seekDown();
}
/*!
\qmlmethod AmFmTuner::startScan()
Starts a scan through all available stations.
The scan will seek to the next available station and will stay there for some seconds until it seeks to the next station.
\sa stopScan scanRunning scanStarted scanStopped
*/
/*!
\fn void QIfAmFmTuner::startScan()
Starts a scan through all available stations.
The scan will seek to the next available station and will stay there for some seconds until it seeks to the next station.
\sa stopScan scanRunning scanStarted scanStopped
*/
void QIfAmFmTuner::startScan()
{
Q_IF_BACKEND(QIfAmFmTuner, d->tunerBackend(), "Can't start scanning without a connected backend");
if (d->m_scanRunning) {
qWarning("A scan is already in progress");
return;
}
backend->startScan();
}
/*!
\qmlmethod AmFmTuner::stopScan()
Stops the currently active scan. If no scan is active, this method does nothing.
\sa startScan scanRunning scanStarted scanStopped
*/
/*!
\fn void QIfAmFmTuner::stopScan()
Stops the currently active scan. If no scan is active, this method does nothing.
\sa startScan scanRunning scanStarted scanStopped
*/
void QIfAmFmTuner::stopScan()
{
Q_IF_BACKEND(QIfAmFmTuner, d->tunerBackend(), "Can't stop scanning without a connected backend");
if (!d->m_scanRunning) {
qWarning("Currently no scan is active which can be stopped");
return;
}
backend->stopScan();
}
/*!
\internal
*/
QIfAmFmTuner::QIfAmFmTuner(QIfAmFmTunerPrivate &dd, QObject *parent)
: QIfAbstractFeature(dd, parent)
{
}
/*!
\reimp
*/
void QIfAmFmTuner::connectToServiceObject(QIfServiceObject *serviceObject)
{
Q_UNUSED(serviceObject);
Q_D(QIfAmFmTuner);
QIfAmFmTunerBackendInterface *backend = d->tunerBackend();
if (!backend)
return;
QObjectPrivate::connect(backend, &QIfAmFmTunerBackendInterface::frequencyChanged,
d, &QIfAmFmTunerPrivate::onFrequencyChanged);
QObjectPrivate::connect(backend, &QIfAmFmTunerBackendInterface::minimumFrequencyChanged,
d, &QIfAmFmTunerPrivate::onMinimumFrequencyChanged);
QObjectPrivate::connect(backend, &QIfAmFmTunerBackendInterface::maximumFrequencyChanged,
d, &QIfAmFmTunerPrivate::onMaximumFrequencyChanged);
QObjectPrivate::connect(backend, &QIfAmFmTunerBackendInterface::stepSizeChanged,
d, &QIfAmFmTunerPrivate::onStepSizeChanged);
QObjectPrivate::connect(backend, &QIfAmFmTunerBackendInterface::bandChanged,
d, &QIfAmFmTunerPrivate::onBandChanged);
QObjectPrivate::connect(backend, &QIfAmFmTunerBackendInterface::stationChanged,
d, &QIfAmFmTunerPrivate::onStationChanged);
QObjectPrivate::connect(backend, &QIfAmFmTunerBackendInterface::scanStatusChanged,
d, &QIfAmFmTunerPrivate::onScanStatusChanged);
QIfAbstractFeature::connectToServiceObject(serviceObject);
}
/*!
\reimp
*/
void QIfAmFmTuner::clearServiceObject()
{
Q_D(QIfAmFmTuner);
d->clearToDefaults();
}
/*!
\qmlsignal AmFmTuner::scanStarted()
A new scan has started and is now running.
\sa startScan stopScan scanRunning scanStopped
*/
/*!
\fn void QIfAmFmTuner::scanStarted()
A new scan has started and is now running.
\sa startScan stopScan scanRunning scanStopped
*/
/*!
\qmlsignal AmFmTuner::scanStopped()
The currently active scan has stopped.
\sa startScan stopScan scanRunning scanStarted
*/
/*!
\fn void QIfAmFmTuner::scanStopped()
The currently active scan has stopped.
\sa startScan stopScan scanRunning scanStarted
*/
QT_END_NAMESPACE
#include "moc_qifamfmtuner.cpp"
|