-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
58 lines (47 loc) · 1.39 KB
/
mainwindow.cpp
File metadata and controls
58 lines (47 loc) · 1.39 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "plcmodbus.h"
#include "joyhid.h"
#include <QThread>
#include <QDebug>
#include <QTimer>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow), joystck(nullptr)
{
ui->setupUi(this);
QTimer* timer = new QTimer(this);
timer->setSingleShot(false);
timer->setInterval(70); // 10 seconds
/*Joystick*/
QThread *joy_thread = new QThread;
joystck = new JoyHID;
joystck -> moveToThread(joy_thread);
connect(joy_thread, &QThread::started, joystck, &JoyHID::init_machine);
connect(joystck, &JoyHID::updateUI, this, &MainWindow::uiSlot);
joy_thread->start();
/*Modbus*/
plc = new PlcModbus;
connect(joystck, &JoyHID::updateUI, plc, &PlcModbus::updateHID);
connect(timer, &QTimer::timeout, plc, &PlcModbus::plcReadWrite);
timer->start();
}
MainWindow::~MainWindow()
{
delete joystck;
delete plc;
delete ui;
}
void MainWindow::uiSlot(HID_JOYSTK_Info_TypeDef *dev)
{
ui->lineEdit->setText(QString::number(dev->X));
ui->lineEdit_2->setText(QString::number(dev->Y));
ui->lineEdit_3->setText(QString::number(dev->Z));
ui->lineEdit_4->setText(QString::number(dev->X_low));
ui->lineEdit_5->setText(QString::number(dev->Y_low));
}
void MainWindow::on_tabWidget_tabBarClicked(int index)
{
if (index==3)
MainWindow::close();
}