-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtune_dialog.cpp
More file actions
110 lines (93 loc) · 3.05 KB
/
tune_dialog.cpp
File metadata and controls
110 lines (93 loc) · 3.05 KB
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
#include "tune_dialog.h"
#include "mainwindow.h"
TuneDialog::TuneDialog(QObject *parent)
: QObject{parent}
{
tp = nullptr;
tuning = 0;
pMainWindow = static_cast<MainWindow *>(parent);
pHamLib = pMainWindow->getHamlibPointer();
dp = new QDialog(static_cast<QWidget *>(parent));
dp->setModal(true);
dp->setMinimumSize(QSize(300, 100));
pLabel = new QLabel("Click TUNE Button to Tune - Watch SWR", dp);
pLabel->setGeometry(QRect(5,5,300,25));
swrLabel = new QLabel("SWR: ", dp);
swrLabel->setGeometry((QRect(25, 40, 200, 25)));
pbox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, dp);
pbox->setGeometry(50, 80, 150, 60);
// Change the label of the standard OK button to "TUNE"
QPushButton *tb = pbox->button(QDialogButtonBox::Ok);
tb->setText("TUNE");
// Connect signals
connect(pbox, &QDialogButtonBox::clicked, this, &TuneDialog::pb_ok_clicked);
connect(pbox, &QDialogButtonBox::accepted, this, &TuneDialog::accept_clicked);
connect(this, &TuneDialog::setTune_sig, pHamLib, &HamlibConnector::mrrSetTune);
dp->exec();
}
void TuneDialog::pb_ok_clicked(QAbstractButton *button) {
QString button_text = button->text();
qDebug() << "TuneDialog::pb_ok_clicked(): entered - button text" << button_text;
if ( button_text == "Cancel" ) {
if ( tuning ) {
emit setTune_sig(false);
tuning = 0;
}
if ( tp ) {
tp->terminate();
tp->wait();
delete tp;
tp = nullptr;
}
dp->close();
}
return;
}
TuneDialog::~TuneDialog() {
delete pbox; delete pLabel; delete dp;
}
void TuneDialog::accept_clicked() {
qDebug() << "TuneDialog::accept_clicked(): entered";
tp = new TuneThread(dp);
connect(tp, &TuneThread::setTune_sig, pHamLib, &HamlibConnector::mrrSetTune);
// Signal "finished" is a private QThread signal emitted with the thread finishes
connect(tp, &TuneThread::finished, this, &TuneDialog::tuneFinished);
connect(tp, &TuneThread::updateSWR, this, &TuneDialog::updateSWR);
tp->pHamLib = pMainWindow->getHamlibPointer();
tuning = 1;
tp->start();
}
void TuneDialog::tuneFinished() {
qDebug() << "TuneDialog::tuneFinished(): cleaning up";
emit setTune_sig(false);
}
void TuneDialog::updateSWR(float s) {
QString str = "SWR: ";
QString str2;
str2.setNum(s);
swrLabel->setText(str + str2);
}
/*
****************** Tune Thread **************************
*/
TuneThread::TuneThread()
{
}
TuneThread::TuneThread(QDialog *p)
{
qDebug() << "TuneThread::TuneThread() constructor entered";
pDialog = p;
}
void TuneThread::run() {
qDebug() << "TuneThread running";
emit setTune_sig(true);
for ( int i=0; i<1; i++ ) {
qDebug() << "TuneThread::run(): calling read_rig_swr()";
float swr = pHamLib->read_rig_swr();
emit updateSWR(swr);
// pDialog->swrLabel->setText("SWR: ");
// pDialog->
qDebug() << "Transmit SWR = " << swr;
QThread::msleep(4000);
}
}