-
Notifications
You must be signed in to change notification settings - Fork 2
/
CorsairDevice.h
123 lines (103 loc) · 2.76 KB
/
CorsairDevice.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
/*
* Copyright 2016 Clément Vuchener
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef CORSAIR_DEVICE_H
#define CORSAIR_DEVICE_H
#include <cstdint>
#include <stdexcept>
#include <vector>
extern "C" {
#include <libusb.h>
}
struct Color {
uint8_t r, g, b;
};
class CorsairDevice
{
public:
class FeatureNotSupported: public std::exception
{
public:
FeatureNotSupported ();
virtual const char *what () noexcept;
};
CorsairDevice (libusb_device *dev, std::size_t status_size);
virtual ~CorsairDevice ();
enum Mode: uint8_t {
HardwareMode = 0x01,
FirmwareUpdateMode = 0x10,
SoftwareMode = 0x30,
};
Mode getMode ();
void setMode (Mode mode);
virtual unsigned int getBacklightBrightness () = 0;
virtual void setBacklightBrightness (unsigned int brightness) = 0;
virtual unsigned int getCurrentProfile () = 0;
virtual void setCurrentProfile (unsigned int index);
virtual Color getProfileColor (unsigned int profile_index) = 0;
virtual void setProfileColor (unsigned int profile_index, Color color) = 0;
struct MacroItem {
enum Type: uint8_t {
Key = 0x84,
End = 0x86,
Delay = 0x87,
} type;
union {
struct {
uint8_t usage;
bool pressed;
} key_event;
uint16_t delay;
};
};
struct KeySettings {
uint8_t key_usage;
enum RepeatMode: uint8_t {
RepeatFixed = 1,
RepeatHold = 2,
RepeatToggle = 3,
} repeat_mode;
enum BindType: uint8_t {
BindNone = 0x00,
BindUsage = 0x10,
BindMacro = 0x20,
} bind_type;
uint8_t target_usage;
uint16_t repeat_count;
std::vector<MacroItem> macro;
};
void setKeys (unsigned int profile_index, const std::vector<KeySettings> &keys);
std::vector<uint8_t> getRawStatus ();
bool checkErrorState ();
protected:
enum CorsairRequest: uint8_t {
SetMode = 2,
GetMode = 5,
Status = 4,
SetCurrentProfile = 20,
MacroBindings = 16,
MacroData = 18,
MacroKeys = 22,
};
static constexpr uint8_t RequestInType =
LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE;
static constexpr uint8_t RequestOutType =
LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE;
libusb_device_handle *_dev;
std::size_t _status_size;
};
#endif