-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
149 lines (117 loc) · 3.46 KB
/
mainwindow.cpp
File metadata and controls
149 lines (117 loc) · 3.46 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
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPushButton>
#include <QDateTime>
#include <QtDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// m_thread.startPort("/dev/ttyACM0", 10);
ui->ipEdit->setText(settings.value("MainWindow/ipEdit").toString());
ui->latencySlider->setValue(settings.value("MainWindow/latencySlider").toInt());
ui->rateSlider->setValue(settings.value("MainWindow/rateSlider").toInt());
connect(&timer, &QTimer::timeout, [=](){
sendMessage();
});
timer.setInterval(1000/30);
connect(&m_thread, &CommunicationThread::error, [=](const QString s){
qInfo() << s;
});
connect(&m_thread, &CommunicationThread::yaw, [&](double f){
ui->yawLCD->setText(QString::number(f));
});
connect(&m_thread, &CommunicationThread::pitch, [&](double f){
ui->pitchLCD->setText(QString::number(f));
});
connect(&m_thread, &CommunicationThread::roll, [&](double f){
ui->rollLCD->setText(QString::number(f));
});
//connect(&m_thread, &CommunicationThread::roll, this, &MainWindow::update_roll );
fillSerialPortList();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::sendMessage()
{
QString rateText = ui->rateSpinBox->text();
QString latencyText = ui->latencySpinBox->text();
uint8_t rate = rateText.toUInt();
uint8_t latency = latencyText.toUInt();
unsigned char bytes [] {0xff, rate, latency};
QByteArray barr( ((char*)bytes), 3);
m_thread.squeduleWrite(barr, 15);
}
void MainWindow::fillSerialPortList()
{
ui->serialPortComboBox->clear();
QList<QSerialPortInfo> ports = QSerialPortInfo::availablePorts();
for(int i = 0; i < ports.length(); i++){
ui->serialPortComboBox->addItem(ports.at(i).portName());
}
isReady = true;
}
void MainWindow::on_serialPortComboBox_currentIndexChanged(const QString &arg1)
{
if(isReady){
m_thread.startPort(arg1, 10);
}
}
void MainWindow::on_latencySlider_valueChanged(int value)
{
if(!timer.isActive()){
sendMessage();
}
settings.setValue("MainWindow/latencySlider", value);
}
void MainWindow::on_udpRadioButton_toggled(bool checked)
{
if(ui->udpRadioButton->isChecked()){
qInfo("udp radio butt");
m_thread.startUdp(ui->udpPortEdit->text().toInt(),
ui->ipEdit->text());
}
}
void MainWindow::on_tcpRadioButton_toggled(bool checked)
{
if(ui->tcpRadioButton->isChecked()){
qInfo("tcp radio butt");
m_thread.startTcp(ui->tcpPortEdit->text().toInt(),
ui->ipEdit->text());
}
}
void MainWindow::on_ipEdit_textChanged(const QString &arg1)
{
settings.setValue("MainWindow/ipEdit", arg1);
}
void MainWindow::on_serialRadioButton_toggled(bool checked)
{
if(ui->serialRadioButton->isChecked()){
m_thread.startPort(ui->serialPortComboBox->currentText(), 10);
}
}
void MainWindow::update_roll(double roll)
{
ui->rollLCD->setText(QString::number(roll));
}
void MainWindow::on_rateSlider_valueChanged(int value)
{
settings.setValue("MainWindow/rateSlider", value);
sendMessage();
}
void MainWindow::on_latencySlider_sliderMoved(int position)
{
}
void MainWindow::on_latencySlider_sliderPressed()
{
qInfo() << "sliderPressed";
timer.start();
}
void MainWindow::on_latencySlider_sliderReleased()
{
qInfo() << "sliderReleased";
timer.stop();
}