Wizualizacja konfiguracji dłoni  1.0
mainwindow.hh
Idź do dokumentacji tego pliku.
1 #ifndef MAINWINDOW_H
2 #define MAINWINDOW_H
3 
4 #include <QMainWindow>
5 #include <QCoreApplication>
6 #include <QtGlobal>
7 
8 #include <QFile>
9 #include <QtSerialPort/QSerialPort>
10 #include <QTimer>
11 #include <QVector>
12 
13 #include <stdio.h>
14 #include <iostream>
15 
16 #include "connection.hh"
17 #include "time.hh"
18 #include "qcustomplot.hh"
19 #include "functions.hh"
20 
21 // opcje polaczenia
22 #define MAX_CONNECTION_TRIES 3
23 #define RECONNECT_SECONDS 5
24 #define SERIAL_OPEN_MODE QIODevice::ReadWrite
25 
26 // KOMUNIKACJA Z URZADZENIEM
27 // -- typy czujnikow
28 #define SENSOR_TYPE_BEND 0x1
29 #define SENSOR_TYPE_TOUCH 0x2
30 #define SENSOR_TYPE_ACC 0x3
31 
32 // -- ID czujnika
33 #define SENSOR_ID_FINGER_THUMB 0x1
34 #define SENSOR_ID_FINGER_INDEX 0x2
35 #define SENSOR_ID_FINGER_MIDDLE 0x3
36 #define SENSOR_ID_FINGER_RING 0x4
37 #define SENSOR_ID_FINGER_PINKY 0x5
38 #define SENSOR_ID_ACC_XAXIS 0xA
39 #define SENSOR_ID_ACC_ZAXIS 0xB
40 
41 // -- zakresy czujnikow
42 #define SENSOR_RANGE_BEND_MIN 0x00
43 #define SENSOR_RANGE_BEND_MAX 0xFF
44 #define SENSOR_RANGE_TOUCH_MIN 0x00
45 #define SENSOR_RANGE_TOUCH_MAX 0xFF
46 #define SENSOR_RANGE_ACC_MIN 0x00
47 #define SENSOR_RANGE_ACC_MAX 0xFF
48 
49 // -- zakresy progress barow
50 #define BAR_PERCENTAGE_MAX 0x64
51 #define BAR_PERCENTAGE_MIN 0x00
52 
53 // -- komunikaty wysylane
54 #define DEVICE_HANDSHAKE "01\n"
55 #define DEVICE_START "02\n"
56 #define DEVICE_STOP "03\n"
57 
58 #define DEVICE_VIBRATE 0x40
59 
60 // -- komunikaty odbierane
61 #define DEVICE_HANDSHAKE_RESPONSE 0x10
62 #define DEVICE_START_RESPONSE 0x20
63 #define DEVICE_STOP_RESPONSE 0x30
64 #define DEVICE_FIRST_WORD 0xF0
65 
66 // WYKRESY
67 #define X_RANGE_POINTS 20
68 #define TIMER_TIMEOUT_MS 250
69 
70 // -- debugging i testy
71 #define MAX_SENSORS_BEND 5
72 #define MAX_SENSORS_TOUCH 5
73 #define MAX_AXIS_ACC 2
74 #define MAX_SENSORS MAX_SENSORS_BEND + MAX_SENSORS_TOUCH + MAX_AXIS_ACC
75 
76 namespace Ui {
77 class MainWindow;
78 }
79 
85 class MainWindow : public QMainWindow
86 {
87  Q_OBJECT
88 private:
89  QGraphicsScene *scene_visualisation = new QGraphicsScene;
90  QGraphicsScene *scene_orientation = new QGraphicsScene;
91 
99  void set_hand_visualisation_scene(int sensor_type, int sensor_id, int sensor_value);
100 
104  void reset_hand_visualisation_scene();
105 
106 
107 public:
111  explicit MainWindow(QWidget *parent = nullptr);
115  ~MainWindow();
116 
120  void parse(const std::string&);
121 
128  double convert_touch_value(double touch_value);
129 
130 public slots:
134  void action_connect_click();
138  void action_disconnect_click();
142  void action_exit_click();
143 
144 
145 
149  void serial_dataAvailable();
150 
156  void serial_errorOccurred(QSerialPort::SerialPortError error);
157 
158 
159 
163  void device_ready();
164 
168  void handle_data(const std::string& _data);
169 
170 
171 
177  void vibrate(const int& sensor_id);
178 
182  void vibrate_thumb();
183 
187  void vibrate_index();
188 
192  void vibrate_middle();
193 
197  void vibrate_ring();
198 
202  void vibrate_pinky();
203 
204 
205 
209  void testrun();
210 
214  void testrun_timeoutHandler();
215 
216 signals:
220  void disconnect_me();
221 
225  void reconnect();
226 
227 private:
229 
230  // -- ustawienia polaczenia
232 
233  // -- polaczenie
234  QSerialPort *serial;
235  int timeout_counter; // ilosc powtornych prob polaczenia
236 
237  // flagi komunikacji
238  bool flag_isConnected; // podlaczony
239  bool device_firstWord; // przeslal pierwszy komunikat
240  bool device_isReady; // gotowy do transmisji
242 
243  // -- dane do wykresow
244  QVector<double> graph_time, // czas
245 
246  sensor_bend_01, // kciuk zgiecie
247  sensor_bend_02, // wskazujacy zgiecie
248  sensor_bend_03, // srodkowy zgiecie
249  sensor_bend_04, // serdeczny zgiecie
250  sensor_bend_05, // maly zgiecie
251 
252  // w przypadku sensorow dotyku dane dotycza rowniez progress barow
253  sensor_touch_01, // kciuk dotyk
254  sensor_touch_02, // wskazujacy dotyk
255  sensor_touch_03, // srodkowy dotyk
256  sensor_touch_04, // serdeczny dotyk
257  sensor_touch_05, // maly dotyk
258 
259  sensor_acc_x, // akcelerometr os x
260  sensor_acc_z; // akcelerometr os z
261 
262  QVector<QVector<double>*> pointers_bendSensor; // wskazniki na wektory danych czujnikow zgiecia
263  QVector<QVector<double>*> pointers_touchSensor; // wskazniki na wektory danych czujnikow dotyku
264  QVector<QVector<double>*> pointers_accSensor; // wskazniki na wektory danych akcelerometru
265 
266  double time_now; // przechowuje aktualny czas polaczenia
267 
268  // -- ustawienia wykresow
269  // zgiecie
270  QVector<QPen> pens;
271  QVector<QPen> pens_ACC;
272 
273  // -- debug
274  QTimer* debugTimer;
275  bool debug_on;
276  char* debug_frame;
277 };
278 
279 #endif // MAINWINDOW_H
bool device_finished
Definition: mainwindow.hh:241
double time_now
Definition: mainwindow.hh:266
QVector< QPen > pens
Definition: mainwindow.hh:270
Definition: mainwindow.hh:76
QSerialPort * serial
Definition: mainwindow.hh:234
QVector< QPen > pens_ACC
Definition: mainwindow.hh:271
Klasa definiujaca okno ustawień połączenia.
Definition: connection.hh:13
QVector< QVector< double > * > pointers_accSensor
Definition: mainwindow.hh:264
char * debug_frame
Definition: mainwindow.hh:276
QVector< double > sensor_touch_05
Definition: mainwindow.hh:244
Ui::MainWindow * ui
Definition: mainwindow.hh:228
Connection * connectionWindow
Definition: mainwindow.hh:231
int timeout_counter
Definition: mainwindow.hh:235
QTimer * debugTimer
Definition: mainwindow.hh:274
bool debug_on
Definition: mainwindow.hh:275
Definition: ui_mainwindow.hh:703
QVector< QVector< double > * > pointers_touchSensor
Definition: mainwindow.hh:263
bool device_firstWord
Definition: mainwindow.hh:239
QVector< QVector< double > * > pointers_bendSensor
Definition: mainwindow.hh:262
Klasa definiujaca glowne okno.
Definition: mainwindow.hh:85
bool device_isReady
Definition: mainwindow.hh:240
bool flag_isConnected
Definition: mainwindow.hh:238