-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmainwindow.cpp
1960 lines (1705 loc) · 65.5 KB
/
mainwindow.cpp
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
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
** This file is part of the CatRadio project.
** Copyright 2022-2025 Gianfranco Sordetti IZ8EWD <iz8ewd@pianetaradio.it>.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "dialogconfig.h"
#include "dialogsetup.h"
#include "dialogvoicekeyer.h"
#include "dialogcommand.h"
#include "dialogradioinfo.h"
#include "dialognetrigctl.h"
#include "rigdaemon.h"
#include "rigdata.h"
#include "guidata.h"
#include "rigcommand.h"
#include <QDebug>
#include <QMessageBox>
#include <QThread>
#include <QString>
#include <QtGlobal>
#include <QDesktopServices>
#include <QUrl>
#include <QApplication>
#include <QCoreApplication>
#include <QDir>
#include <cwchar>
#include <rig.h> //Hamlib
//RIG *my_rig;
extern rigConnect rigCom;
extern rigSettings rigGet;
extern rigSettings rigSet;
extern rigCommand rigCmd;
extern rigCommand rigCap;
extern guiConfig guiConf;
extern guiCommand guiCmd;
extern voiceKeyerConfig voiceKConf;
int retcode; //Return code from function
int i; //Index
int prevDial; //Previous dial value
int fastDial; //Fast pushbutton state
const float fudge = 0.003;
FILE* debugFile;
QThread workerThread; //
RigDaemon *rigDaemon = new RigDaemon;
QDialog *command = nullptr;
QDialog *radioInfo = nullptr;
//***** MainWindow *****
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
//display name and version in the window title
QString version = QString::number(VERSION_MAJ)+"."+QString::number(VERSION_MIN)+"."+QString::number(VERSION_MIC);
this->setWindowTitle("CatRadio v."+version);
QDir::setCurrent(QCoreApplication::applicationDirPath()); //set current path = application path
timer = new QTimer(this); //timer for rigDaemon thread call
//* Signal and Slot connection for Slider and associated Label
connect(ui->verticalSlider_RFpower, &QAbstractSlider::valueChanged, ui->label_RFpowerValue, QOverload<int>::of(&QLabel::setNum));
connect(ui->verticalSlider_RFgain, &QAbstractSlider::valueChanged, ui->label_RFgainValue, QOverload<int>::of(&QLabel::setNum));
connect(ui->verticalSlider_AFGain, &QAbstractSlider::valueChanged, ui->label_AFGainValue, QOverload<int>::of(&QLabel::setNum));
connect(ui->verticalSlider_Squelch, &QAbstractSlider::valueChanged, ui->label_SquelchValue, QOverload<int>::of(&QLabel::setNum));
connect(ui->verticalSlider_micGain, &QAbstractSlider::valueChanged, ui->label_micGainLevel, QOverload<int>::of(&QLabel::setNum));
connect(ui->verticalSlider_micMonitor, &QAbstractSlider::valueChanged, ui->label_micMonitorLevel, QOverload<int>::of(&QLabel::setNum));
connect(ui->verticalSlider_micCompressor, &QAbstractSlider::valueChanged, ui->label_micCompressorLevel, QOverload<int>::of(&QLabel::setNum));
connect(ui->horizontalSlider_clar, &QAbstractSlider::valueChanged, ui->label_clar, QOverload<int>::of(&QLabel::setNum));
connect(ui->horizontalSlider_IFshift, &QAbstractSlider::valueChanged, ui->label_IFshiftValue,QOverload<int>::of(&QLabel::setNum));
//* Signal and Slot connection for vfoDisplay
connect(ui->lineEdit_vfoMain, &vfoDisplay::on_valueChanged, this, &MainWindow::on_vfoDisplayMainValueChanged);
connect(ui->lineEdit_vfoSub, &vfoDisplay::on_valueChanged, this, &MainWindow::on_vfoDisplaySubValueChanged);
//* Thread for RigDaemon
rigDaemon->moveToThread(&workerThread); //
connect(&workerThread, &QThread::finished, rigDaemon, &QObject::deleteLater);
connect(timer, &QTimer::timeout, this, &MainWindow::rigUpdate);
connect(rigDaemon, &RigDaemon::resultReady, this, &MainWindow::on_rigDaemonResultReady);
workerThread.start();
//* Load settings from catradio.ini
QSettings configFile(QString("catradio.ini"), QSettings::IniFormat);
rigCom.rigModel = configFile.value("rigModel", 0).toUInt();
rigCom.rigPort = configFile.value("rigPort").toString();
rigCom.serialSpeed = configFile.value("serialSpeed", 9600).toUInt();
rigCom.civAddr = configFile.value("civAddress", 0).toInt();
if (configFile.contains("serialDataBits")) //For backward compatibility with CatRadio v.< 1.4.0
{
rigCom.serialDataBits = configFile.value("serialDataBits", 8).toUInt();
rigCom.serialParity = configFile.value("serialParity", 0).toUInt();
rigCom.serialStopBits = configFile.value("serialStopBits", 2).toUInt();
rigCom.serialHandshake = configFile.value("serialHandshake", 0).toUInt();
}
rigCom.netRigctl = configFile.value("netRigctl", false).toBool();
rigCom.rigRefresh = configFile.value("rigRefresh", 100).toInt();
rigCom.fullPoll = configFile.value("fullPolling", true).toBool();
rigCom.autoConnect = configFile.value("autoConnect", false).toBool();
rigCom.autoPowerOn = configFile.value("autoPowerOn", false).toBool();
guiConf.vfoDisplayMode = configFile.value("vfoDisplayMode", 0).toInt();
guiConf.darkTheme = configFile.value("darkTheme", false).toBool();
guiConf.voiceKeyerMode = configFile.value("voiceKeyerMode", 0).toInt();
guiConf.peakHold = configFile.value("peakHold", true).toBool();
guiConf.debugMode = configFile.value("debugMode", false).toBool();
//Window settings
restoreGeometry(configFile.value("WindowSettings/geometry").toByteArray());
restoreState(configFile.value("WindowSettings/state").toByteArray());
//Voice memory
if (guiConf.voiceKeyerMode == 1)
{
ui->action_Voice_Keyer->setEnabled(true); //enable Voice Keyer menu
audioOutputInit(configFile.fileName()); //init audio
}
//* Debug
if (guiConf.debugMode) rig_set_debug_level(RIG_DEBUG_VERBOSE); //debug verbose
else rig_set_debug_level(RIG_DEBUG_WARN); //normal
//rig_set_debug_level(RIG_DEBUG_VERBOSE); //debug verbose
//rig_set_debug_level(RIG_DEBUG_TRACE); //debug trace
rig_set_debug_time_stamp(true);
if ((debugFile=fopen("catradio.log","w+")) == NULL) rig_set_debug_level(RIG_DEBUG_NONE);
else rig_set_debug_file(debugFile);
//* Style
//ui->pushButton_PTT->setStyleSheet("QPushButton::checked {font: bold; color: red;}");
//Dark theme
if (guiConf.darkTheme)
{
//QFile darkStyleFile(":/dark/stylesheet.qss");
QFile darkStyleFile(":qdarkstyle/dark/darkstyle.qss");
if (!darkStyleFile.exists()) ui->statusbar->showMessage("Unable to set stylesheet, file not found!");
else
{
darkStyleFile.open(QFile::ReadOnly | QFile::Text);
QTextStream ts(&darkStyleFile);
qApp->setStyleSheet(ts.readAll());
ui->progressBar_Smeter->setBgColor(Qt::black);
ui->progressBar_Smeter->setScaleColor(Qt::white);
ui->progressBar_Smeter->setLineColor(Qt::white);
ui->progressBar_Smeter->setProgressColor(QColor(0x66, 0x8f, 0xb8));
ui->progressBar_subMeter->setBgColor(Qt::black);
ui->progressBar_subMeter->setScaleColor(Qt::white);
ui->progressBar_subMeter->setLineColor(Qt::white);
ui->progressBar_subMeter->setProgressColor(QColor(0x66, 0x8f, 0xb8));
ui->lineEdit_vfoMain->setBgColor(Qt::black);
ui->lineEdit_vfoMain->setLineColor(Qt::white);
ui->lineEdit_vfoMain->setTextColor(Qt::white);
ui->lineEdit_vfoSub->setBgColor(Qt::black);
ui->lineEdit_vfoSub->setLineColor(Qt::white);
ui->lineEdit_vfoSub->setTextColor(Qt::white);
}
}
//Light QFile darkStyleFile(":qdarkstyle/light/lightstyle.qss");
QApplication::setWheelScrollLines(10); //Mouse wheel scroll step
//* Init
//Meter
ui->progressBar_Smeter->setTx(false);
ui->progressBar_Smeter->setMaxValue(100);
ui->progressBar_Smeter->setGateValue(80);
ui->progressBar_Smeter->setValue(-54);
ui->progressBar_Smeter->resetPeakValue();
ui->progressBar_Smeter->setPeakFactor(rigCom.rigRefresh/1000.0);
ui->progressBar_subMeter->resetPeakValue();
ui->progressBar_subMeter->setPeakFactor(rigCom.rigRefresh/1000.0);
//VFO
ui->lineEdit_vfoMain->setValue(0);
ui->lineEdit_vfoSub->setValue(0);
//Check Hamlib version
if (!checkHamlibVersion(4, 6, 0))
{
QMessageBox msgBox;
msgBox.setWindowTitle("Hamlib");
msgBox.setText("Please, update Hamlib libraries to version 4.6 or higher.");
msgBox.setIcon(QMessageBox::Warning);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
}
//Auto connect
if (rigCom.autoConnect) ui->pushButton_Connect->toggle();
}
MainWindow::~MainWindow()
{
workerThread.quit(); //
workerThread.wait();
if (rigCom.connected)
{
timer->stop();
rigCom.connected = 0;
rig_close(my_rig); //Close the communication to the rig
}
rig_cleanup(my_rig); //Release rig handle and free associated memory
fclose(debugFile); //Close debug.log
//* Save window settings
QSettings configFile(QString("catradio.ini"), QSettings::IniFormat);
configFile.setValue("WindowSettings/geometry", saveGeometry());
configFile.setValue("WindowSettings/state", saveState());
delete ui;
}
//***** GUI function *****
void MainWindow::guiInit()
{
//* Power on/off cap
if (rig_has_set_func(my_rig, RIG_FUNCTION_SET_POWERSTAT)==0)
//if (my_rig->caps->set_powerstat == NULL)
{
ui->pushButton_Power->setDisabled(true); //Power pushbutton disabled
rigCap.onoff = 0;
}
else
{
ui->pushButton_Power->setDisabled(false);
rigCap.onoff = 1;
}
//* PTT cap
if (rig_has_set_func(my_rig, RIG_FUNCTION_SET_PTT)==0)
//if (my_rig->caps->set_ptt == NULL)
{
ui->pushButton_PTT->setDisabled(true); //PTT pushbutton disabled
rigCap.ptt = 0;
}
else
{
ui->pushButton_PTT->setDisabled(false);
rigCap.ptt = 1;
}
//* Band select cap
if (rig_has_set_level(my_rig, RIG_LEVEL_BAND_SELECT)) rigCap.bandChange = 1;
else rigCap.bandChange = 0;
//* Mode combobox
if (my_rig->state.mode_list == RIG_MODE_NONE)
{
ui->comboBox_Mode->setDisabled(true);
ui->comboBox_ModeSub->setDisabled(true);
}
else
{
ui->comboBox_Mode->clear(); //Clear old contents
ui->comboBox_ModeSub->clear();
for (i=0; i<HAMLIB_MAX_MODES; i++)
{
if (my_rig->state.mode_list & (1ULL << i))
{
ui->comboBox_Mode->addItem(rig_strrmode(my_rig->state.mode_list & (1ULL << i)));
ui->comboBox_ModeSub->addItem(rig_strrmode(my_rig->state.mode_list & (1ULL << i)));
}
}
ui->comboBox_ModeSub->addItem(rig_strrmode(RIG_MODE_NONE)); //add None mode in the modeSub list, used in case mode sub vfo is not targetable
guiCmd.bwidthList = 1; //Command to populate BW combobox in guiUpdate()
}
//* ANT comboBox
ui->comboBox_Ant->clear();
if (!rig_has_set_func(my_rig, RIG_FUNCTION_SET_ANT)) ui->comboBox_Ant->setEnabled(false);
//* AGC level comboBox
ui->comboBox_AGC->clear();
if (!rig_has_set_level(my_rig, RIG_LEVEL_AGC)) ui->comboBox_AGC->setEnabled(false);
else
{
for (i = 0; i < HAMLIB_MAX_AGC_LEVELS && i < my_rig->state.agc_level_count; i++) ui->comboBox_AGC->addItem(rig_stragclevel(my_rig->state.agc_levels[i]));
if (i==0) //Print all levels if list is not specified
{
ui->comboBox_AGC->addItem(rig_stragclevel(RIG_AGC_OFF));
ui->comboBox_AGC->addItem(rig_stragclevel(RIG_AGC_AUTO));
ui->comboBox_AGC->addItem(rig_stragclevel(RIG_AGC_FAST));
ui->comboBox_AGC->addItem(rig_stragclevel(RIG_AGC_MEDIUM));
ui->comboBox_AGC->addItem(rig_stragclevel(RIG_AGC_SLOW));
}
}
//* Meters & Sub-meter comboBox
//ui->progressBar_Smeter->setMaxValue(5); //FIXME tx_range_list
ui->progressBar_Smeter->setPeak(guiConf.peakHold);
ui->progressBar_subMeter->setPeak(guiConf.peakHold);
ui->comboBox_Meter->clear();
if (rig_has_get_level(my_rig, RIG_METER_SWR)) ui->comboBox_Meter->addItem("SWR");
if (rig_has_get_level(my_rig, RIG_METER_ALC)) ui->comboBox_Meter->addItem("ALC");
if (rig_has_get_level(my_rig, RIG_METER_COMP)) ui->comboBox_Meter->addItem("COMP");
if (rig_has_get_level(my_rig, RIG_METER_IC)) ui->comboBox_Meter->addItem("ID");
if (rig_has_get_level(my_rig, RIG_METER_VDD)) ui->comboBox_Meter->addItem("VDD");
rigSet.meter = levelmeterstr (ui->comboBox_Meter->currentText());
setSubMeter();
ui->label_hiSWR->setVisible(false);
//* Attenuator comboBox
ui->comboBox_Att->clear();
if (!rig_has_set_level(my_rig, RIG_LEVEL_ATT)) ui->comboBox_Att->setEnabled(false);
ui->comboBox_Att->addItem("0");
for (i = 0; i < HAMLIB_MAXDBLSTSIZ && my_rig->state.attenuator[i] != 0; i++)
{
ui->comboBox_Att->addItem(QString::number(my_rig->state.attenuator[i]));
}
//* Preamp comboBox
ui->comboBox_Preamp->clear();
if (!rig_has_set_level(my_rig, RIG_LEVEL_PREAMP)) ui->comboBox_Preamp->setEnabled(false);
ui->comboBox_Preamp->addItem("0");
for (i = 0; i < HAMLIB_MAXDBLSTSIZ && my_rig->state.preamp[i] != 0; i++)
{
ui->comboBox_Preamp->addItem(QString::number(my_rig->state.preamp[i]));
}
//* Levels
if (!rig_has_set_level(my_rig, RIG_LEVEL_RFPOWER)) ui->verticalSlider_RFpower->setEnabled(false);
if (!rig_has_set_level(my_rig, RIG_LEVEL_RF)) ui->verticalSlider_RFgain->setEnabled(false);
if (!rig_has_set_level(my_rig, RIG_LEVEL_AF)) ui->verticalSlider_AFGain->setEnabled(false);
if (!rig_has_set_level(my_rig, RIG_LEVEL_SQL)) ui->verticalSlider_Squelch->setEnabled(false);
if (!rig_has_set_level(my_rig, RIG_LEVEL_MICGAIN)) ui->verticalSlider_micGain->setEnabled(false);
if (!rig_has_set_level(my_rig, RIG_LEVEL_MONITOR_GAIN)) ui->verticalSlider_micMonitor->setEnabled(false);
if (!rig_has_set_level(my_rig, RIG_LEVEL_COMP)) ui->verticalSlider_micCompressor->setEnabled(false);
if (!rig_has_set_func(my_rig, RIG_FUNC_COMP)) ui->checkBox_micCompressor->setEnabled(false);
if (!rig_has_set_func(my_rig, RIG_FUNC_MON)) ui->checkBox_micMonitor->setEnabled(false);
//* Filter
if (!rig_has_set_func(my_rig, RIG_FUNC_NB)) ui->checkBox_NB->setEnabled(false);
if (!rig_has_set_func(my_rig, RIG_FUNC_NB2)) ui->checkBox_NB2->setEnabled(false);
if (!rig_has_set_func(my_rig, RIG_FUNC_ANF)) ui->checkBox_NF->setEnabled(false);
if (rig_has_set_func(my_rig, RIG_FUNC_NR))
{
int max, min, step;
for (i = 0; i < RIG_SETTING_MAX; i++)
{
//qDebug()<<i<<rig_idx2setting(i)<<rig_strparm(rig_idx2setting(i));
if (RIG_LEVEL_NR & rig_idx2setting(i)) break;
}
//qDebug()<<rig_strparm(RIG_LEVEL_NR & rig_idx2setting(i));
//qDebug()<<i;
if (RIG_LEVEL_IS_FLOAT(rig_idx2setting(i))) //float 0..1
{
float stepf = 1/my_rig->state.level_gran[i].step.f;
max = (int)(my_rig->state.level_gran[i].max.f*stepf+fudge);
step = (int)(stepf+fudge);
min = max-step+1;
step = max/step;
}
else //integer
{
step = my_rig->state.level_gran[i].step.i;
max = my_rig->state.level_gran[i].max.i;
min = my_rig->state.level_gran[i].min.i;
}
//qDebug()<<max<<min<<step;
ui->spinBox_NR->setMaximum(max);
ui->spinBox_NR->setMinimum(min);
ui->spinBox_NR->setSingleStep(step);
}
else
{
ui->checkBox_NR->setEnabled(false);
ui->spinBox_NR->setEnabled(false);
}
//* Clarifier
rigSet.rit = 1;
if (!rig_has_set_func(my_rig, RIG_FUNC_XIT)) ui->radioButton_clarXIT->setEnabled(false);
//* CW
if (!rig_has_set_func(my_rig, RIG_FUNC_FBKIN)) ui->checkBox_BKIN->setEnabled(false);
if (!rig_has_set_func(my_rig, RIG_FUNC_APF)) ui->checkBox_APF->setEnabled(false);
if (!rig_has_set_level(my_rig, RIG_LEVEL_KEYSPD)) ui->spinBox_WPM->setEnabled(false);
//* FM
ui->comboBox_toneType->clear();
ui->comboBox_toneType->addItem(""); //None
if (rig_has_set_func(my_rig, RIG_FUNC_TBURST)) ui->comboBox_toneType->addItem("1750Hz"); //Burst 1750 Hz
if (rig_has_set_func(my_rig, RIG_FUNC_TONE)) ui->comboBox_toneType->addItem("TONE"); //CTCSS Tx
if (rig_has_set_func(my_rig, RIG_FUNC_TSQL)) ui->comboBox_toneType->addItem("TSQL"); //CTCSS Tx + Rx squelch
if (rig_has_set_func(my_rig, RIG_FUNC_CSQL)) ui->comboBox_toneType->addItem("DCS"); //DCS
//* VFO
ui->lineEdit_vfoMain->setMode(guiConf.vfoDisplayMode);
ui->lineEdit_vfoSub->setMode(guiConf.vfoDisplayMode);
//check for targetable sub VFO
//if (my_rig->caps->rig_model != 2) //Hamlib 4.4 has bug for rigctld and targetable_vfo, skip check
//{
if (my_rig->caps->targetable_vfo & RIG_TARGETABLE_FREQ) rigCap.freqSub = 1; //targetable frequency
else rigCap.freqSub = 0;
if (my_rig->caps->targetable_vfo & RIG_TARGETABLE_MODE) rigCap.modeSub = 1; //targetable mode
else rigCap.modeSub = 0;
if (my_rig->caps->targetable_vfo == RIG_TARGETABLE_NONE)
{
rigCap.freqSub = 0; //disable get/set freq for subVFO
rigCap.modeSub = 0; //disable get/set mode for subVFO
ui->radioButton_VFOSub->setCheckable(false); //disable VFOsub radio button
}
//}
//else //NET rigctl, as workaround assume targetable_vfo
//{
// rigCap.freqSub = 1;
// rigCap.modeSub = 1;
//}
//* Menu
ui->action_Command->setEnabled(true);
ui->action_RadioInfo->setEnabled(true);
guiCmd.rangeList = 1; //update range list
guiCmd.antList = 1; //update antenna list
guiCmd.toneList = 1; //update tone list
guiCmd.tabList = 1; //select tab
}
void MainWindow::audioOutputInit(QString configFileName)
{
//Set audio file names associated to keyer memory buttons
QSettings configFile(configFileName, QSettings::IniFormat);
voiceKConf.memoryFile[0] = configFile.value("VoiceKeyer/voiceMemoryFile1", "").toString();
voiceKConf.memoryFile[1] = configFile.value("VoiceKeyer/voiceMemoryFile2", "").toString();
voiceKConf.memoryFile[2] = configFile.value("VoiceKeyer/voiceMemoryFile3", "").toString();
voiceKConf.memoryFile[3] = configFile.value("VoiceKeyer/voiceMemoryFile4", "").toString();
voiceKConf.memoryFile[4] = configFile.value("VoiceKeyer/voiceMemoryFile5", "").toString();
voiceKConf.audioOutput = configFile.value("VoiceKeyer/audioOutput").toString();
voiceKConf.audioOutputVolume = configFile.value("VoiceKeyer/audioOutputVolume", 10).toInt();
audioPlayer = new QMediaPlayer(this);
//Connect signal playback state change with slot on_voiceKeyerStateChanged function
connect(audioPlayer, &QMediaPlayer::mediaStatusChanged, this, &MainWindow::on_voiceKeyerStateChanged);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
audioOutput = new QAudioOutput(this);
//Select audio output device
//QAudioDevice audioDevice = configFile.value("VoiceKeyer/audioOutput", QAudioDevice::Null).value<QAudioDevice>(); //Do not work
QAudioDevice audioDevice = QMediaDevices::defaultAudioOutput(); //Select default audio output device as first attempt
//Search in the system audio output devices for a device with the selected name
audioDevices = new QMediaDevices(this);
const QList<QAudioDevice> devices = audioDevices->audioOutputs();
for (const QAudioDevice &deviceInfo : devices)
if (voiceKConf.audioOutput == deviceInfo.description()) audioDevice = deviceInfo;
audioOutput->setDevice(audioDevice);
audioPlayer->setAudioOutput(audioOutput);
//Set output volume
audioOutput->setVolume((float)(voiceKConf.audioOutputVolume/10)); //Float 0 min - 1 max
#else
/* QT5 QMediaPlayer, is not possible to play sound other than the default audio device
* possible solution using obsolete class QAudioOutputSelectorControl or play sound with QAudioOutput
for (QAudioDeviceInfo &deviceInfo: QAudioDeviceInfo::availableDevices(QAudio::AudioOutput))
if (voiceKConf.audioOutput == deviceInfo.deviceName())
{
m_audioOutput.reset(new QAudioOutput(deviceInfo, deviceInfo.preferredFormat()));
audioDeviceInfo = deviceInfo;
qDebug() << audioDeviceInfo.deviceName();
}
*/
audioPlayer->setVolume((int)(voiceKConf.audioOutputVolume*10)); //Int 0 min - 100 max
#endif
}
void MainWindow::guiUpdate()
{
//* Power button
if (rigGet.onoff == RIG_POWER_ON)
{
ui->pushButton_Power->setChecked(true);
//ui->pushButton_Power->setStyleSheet("QPushButton {color: limegreen;}");
}
else if (rigGet.onoff == RIG_POWER_OFF)
{
if(timer->isActive())
{
timer->stop();
ui->pushButton_Power->setChecked(false);
//ui->pushButton_Power->setStyleSheet("");
//Reset Smeter
rigGet.sMeter.i = -54;
ui->progressBar_Smeter->resetPeakValue();
//Reset VFOs
rigGet.freqMain = 0;
rigGet.freqSub = 0;
ui->statusbar->showMessage("Radio off");
}
}
//* VFOs
if (!rigCmd.freqMain) ui->lineEdit_vfoMain->setValue(rigGet.freqMain);
if (!rigCmd.freqSub) ui->lineEdit_vfoSub->setValue(rigGet.freqSub);
ui->label_vfoMain->setText(rig_strvfo(rigGet.vfoMain));
switch (rigGet.vfoMain)
{
case RIG_VFO_A: rigGet.vfoSub = RIG_VFO_B; break;
case RIG_VFO_B: rigGet.vfoSub = RIG_VFO_A; break;
case RIG_VFO_MAIN: rigGet.vfoSub = RIG_VFO_SUB; break;
case RIG_VFO_SUB: rigGet.vfoSub = RIG_VFO_MAIN; break;
}
ui->label_vfoSub->setText(rig_strvfo(rigGet.vfoSub));
//* Mode
if (!rigCmd.mode) ui->comboBox_Mode->setCurrentText(rig_strrmode(rigGet.mode));
if (!rigCmd.modeSub) ui->comboBox_ModeSub->setCurrentText(rig_strrmode(rigGet.modeSub));
if (guiCmd.tabList) //Select appropriate mode function tab
{
if (rigGet.mode == RIG_MODE_SSB || rigGet.mode == RIG_MODE_USB || rigGet.mode == RIG_MODE_LSB) ui->tabWidget->setCurrentIndex(0); //Clarifier tab
if (rigGet.mode == RIG_MODE_CW || rigGet.mode == RIG_MODE_CWR || rigGet.mode == RIG_MODE_CWN) ui->tabWidget->setCurrentIndex(1); //CW tab
if (rigGet.mode == RIG_MODE_FM || rigGet.mode == RIG_MODE_FMN || rigGet.mode == RIG_MODE_PKTFM || rigGet.mode == RIG_MODE_PKTFMN || rigGet.mode == RIG_MODE_C4FM || rigGet.mode == RIG_MODE_DSTAR) ui->tabWidget->setCurrentIndex(2); //FM tab
guiCmd.tabList = 0;
}
//* BW combobox
if (guiCmd.bwidthList)
{
ui->comboBox_BW->clear();
filter_list bwidth_list; //IF filter bandwidth per mode
for (i=0; i<HAMLIB_FLTLSTSIZ && !RIG_IS_FLT_END(my_rig->state.filters[i]); i++)
{
char modeslist[1000] = "";
QString modes, mode;
bwidth_list = my_rig->state.filters[i];
rig_strrmodes(bwidth_list.modes, modeslist, sizeof(modeslist));
modes = modeslist;
modes.append(" ");
mode = rig_strrmode(rigGet.mode);
if (mode != "")
{
int j = 0;
//qDebug() << modes << mode << bwidth_list.width;
QRegularExpression rx("\\b"+mode+"?\\s");
if (modes.contains (rx) && bwidth_list.width != RIG_FLT_ANY)
{ //sort the BW list
if (ui->comboBox_BW->count() == 0) ui->comboBox_BW->addItem(QString::number(bwidth_list.width)); //first line
else while (j <= ui->comboBox_BW->count()) //sort descending by filter width
{
ui->comboBox_BW->setCurrentIndex(j);
QString bwidthCurrent = ui->comboBox_BW->currentText();
if (bwidth_list.width > bwidthCurrent.toLong())
{
ui->comboBox_BW->insertItem(j, QString::number(bwidth_list.width));
break;
}
else j++;
}
}
}
//else qDebug() << "vuoto" << rigGet.mode;
}
//ui->comboBox_BW->model()->sort(0, Qt::DescendingOrder);
guiCmd.bwidthList = 0;
}
if (!rigCmd.bwidth) ui->comboBox_BW->setCurrentText(QString::number(rigGet.bwidth));
ui->checkBox_NAR->setChecked(rigGet.bwNarrow);
//* Range list
if (guiCmd.rangeList)
{
for (i=0; i<HAMLIB_FRQRANGESIZ; i++) //Tx range list
{
//qDebug()<<rigGet.freqMain<<my_rig->state.tx_range_list[i].startf<<my_rig->state.tx_range_list[i].endf;
if (rigGet.freqMain >= my_rig->state.tx_range_list[i].startf && rigGet.freqMain <= my_rig->state.tx_range_list[i].endf) break;
}
rigGet.rangeListTxIndex = i;
for (i=0; i<HAMLIB_FRQRANGESIZ; i++) //Rx range list
{
if (rigGet.freqMain >= my_rig->state.rx_range_list[i].startf && rigGet.freqMain <= my_rig->state.rx_range_list[i].endf) break;
}
if (rigGet.rangeListRxIndex != i) guiCmd.antList = 1;
rigGet.rangeListRxIndex = i;
guiCmd.rangeList = 0;
}
//* Antenna list
if (guiCmd.antList)
{
ui->comboBox_Ant->clear();
if (!rig_has_get_func(my_rig, RIG_FUNCTION_GET_ANT)) ui->comboBox_Ant->addItem("");
else if (my_rig->state.tx_range_list[rigGet.rangeListRxIndex].ant == RIG_ANT_NONE) ui->comboBox_Ant->addItem("NONE"); //RIG_ANT_NONE
else for (i=0; i < RIG_ANT_MAX; i++)
{
if (my_rig->state.tx_range_list[rigGet.rangeListRxIndex].ant & (1UL << i))
{
switch (i)
{
case 0: ui->comboBox_Ant->addItem("ANT1"); break; //RIG_ANT_1
case 1: ui->comboBox_Ant->addItem("ANT2"); break; //RIG_ANT_2
case 2: ui->comboBox_Ant->addItem("ANT3"); break; //RIG_ANT_3
case 3: ui->comboBox_Ant->addItem("ANT4"); break; //RIG_ANT_4
case 4: ui->comboBox_Ant->addItem("ANT5"); break; //RIG_ANT_5
case 30: ui->comboBox_Ant->addItem("UNK"); break; //RIG_ANT_UNKNOWN
case 31: ui->comboBox_Ant->addItem("CURR"); break; //RIG_ANT_CURR
default: ui->comboBox_Ant->addItem(""); break;
}
}
}
guiCmd.antList = 0;
}
//* Tone list
if (guiCmd.toneList)
{
ui->comboBox_toneFreq->clear();
if (rigGet.toneType == 2 || rigGet.toneType == 3)
{
for (i = 0; i < CTCSS_LIST_SIZE; i++) //CTCSS tone
{
if (my_rig->caps->ctcss_list[i] == 0) break;
ui->comboBox_toneFreq->addItem(QString::number(my_rig->caps->ctcss_list[i]/10.0,'f',1));
}
}
if (rigGet.toneType == 4)
{
for (i = 0; i < DCS_LIST_SIZE; i++) //DCS code
{
if (my_rig->caps->dcs_list[i] == 0) break;
ui->comboBox_toneFreq->addItem(QString::number(my_rig->caps->dcs_list[i]));
}
}
guiCmd.toneList = 0;
}
//* RF
if (!rigCmd.tuner) ui->radioButton_Tuner->setChecked(rigGet.tuner);
if (!rigCmd.agc) ui->comboBox_AGC->setCurrentText(rig_stragclevel(rigGet.agc));
if (!rigCmd.att) ui->comboBox_Att->setCurrentText(QString::number(rigGet.att));
if (!rigCmd.pre) ui->comboBox_Preamp->setCurrentText(QString::number(rigGet.pre));
//* Split
if (rigGet.split == RIG_SPLIT_ON)
{
ui->pushButton_Split->setChecked(true);
if (rigGet.vfoSub == rigGet.vfoTx)
{
ui->label_vfoMainRxTx->setText("RX");
ui->label_vfoSubRxTx->setText("TX");
}
else
{
ui->label_vfoMainRxTx->setText("TX");
ui->label_vfoSubRxTx->setText("RX");
}
}
else
{
ui->pushButton_Split->setChecked(false);
ui->label_vfoMainRxTx->setText("RX TX");
ui->label_vfoSubRxTx->setText("");
}
//* PTT & Meter
if (rigGet.ptt == RIG_PTT_ON)
{
//ui->pushButton_PTT->setChecked(true);
if (rigGet.vfoTx == rigGet.vfoSub) ui->label_vfoSub->setStyleSheet("QLabel {background-color: red}");
else ui->label_vfoMain->setStyleSheet("QLabel {background-color: red}");
//Smeter and subMeter
if (!ui->progressBar_Smeter->getTx())
{
ui->progressBar_Smeter->setTx(true);
ui->progressBar_Smeter->setValue(0);
ui->progressBar_Smeter->resetPeakValue();
}
ui->progressBar_Smeter->setValue(rigGet.powerMeter.f*100);
ui->progressBar_subMeter->setValue(rigGet.subMeter.f);
if (rigGet.hiSWR.f > 2) ui->label_hiSWR->setVisible(true);
//Voice keyer
if (guiConf.voiceKeyerMode == 1 && rigCmd.voiceSend) audioPlayer->play();
}
else //RIG_PTT_OFF
{
//ui->pushButton_PTT->setChecked(false);
if (rigGet.vfoTx == rigGet.vfoSub) ui->label_vfoSub->setStyleSheet("QLabel {}");
else ui->label_vfoMain->setStyleSheet("QLabel {}");
if (ui->progressBar_Smeter->getTx())
{
ui->progressBar_Smeter->setTx(false);
ui->progressBar_Smeter->setValue(-54);
ui->progressBar_Smeter->resetPeakValue();
ui->label_hiSWR->setVisible(false);
//if (rigSet.meter == RIG_LEVEL_SWR) ui->progressBar_subMeter->setValue(1.0);
//else ui->progressBar_subMeter->setValue(0.0);
//ui->progressBar_subMeter->resetPeakValue();
}
ui->progressBar_Smeter->setValue(rigGet.sMeter.i);
if (rigSet.meter == RIG_LEVEL_SWR) ui->progressBar_subMeter->setValue(1.0);
else ui->progressBar_subMeter->setValue(0.0);
}
//* Levels
if (!ui->verticalSlider_RFpower->isSliderDown() && !rigCmd.rfPower) ui->verticalSlider_RFpower->setValue((int)(rigGet.rfPower*100+fudge));
if (!ui->verticalSlider_RFgain->isSliderDown() && !rigCmd.rfGain) ui->verticalSlider_RFgain->setValue((int)(rigGet.rfGain*100+fudge));
if (!ui->verticalSlider_AFGain->isSliderDown() && !rigCmd.afGain) ui->verticalSlider_AFGain->setValue((int)(rigGet.afGain*100+fudge));
if (!ui->verticalSlider_Squelch->isSliderDown() && !rigCmd.squelch) ui->verticalSlider_Squelch->setValue((int)(rigGet.squelch*100+fudge));
//* MIC
if (!ui->verticalSlider_micGain->isSliderDown() && !rigCmd.micGain) ui->verticalSlider_micGain->setValue((int)(rigGet.micGain*100+fudge));
if (!ui->verticalSlider_micMonitor->isSliderDown() && !rigCmd.micMonLevel) ui->verticalSlider_micMonitor->setValue((int)(rigGet.micMonLevel*100+fudge));
if (!ui->verticalSlider_micCompressor->isSliderDown() && !rigCmd.micCompLevel) ui->verticalSlider_micCompressor->setValue((int)(rigGet.micCompLevel*100+fudge));
if (!rigCmd.micComp) ui->checkBox_micCompressor->setChecked(rigGet.micComp);
if (!rigCmd.micMon) ui->checkBox_micMonitor->setChecked(rigGet.micMon);
//* Filter
if (!rigCmd.noiseBlanker) ui->checkBox_NB->setChecked(rigGet.noiseBlanker);
if (!rigCmd.noiseBlanker2) ui->checkBox_NB2->setChecked(rigGet.noiseBlanker2);
if (!rigCmd.noiseReduction) ui->checkBox_NR->setChecked(rigGet.noiseReduction);
if (!rigCmd.noiseReductionLevel) ui->spinBox_NR->setValue((int)(rigGet.noiseReductionLevel*ui->spinBox_NR->maximum()+fudge));
if (!rigCmd.notchFilter) ui->checkBox_NF->setChecked(rigGet.notchFilter);
if (!ui->horizontalSlider_IFshift->isSliderDown() && !rigCmd.ifShift) ui->horizontalSlider_IFshift->setValue(rigGet.ifShift);
//* Clarifier
if (!rigCmd.clar) ui->checkBox_clar->setChecked(rigGet.clar);
if (rigSet.xit)
{
ui->radioButton_clarXIT->setChecked(true);
if (!ui->horizontalSlider_clar->isSliderDown() && !rigCmd.clar) ui->horizontalSlider_clar->setValue(rigGet.xitOffset);
}
else //rigSet.rit
{
ui->radioButton_clarRIT->setChecked(true);
if (!ui->horizontalSlider_clar->isSliderDown() && !rigCmd.clar) ui->horizontalSlider_clar->setValue(rigGet.ritOffset);
}
//* CW
if (!rigCmd.bkin) ui->checkBox_BKIN->setChecked(rigGet.bkin);
if (!rigCmd.apf) ui->checkBox_APF->setChecked(rigGet.apf);
if (!rigCmd.wpm) ui->spinBox_WPM->setValue(rigGet.wpm);
//* FM
if (rigGet.rptShift == RIG_RPT_SHIFT_MINUS && !rigCmd.rptShift) ui->radioButton_RPTshiftMinus->setChecked(true); //-
else if (rigGet.rptShift == RIG_RPT_SHIFT_PLUS && !rigCmd.rptShift) ui->radioButton_RPTshiftPlus->setChecked(true); //+
else ui->radioButton_RPTshiftSimplex->setChecked(true); //Simplex
if (!rigCmd.rptOffset) ui->spinBox_RPToffset->setValue(rigGet.rptOffset/1000); //Offset (kHz)
switch (rigGet.toneType)
{
case (1): ui->comboBox_toneType->setCurrentText("1750Hz"); break;
case (2): ui->comboBox_toneType->setCurrentText("TONE"); break;
case (3): ui->comboBox_toneType->setCurrentText("TSQL"); break;
case (4): ui->comboBox_toneType->setCurrentText("DCS"); break;
default: ui->comboBox_toneType->setCurrentText(""); break;
}
if (rigGet.toneType == 2 || rigGet.toneType == 3) ui->comboBox_toneFreq->setCurrentText(QString::number(rigGet.tone/10.0)); //CTCSS
else if (rigGet.toneType == 4) ui->comboBox_toneFreq->setCurrentText(QString::number(rigGet.tone)); //DCS
}
void MainWindow::rigUpdate()
{
rigDaemon->rigUpdate(my_rig);
}
//* RigDaemon handle results
void MainWindow::on_rigDaemonResultReady()
{
guiUpdate();
}
//* SubMeter
void MainWindow::setSubMeter()
{
if (rigSet.meter == RIG_LEVEL_SWR)
{
ui->progressBar_subMeter->setMeterSWR(true);
ui->progressBar_subMeter->setMaxValue(4.0);
ui->progressBar_subMeter->setGateValue(2.0);
ui->progressBar_subMeter->setLongStep(0.5);
ui->progressBar_subMeter->setShortStep(0.1);
ui->progressBar_subMeter->setValue(1.0);
}
else if (rigSet.meter == RIG_LEVEL_ID_METER)
{
ui->progressBar_subMeter->setMeterSWR(false);
ui->progressBar_subMeter->setMaxValue(25.0);
ui->progressBar_subMeter->setMinValue(0.0);
ui->progressBar_subMeter->setGateValue(10.0);
ui->progressBar_subMeter->setPrecision(0);
ui->progressBar_subMeter->setLongStep(5.0);
ui->progressBar_subMeter->setShortStep(1.0);
ui->progressBar_subMeter->setValue(0);
}
else if (rigSet.meter == RIG_LEVEL_VD_METER)
{
ui->progressBar_subMeter->setMeterSWR(false);
ui->progressBar_subMeter->setMaxValue(15.0);
ui->progressBar_subMeter->setMinValue(0.0);
ui->progressBar_subMeter->setGateValue(13.8);
ui->progressBar_subMeter->setPrecision(1);
ui->progressBar_subMeter->setLongStep(5.0);
ui->progressBar_subMeter->setShortStep(1.0);
ui->progressBar_subMeter->setValue(0);
}
else if (rigSet.meter == RIG_LEVEL_COMP_METER)
{
ui->progressBar_subMeter->setMeterSWR(false);
ui->progressBar_subMeter->setMaxValue(20.0);
ui->progressBar_subMeter->setMinValue(0.0);
ui->progressBar_subMeter->setGateValue(15.0);
ui->progressBar_subMeter->setPrecision(0);
ui->progressBar_subMeter->setLongStep(5.0);
ui->progressBar_subMeter->setShortStep(1.0);
ui->progressBar_subMeter->setValue(0);
}
else
{
ui->progressBar_subMeter->setMeterSWR(false);
ui->progressBar_subMeter->setMaxValue(1.0);
ui->progressBar_subMeter->setMinValue(0.0);
ui->progressBar_subMeter->setGateValue(0.5);
ui->progressBar_subMeter->setPrecision(1);
ui->progressBar_subMeter->setLongStep(0.5);
ui->progressBar_subMeter->setShortStep(0.1);
ui->progressBar_subMeter->setValue(0);
}
ui->progressBar_subMeter->resetPeakValue();
}
void MainWindow::on_voiceKeyerStateChanged()
{
//qDebug() << audioPlayer->mediaStatus() << rigCmd.voiceSend << rigGet.ptt;
if (rigCmd.voiceSend >= 1)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
if (audioPlayer->mediaStatus() == QMediaPlayer::LoadedMedia && audioPlayer->source() == QUrl::fromLocalFile(voiceKConf.memoryFile[rigCmd.voiceSend - 1])) //LoadedMedia
#else
if (audioPlayer->mediaStatus() == QMediaPlayer::LoadedMedia && audioPlayer->media() == QUrl::fromLocalFile(voiceKConf.memoryFile[rigCmd.voiceSend - 1]))
#endif
{
ui->pushButton_PTT->toggle();
ui->statusbar->showMessage("Playing audio...");
}
else if (audioPlayer->mediaStatus() == QMediaPlayer::NoMedia || audioPlayer->mediaStatus() == QMediaPlayer::InvalidMedia) //NoMedia or InvalidMedia
{
rigCmd.voiceSend = 0;
ui->statusbar->showMessage("Audio file error!", 5000);
}
else if (audioPlayer->mediaStatus() == QMediaPlayer::EndOfMedia && rigGet.ptt) //EndOfMedia
{
rigCmd.voiceSend = 0;
ui->pushButton_PTT->toggle();
ui->statusbar->clearMessage();
}
}
}
bool MainWindow::checkHamlibVersion(int major, int minor, int revision)
{
QString hamlibVer = rig_version();
QRegularExpression hamlibVerExp("(?P<major>\\d)\\.(?P<minor>\\d)\\.?(?P<revision>\\d)?");
QRegularExpressionMatch hamlibVerMatch = hamlibVerExp.match(hamlibVer);
if (hamlibVerMatch.hasMatch())
{
int majorVer = hamlibVerMatch.captured("major").toInt();
int minorVer = hamlibVerMatch.captured("minor").toInt();
int revisionVer = hamlibVerMatch.captured("revision").toInt();
//qDebug()<<majorVer<<minorVer<<revisionVer;
if (majorVer > major) return true;
else if (majorVer < major) return false;
else if (minorVer > minor) return true; //& majorVer=major
else if (minorVer < minor) return false; //& majorVer=major
else if (revisionVer < revision) return false; //& majorVer=major, minorVer=minor
else return true; //revisionVer>=revision & majorVer=major, minorVer=minor
}
else return false;
}
//***** PushButton *****
void MainWindow::on_pushButton_Connect_toggled(bool checked)
{
QString connectMsg;
if (checked && rigCom.connected == 0)
{
int retcode;
my_rig = rigDaemon->rigConnect(&retcode); //Open Rig connection
if (retcode != RIG_OK) //Connection error
{
rigCom.connected = 0;
connectMsg = "Connection error: ";
connectMsg.append(rigerror(retcode));
ui->pushButton_Connect->setChecked(false); //Uncheck the button
}
else //Rig connected
{
rigCom.connected = 1;
guiInit();
connectMsg = "Connected to ";
connectMsg.append(my_rig->state.model_name);
if (rigCap.onoff == 0 || rigGet.onoff == RIG_POWER_ON || rigGet.onoff == RIG_POWER_UNKNOWN)
{
freq_t retfreq;
retcode = rig_get_freq(my_rig, RIG_VFO_CURR, &retfreq); //double check if rig is on, by getting the current frequency
if (retcode==RIG_OK && retfreq!=0)
{
rigGet.onoff = RIG_POWER_ON; //force it for rigCap.onoff = 0 || rigGet.onoff = RIG_POWER_UNKNOWN
timer->start(rigCom.rigRefresh);
}
else rigGet.onoff = RIG_POWER_OFF;
}
}
}
else if (rigCom.connected) //Button unchecked
{
if (rigSet.ptt == RIG_PTT_OFF) //Disconnect only if PTT off
{
rigCom.connected = 0;
if(timer->isActive()) timer->stop();
rig_close(my_rig); //Close the communication to the rig
connectMsg = "Disconnected";
//rig_cleanup(my_rig); //Release rig handle and free associated memory
//Reset meters
ui->progressBar_Smeter->setValue(-54);
ui->progressBar_Smeter->resetPeakValue();
setSubMeter();
}
else
{
ui->pushButton_Connect->setChecked(false); //Uncheck the button
connectMsg = "Warning PTT on!";
}
}
ui->statusbar->showMessage(connectMsg);
}
void MainWindow::on_pushButton_Power_toggled(bool checked)