First commit.
[temp2RGB.git] / src / roccat.rs
1 use crate::common::*;
2
3 const VID: u16 = 0x1E7D;
4 const PID: u16 = 0x2E2C;
5 const INTERFACE: i32 = 0x00;
6 const PAGE: u16 = 0x0B;
7 const USAGE: u16 = 0x00;
8
9 pub fn get_device(api: &hidapi::HidApi) -> hidapi::HidDevice {
10 let device_info = api
11 .device_list()
12 .find(|device| {
13 device.vendor_id() == VID
14 && device.product_id() == PID
15 && device.interface_number() == INTERFACE
16 && device.usage_page() == PAGE
17 && device.usage() == USAGE
18 })
19 .unwrap();
20 device_info.open_device(&api).unwrap()
21 }
22
23 pub fn init(device: &hidapi::HidDevice) {
24 let mut buffer = [0u8; 6];
25
26 buffer[0x00] = 0x0E;
27 buffer[0x01] = 0x06;
28 buffer[0x02] = 0x01;
29 buffer[0x03] = 0x01;
30 buffer[0x04] = 0x00;
31 buffer[0x05] = 0xFF;
32
33 device
34 .send_feature_report(&buffer)
35 .expect("Cannot send feature report during init");
36 }
37
38 pub fn set_color(device: &hidapi::HidDevice, color: &RGB) {
39 let mut buffer = [0u8; 46];
40 buffer[0] = 0x0D;
41 buffer[1] = 0x2E;
42
43 /*
44 * Leds:
45 * 0: Scroll wheel.
46 * 1-4: Strip left.
47 * 5-8: Strip right.
48 * 9: Lower left.
49 * 10: Lower right.
50 */
51 for i in 0..=10 {
52 let offset = i * 4 + 2;
53 buffer[offset] = color.red;
54 buffer[offset + 1] = color.green;
55 buffer[offset + 2] = color.blue;
56 }
57
58 device
59 .send_feature_report(&buffer)
60 .expect("Cannot send feature report during set color");
61 }