-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCUESDKInjection.cpp
More file actions
136 lines (100 loc) · 4.51 KB
/
Copy pathCUESDKInjection.cpp
File metadata and controls
136 lines (100 loc) · 4.51 KB
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
134
135
136
#include "CUESDKInjection.h"
// checks file and protocol version of CUE to understand which of SDK functions can be used with this version of CUE
CorsairProtocolDetails CorsairPerformProtocolHandshake() {
initLog();
info("CALL: CorsairPerformProtocolHandshake()");
connectClient();
struct CorsairProtocolDetails details = {
CUESDK_SDK_VERSION,
CUESDK_SERVER_VERSION,
CUESDK_SDK_PROTOCOL,
CUESDK_SERVER_PROTOCOL,
false
};
return details;
}
// returns last error that occured while using any of Corsair* functions
CorsairError CorsairGetLastError() {
info("CALL: CorsairGetLastError()");
return CorsairError::CE_Success;
}
// requestes control using specified access mode. By default client has shared control over lighting so there is no need to call CorsairRequestControl unless client requires exclusive control
bool CorsairRequestControl(CorsairAccessMode accessMode) {
info("CALL: CorsairRequestControl(accessMode=%d)", accessMode);
saveOriginalModes();
return true;
}
// returns number of connected Corsair devices that support lighting control.
int CorsairGetDeviceCount() {
info("CALL: CorsairGetDeviceCount()");
size_t count = getDeviceCount();
info("DEVICES: Found %d device(s)", count);
return count;
}
// returns information about device at provided index
CorsairDeviceInfo *CorsairGetDeviceInfo(int deviceIndex) {
info("CALL: CorsairGetDeviceInfo(deviceIndex=%d)", deviceIndex);
const orgb::Device * device = getDevice(deviceIndex);
struct CorsairDeviceInfo *deviceInfo = new CorsairDeviceInfo[1];
deviceInfo->type = mapDeviceTypeToCorsairDeviceType(device->type);
deviceInfo->model = device->name.c_str();
deviceInfo->ledsCount = device->leds.size();
deviceInfo->capsMask = CorsairDeviceCaps::CDC_Lighting;
deviceInfo->physicalLayout = CorsairPhysicalLayout::CPL_US;
deviceInfo->logicalLayout = CorsairLogicalLayout::CLL_BE;
info("DEVICE: %s with %d leds", deviceInfo->model, deviceInfo->ledsCount);
return deviceInfo;
}
typedef struct CorsairLedPositions CorsairLedPositions;
typedef struct CorsairLedPosition CorsairLedPosition;
// provides list of keyboard LEDs with their physical positions.
CorsairLedPositions *_CorsairGetLedPositions(int deviceIndex) {
const orgb::Device * device = getDevice(deviceIndex);
CorsairLedPositions* positions = new CorsairLedPositions;
positions->numberOfLed = device->leds.size();
positions->pLedPosition = basicLayout;
return positions;
}
// provides list of keyboard LEDs with their physical positions.
CorsairLedPositions *CorsairGetLedPositions() {
info("CALL: CorsairGetLedPositions()");
// TODO: Return for all devices as CorsairLedPositions
return _CorsairGetLedPositions(0);
}
// provides list of keyboard or mousemat LEDs with their physical positions.
CorsairLedPositions *CorsairGetLedPositionsByDeviceIndex(int deviceIndex) {
info("CALL: CorsairGetLedPositionsByDeviceIndex(deviceIndex=%d)", deviceIndex);
return _CorsairGetLedPositions(deviceIndex);
}
bool _CorsairSetLedsColors(int size, CorsairLedColor* ledsColors) {
const Device * device = getLastDevice();
for(int i=0; i<size; i++) {
debug("SET COLOR[%d]: LED %d to [%d, %d, %d]",
i,
ledsColors[i].ledId,
ledsColors[i].r,
ledsColors[i].g,
ledsColors[i].b);
setLedColor(i, ledsColors[i].r, ledsColors[i].g, ledsColors[i].b);
}
return true;
}
bool CorsairSetLedsColors(int size, CorsairLedColor* ledsColors) {
debug("CALL: CorsairSetLedsColors(size=%d)", size);
return _CorsairSetLedsColors(size, ledsColors);
}
bool CorsairSetLedsColorsAsync(int size, CorsairLedColor* ledsColors, void(*CallbackType)(void*, bool, CorsairError), void *context) {
debug("CALL: CorsairSetLedsColorsAsync(size=%d)", size);
return _CorsairSetLedsColors(size, ledsColors);
}
// retrieves led id for key name taking logical layout into account.
CorsairLedId CorsairGetLedIdForKeyName(char keyName) {
info("CALL: CorsairGetLedIdForKeyName(keyname=%c)", keyName);
return CorsairLedId::CLK_Escape;
}
//releases previously requested control for specified access mode
bool CorsairReleaseControl(CorsairAccessMode accessMode) {
info("CALL: CorsairReleaseControl(accessMode=%d)", accessMode);
restoreOriginalModes();
return true;
}