-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainwindow.h
68 lines (54 loc) · 1.71 KB
/
mainwindow.h
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
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "controlclient.h"
#include "util.h"
#include <QBluetoothDeviceInfo>
#include <QBluetoothLocalDevice>
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow() override;
private slots:
void sendDirection(const btremote::Direction& direction);
void sendToggle(char func, bool status);
void sendCommand(const char* command);
void setSpeed(int value);
void openDeviceListDialog();
void connectToDevice(QBluetoothDeviceInfo address);
void reconnect();
void disconnect();
void speedUp();
void speedDown();
void onSocketError(QString error);
void onConnected(const QString& peer);
void onDisconnected();
void onMessageReceived(const QString& peerName, const QString& message);
virtual void keyPressEvent(QKeyEvent *ev) override;
virtual void keyReleaseEvent(QKeyEvent *ev) override;
void handleKeyPress(int key);
void handleKeyRelease(int key);
private:
void initializeToggles();
Ui::MainWindow *ui;
ControlClient client;
QBluetoothLocalDevice localDevice;
QBluetoothDeviceInfo currentDevice;
int speed = 0;
// 保证在析构过程中不会错误触发一些东西
bool active = true;
// 保证不会同时有两个重连请求被同时预约
bool reconnectionPending = false;
QString voltage, temperature, humidity;
static const int RECONNECT_TIMEOUT = 2000;
static const int MAX_SPEED = 5;
static const int MIN_SPEED = 1;
static const char TOGGLE_SPRAY = 'P';
static const char TOGGLE_DIFF = 'C';
};
#endif // MAINWINDOW_H