-
Notifications
You must be signed in to change notification settings - Fork 0
/
hid_pnp.h
85 lines (64 loc) · 1.75 KB
/
hid_pnp.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef HID_PNP_H
#define HID_PNP_H
#include <QObject>
#include <QTimer>
#include <stdlib.h>
#include <array>
#include "runtime_config_inc.h"
#include "../teensy_fan_controller/src/hid_shared.h"
#include "../HIDAPI/hidapi.h"
#define BUF_SIZE 65
#define HID_CONNECT_FAIL_MAX 3
struct UI_Data_Fan
{
uint16_t rpm = 0;
uint8_t pct = 0;
uint8_t mode = 0;
uint8_t source = 0;
};
struct UI_Data
{
bool isConnectedLog = false;
bool isConnectedData = false;
bool hasConfigDownloaded = false;
bool pendingConfigUpdate = false;
qreal supplyTemp = 0.0;
qreal returnTemp = 0.0;
qreal caseTemp = 0.0;
qreal aux1Temp = 0.0;
qreal aux2Temp = 0.0;
qreal deltaT = 0.0;
qreal setpointSupply = 0.0;
qreal setpointAux1 = 0.0;
std::array<UI_Data_Fan, FAN_CNT> fans;
};
class HID_PnP : public QObject
{
Q_OBJECT
public:
explicit HID_PnP(QObject *parent = nullptr);
~HID_PnP();
void reconnect();
signals:
void hid_config_download(bool isConnected, const RuntimeConfig &config);
void hid_comm_update(bool isConnected, const UI_Data &ui_data);
void hid_connect_status(const bool connecting, const bool dataOnline, const bool logOnline);
void hid_state(const quint8 state);
void log_append(bool isConnected, QString str);
public slots:
void pollUSB();
bool saveConfig(const RuntimeConfig &conf);
bool writeConfigChunk(uint8_t chunk, bool isLast);
private:
hid_device *deviceLog = nullptr;
hid_device *deviceData = nullptr;
QTimer *timer = nullptr;
byte buf[BUF_SIZE];
byte config_bytes[CONFIG_BYTES];
UI_Data ui_data;
RuntimeConfig config;
uint8_t connectLogErrCnt = 0;
uint8_t connectDataErrCnt = 0;
void closeDevice();
};
#endif // HID_PNP_H