-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
210 lines (195 loc) · 6.05 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <qwt_dial_needle.h>
#include <settingsdialog.h>
#include <QFile>
#include <QMessageBox>
MainWindow::MainWindow(const QString &conffile, QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow), configfile(conffile),
rotator(QFile::exists(conffile)?new QHamRotator(conffile):new QHamRotator()),
polltimer(new QTimer), allowuiupdate(true)
{
ui->setupUi(this);
rotator_status = new QLabel(tr("Standby"));
connection_status = new QLabel(tr("Disconnected"));
ui->statusbar->addWidget(rotator_status);
ui->statusbar->addPermanentWidget(connection_status);
//ui->az_compass->setNeedle(new QwtCompassMagnetNeedle(QwtCompassMagnetNeedle::TriangleStyle,ui->az_compass->palette().mid().color(),ui->az_compass->palette().dark().color()));
ui->el_dial->setNeedle(new QwtDialSimpleNeedle(QwtDialSimpleNeedle::Ray));
ui->az_compass->setNeedle(new QwtDialSimpleNeedle(QwtDialSimpleNeedle::Ray));
reloadUi();
connect(polltimer, SIGNAL(timeout()), this, SLOT(poll_rotator()));
}
void MainWindow::reloadUi()
{
double min_el = 0;
double max_el = 180;
double min_az = 0;
double max_az = 360;
try {
if (rotator->isOpened()) target_pos = rotator->getPosition();
polltimer->setInterval(rotator->getPollingInterval());
min_el = QLocale().toDouble(rotator->getConf("min_el"));
max_el = QLocale().toDouble(rotator->getConf("max_el"));
min_az = QLocale().toDouble(rotator->getConf("min_az"));
max_az = QLocale().toDouble(rotator->getConf("max_az"));
}
catch (const RotException& e) {
QMessageBox::information(this,tr("Error"),tr(e.what()));
}
ui->el_dial->setMinScaleArc(min_el);
ui->el_dial->setMaxScaleArc(max_el);
ui->el_dial->setLowerBound(min_el);
ui->el_dial->setUpperBound(max_el);
ui->el_number->setMinimum(min_el);
ui->el_number->setMaximum(max_el);
ui->az_compass->setMinScaleArc(min_az);
ui->az_compass->setMaxScaleArc((max_az>360)?360:max_az);
ui->az_compass->setLowerBound(min_az);
ui->az_compass->setUpperBound((max_az>360)?360:max_az);
ui->az_number->setMinimum(min_az);
ui->az_number->setMaximum(max_az);
}
MainWindow::~MainWindow()
{
if (rotator->isOpened()) rotator->close();
delete ui;
delete rotator;
delete polltimer;
delete connection_status;
delete rotator_status;
}
void MainWindow::on_actionExit_triggered()
{
QApplication::quit();
}
void MainWindow::poll_rotator()
{
TRotatorPosition pos;
try {
pos = rotator->getPosition();
}
catch (const RotException& e) {
QMessageBox::information(this,tr("Error"),tr(e.what()));
}
if (pos != target_pos) {
rotator_status->setText(tr("Moving to") + " (" + QString::number(target_pos.first) + "," + QString::number(target_pos.second) + ")");
}
else {
rotator_status->setText(tr("Standby"));
}
if (allowuiupdate)
{
ui->az_compass->setValue((pos.first>360)?(pos.first-360):pos.first);
ui->el_dial->setValue(pos.second);
}
}
void MainWindow::on_az_compass_valueChanged(double value)
{
ui->az_number->setValue(value);
}
void MainWindow::on_el_dial_valueChanged(double value)
{
ui->el_number->setValue(value);
}
void MainWindow::on_az_compass_sliderPressed()
{
allowuiupdate = false;
}
void MainWindow::on_el_dial_sliderPressed()
{
allowuiupdate = false;
}
void MainWindow::on_az_compass_sliderReleased()
{
allowuiupdate = true;
try {
if (rotator->isOpened())
{
target_pos.first = ui->az_compass->value();
rotator->setPosition(target_pos);
}
}
catch (const RotException& e) {
QMessageBox::information(this,tr("Error"),tr(e.what()));
}
}
void MainWindow::on_el_dial_sliderReleased()
{
allowuiupdate = true;
try {
if (rotator->isOpened())
{
target_pos.second = ui->el_dial->value();
rotator->setPosition(target_pos);
}
}
catch (const RotException& e) {
QMessageBox::information(this,tr("Error"),tr(e.what()));
}
}
void MainWindow::on_actionConnect_to_rotator_triggered()
{
try {
if (!rotator->isOpened())
{
rotator->open();
polltimer->start();
target_pos = rotator->getPosition();
QString path(rotator->getConf("rot_pathname"));
if (!path.isEmpty()) path = " " + tr("on") + " " + path;
connection_status->setText(tr("Connected to") + " " + QString(rotator->caps->mfg_name) + " " + QString(rotator->caps->model_name) + path );
}
}
catch (const RotException& e) {
polltimer->stop();
rotator->close();
QMessageBox::information(this,tr("Error"),tr(e.what()));
}
}
void MainWindow::on_actionDisconnect_triggered()
{
try {
if (rotator->isOpened())
{
polltimer->stop();
rotator->close();
connection_status->setText(tr("Disconnected"));
}
}
catch (const RotException& e) {
QMessageBox::information(this,tr("Error"),tr(e.what()));
}
}
void MainWindow::on_actionSettings_triggered()
{
SettingsDialog *settings = new SettingsDialog(configfile,this);
settings->setModal(true);
if (settings->exec() == QDialog::DialogCode::Accepted)
{
try {
delete rotator;
rotator = new QHamRotator(configfile);
}
catch (const RotException& e) {
QMessageBox::information(this,tr("Error"),tr(e.what()));
}
reloadUi();
}
delete settings;
}
void MainWindow::on_go_button_clicked()
{
ui->az_compass->setValue(ui->az_number->value());
ui->el_dial->setValue(ui->el_number->value());
target_pos.first = ui->az_number->value(); target_pos.second = ui->el_number->value();
try {
if (rotator->isOpened())
{
rotator->setPosition(target_pos);
}
}
catch (const RotException& e) {
QMessageBox::information(this,tr("Error"),tr(e.what()));
}
}