-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcutesdeck.h
133 lines (101 loc) · 3.27 KB
/
cutesdeck.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
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
#ifndef CUTESDECK_H
#define CUTESDECK_H
#include "qsocketnotifier.h"
#include <QObject>
#include <QImage>
#include <QFuture>
#include <QQmlEngine>
#include <QQmlParserStatus>
#include <libudev.h>
#include <linux/hidraw.h>
class CuteSdeck : public QObject, public QQmlParserStatus
{
Q_OBJECT
Q_INTERFACES(QQmlParserStatus)
QML_NAMED_ELEMENT(CuteStreamDeck)
Q_PROPERTY(bool isOpen READ isOpen NOTIFY isOpenChanged FINAL)
Q_PROPERTY(bool autoOpen READ autoOpen WRITE setAutoOpen NOTIFY autoOpenChanged FINAL)
Q_PROPERTY(QString serial READ serial NOTIFY serialChanged FINAL)
Q_PROPERTY(uint devices READ devices NOTIFY devicesChanged FINAL)
Q_PROPERTY(uint buttons READ buttons NOTIFY buttonsChanged FINAL)
Q_PROPERTY(QColor background READ background WRITE setBackground NOTIFY backgroundChanged FINAL)
Q_PROPERTY(QColor foreground READ foreground WRITE setForeground NOTIFY foregroundChanged FINAL)
public:
explicit CuteSdeck(QObject *parent = nullptr);
void classBegin() override;
void componentComplete() override;
enum Devices {
DeckUnknown=0,
DeckOriginal=0x0060,
DeckOriginalV2=0x006d,
DeckXL=0x006c,
DeckXLV2=0x008f,
DeckMK2=0x0080,
DeckPedal=0x0086,
DeckMiniMK2=0x0090
};
Q_ENUM(Devices)
~CuteSdeck();
bool isOpen();
QString serial() const;
uint buttons() const;
bool autoOpen() const;
void setAutoOpen(bool newAutoOpen);
int getBrightness();
uint devices() const;
QColor background() const;
void setBackground(const QColor &newBackground);
QColor foreground() const;
void setForeground(const QColor &newForeground);
public slots:
bool openDeck(int id);
bool closeDeck();
QString serialNumber();
int setBrightness(uint8_t percent);
int resetDeck();
bool setImage(uint8_t key, const char *img, ssize_t imgsize);
bool setImage(uint8_t key, const QImage &img, bool scale=false);
int resetImages();
bool setImageText(uint8_t key, const QString txt);
bool setImageJPG(uint8_t key, const QString file);
signals:
void keyPressed(quint8 key);
void keyReleased(quint8 key);
void error();
void isOpenChanged();
void serialChanged();
void buttonsChanged();
void autoOpenChanged();
void devicesChanged();
void backgroundChanged();
void foregroundChanged();
protected:
int setImagePart(char key, char part);
private slots:
void readDeck();
void readUdevMonitor();
private:
unsigned char btnbuf[255];
QString m_serial;
QSize m_imgsize;
uint8_t m_buttons=0;
bool m_autoOpen;
bool have_udev;
struct udev *udev;
struct udev_monitor *mon;
struct libevdev *edev;
int udev_fd=-1;
int hid_fd=-1;
QSocketNotifier *m_hid_notifier=nullptr;
QSocketNotifier *m_udev_notifier=nullptr;
QMap<QString, QString> m_devices;
QColor m_background;
QColor m_foreground;
int findInputDevices();
int hidraw_send_feature_report(const unsigned char *data, size_t length);
int hidraw_get_feature_report(const unsigned char *data, size_t length);
void enableUdevMonitoring();
bool probeDevice(const char *devpath);
short getVendorProduct(int fd, hidraw_devinfo &info);
};
#endif // CUTESDECK_H