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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
/*
* 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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
* Should you need to contact me, the author, you can do so by
* e-mail - mail your message to Terry Cain <[email protected]>
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "razermousedock_driver.h"
#include "razercommon.h"
#include "razerchromacommon.h"
/**
* Send report to the dock
*/
static int razer_get_report(IOUSBDeviceInterface **usb_dev, struct razer_report *request_report, struct razer_report *response_report)
{
UInt16 product = -1;
(*usb_dev)->GetDeviceProduct(usb_dev, &product);
switch (product) {
// These devices require longer waits to read their firmware, serial, and other setting values
case USB_DEVICE_ID_RAZER_MOUSE_CHARGING_DOCK:
return razer_get_usb_response(usb_dev, 0x00, request_report, 0x00, response_report, RAZER_MOUSE_DOCK_WAIT_MIN_US);
break;
default:
return -1;
}
}
/**
* Function to send to device, get response, and actually check the response
*/
static struct razer_report razer_send_payload(IOUSBDeviceInterface **usb_dev, struct razer_report *request_report)
{
IOReturn retval = -1;
struct razer_report response_report = {0};
request_report->crc = razer_calculate_crc(request_report);
retval = razer_get_report(usb_dev, request_report, &response_report);
if(retval == 0) {
// Check the packet number, class and command are the same
if(response_report.remaining_packets != request_report->remaining_packets ||
response_report.command_class != request_report->command_class ||
response_report.command_id.id != request_report->command_id.id) {
printf("Response doesn't match request (mousedock)\n");
} else if (response_report.status == RAZER_CMD_BUSY) {
//printf("Device is busy (mousedock)\n");
} else if (response_report.status == RAZER_CMD_FAILURE) {
printf("Command failed (mousedock)\n");
} else if (response_report.status == RAZER_CMD_NOT_SUPPORTED) {
printf("Command not supported (mousedock)\n");
} else if (response_report.status == RAZER_CMD_TIMEOUT) {
printf("Command timed out (mousedock)\n");
}
} else {
printf("Invalid Report Length (mousedock)\n");
}
return response_report;
}
/**
* Write device file "mode_static"
*
* Static effect mode is activated whenever the file is written to with 3 bytes
*/
ssize_t razer_mouse_dock_attr_write_mode_static(IOUSBDeviceInterface **usb_dev, const char *buf, size_t count)
{
struct razer_report report = {0};
UInt16 product = -1;
(*usb_dev)->GetDeviceProduct(usb_dev, &product);
if(count == 3) {
switch (product) {
case USB_DEVICE_ID_RAZER_MOUSE_CHARGING_DOCK:
report = razer_chroma_extended_matrix_effect_static(VARSTORE, ZERO_LED, (struct razer_rgb*) & buf[0]);
break;
default:
printf("razerdock: logo_mode_static not supported for this model\n");
break;
}
report.transaction_id.id = 0x3F;
razer_send_payload(usb_dev, &report);
} else {
printf("razerdock: Static mode only accepts RGB (3byte)\n");
}
return count;
}
/**
* Write device file "mode_static"
*
* ** NOSTORE version for efficiency in custom lighting configurations
*
* Static effect mode is activated whenever the file is written to with 3 bytes
*/
ssize_t razer_mouse_dock_attr_write_mode_static_no_store(IOUSBDeviceInterface **usb_dev, const char *buf, size_t count)
{
struct razer_report report = {0};
UInt16 product = -1;
(*usb_dev)->GetDeviceProduct(usb_dev, &product);
if(count == 3) {
switch (product) {
case USB_DEVICE_ID_RAZER_MOUSE_CHARGING_DOCK:
report = razer_chroma_extended_matrix_effect_static(NOSTORE, ZERO_LED, (struct razer_rgb*) & buf[0]);
break;
default:
printf("razerdock: logo_mode_static not supported for this model\n");
break;
}
report.transaction_id.id = 0x3F;
razer_send_payload(usb_dev, &report);
} else {
printf("razerdock: Static mode only accepts RGB (3byte)\n");
}
return count;
}
/**
* Write device file "logo_mode_spectrum" (for extended mouse matrix effects)
*
* Spectrum effect mode is activated whenever the file is written to
*/
ssize_t razer_mouse_dock_attr_write_mode_spectrum(IOUSBDeviceInterface **usb_dev, const char *buf, size_t count)
{
struct razer_report report = {0};
UInt16 product = -1;
(*usb_dev)->GetDeviceProduct(usb_dev, &product);
switch(product) {
case USB_DEVICE_ID_RAZER_MOUSE_CHARGING_DOCK:
report = razer_chroma_extended_matrix_effect_spectrum(VARSTORE, ZERO_LED);
break;
default:
printf("razerdock: logo_mode_spectrum not supported for this model\n");
return count;
}
razer_send_payload(usb_dev, &report);
return count;
}
/**
* Write device file "logo_mode_breath" (for extended mouse matrix effects)
*
* Sets breathing mode by writing 1, 3 or 6 bytes
*/
ssize_t razer_mouse_dock_attr_write_mode_breath(IOUSBDeviceInterface **usb_dev, const char *buf, size_t count)
{
struct razer_report report = {0};
UInt16 product = -1;
(*usb_dev)->GetDeviceProduct(usb_dev, &product);
switch(product) {
case USB_DEVICE_ID_RAZER_MOUSE_CHARGING_DOCK:
switch(count) {
case 3: // Single colour mode
report = razer_chroma_extended_matrix_effect_breathing_single(VARSTORE, ZERO_LED, (struct razer_rgb*)&buf[0]);
break;
case 6: // Dual colour mode
report = razer_chroma_extended_matrix_effect_breathing_dual(VARSTORE, ZERO_LED, (struct razer_rgb*)&buf[0], (struct razer_rgb*)&buf[3]);
break;
default: // "Random" colour mode
report = razer_chroma_extended_matrix_effect_breathing_random(VARSTORE, ZERO_LED);
break;
}
break;
}
report.transaction_id.id = 0x3f;
razer_send_payload(usb_dev, &report);
return count;
}
/**
* Write device file "logo_mode_none" (for extended mouse matrix effects)
*
* No effect is activated whenever this file is written to
*/
ssize_t razer_mouse_dock_attr_write_mode_none(IOUSBDeviceInterface **usb_dev, const char *buf, size_t count)
{
struct razer_report report = {0};
UInt16 product = -1;
(*usb_dev)->GetDeviceProduct(usb_dev, &product);
switch(product) {
case USB_DEVICE_ID_RAZER_MOUSE_CHARGING_DOCK:
report = razer_chroma_extended_matrix_effect_none(VARSTORE, ZERO_LED);
break;
default:
printf("razerdock: logo_mode_none not supported for this model\n");
return count;
}
razer_send_payload(usb_dev, &report);
return count;
}
|