-
Notifications
You must be signed in to change notification settings - Fork 0
/
switch_mode.c
67 lines (61 loc) · 1.83 KB
/
switch_mode.c
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
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <hidapi/hidapi.h>
#include "logging.h"
#include "device_ids.h"
#include "probe.h"
// ref https://github.com/berarma/new-lg4ff/blob/master/hid-lg4ff.c
void switch_mode(struct hidraw_device device, uint32_t target_product_id){
hid_device *hd = hid_open_path(device.backend_path);
if(hd == NULL){
char error_buf[128];
wcstombs(error_buf, hid_error(NULL), sizeof(error_buf));
STDERR("failed opening hid device at %s, %s\n", device.backend_path, error_buf);
exit(1);
}
int ret;
switch(target_product_id){
case USB_DEVICE_ID_LOGITECH_G29_WHEEL:{
uint8_t cmd[] = {0xf8, 0x09, 0x05, 0x01, 0x01, 0x00, 0x00};
ret = hid_write(hd, cmd, sizeof(cmd));
break;
}
case USB_DEVICE_ID_LOGITECH_G27_WHEEL:{
uint8_t cmd[] = {0xf8, 0x09, 0x04, 0x01, 0x00, 0x00, 0x00};
ret = hid_write(hd, cmd, sizeof(cmd));
break;
}
case USB_DEVICE_ID_LOGITECH_G25_WHEEL:{
uint8_t cmd[] = {0xf8, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00};
ret = hid_write(hd, cmd, sizeof(cmd));
break;
}
case USB_DEVICE_ID_LOGITECH_DFGT_WHEEL:{
uint8_t cmd[] = {0xf8, 0x09, 0x03, 0x01, 0x00, 0x00, 0x00};
ret = hid_write(hd, cmd, sizeof(cmd));
break;
}
case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:{
uint8_t cmd[] = {0xf8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00};
ret = hid_write(hd, cmd, sizeof(cmd));
break;
}
case USB_DEVICE_ID_LOGITECH_WHEEL:{
uint8_t cmd[] = {0xf8, 0x09, 0x00, 0x01, 0x00, 0x00, 0x00};
ret = hid_write(hd, cmd, sizeof(cmd));
break;
}
default:{
STDERR("unknown product id 0x%04x for mode switching\n", target_product_id);
exit(1);
}
}
if(ret == -1){
char error_buf[128];
wcstombs(error_buf, hid_error(hd), sizeof(error_buf));
STDERR("failed sending mode set command, %s\n", error_buf);
exit(1);
}
STDOUT("mode set command sent\n");
}