Skip to content

Commit a183fce

Browse files
committed
Change formatting option and fixed format
1 parent ad3f125 commit a183fce

19 files changed

+140
-156
lines changed

.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
Language: Cpp
33
BasedOnStyle: WebKit
44
AlignConsecutiveMacros: true
5+
AlignConsecutiveAssignments: true
56
...

src/dev.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static void print_devices(unsigned short vendorid, unsigned short productid)
2323
{
2424
struct hid_device_info *devs, *cur_dev;
2525

26-
devs = hid_enumerate(vendorid, productid);
26+
devs = hid_enumerate(vendorid, productid);
2727
cur_dev = devs;
2828
while (cur_dev) {
2929
printf("Device Found\n VendorID: %#06hx\n ProductID: %#06hx\n path: %s\n serial_number: %ls",
@@ -59,7 +59,7 @@ static int get_data_from_parameter(char* input, char* dest, size_t len)
5959

6060
// For each token in the string, parse and store in buf[].
6161
char* token = strtok(input, delim);
62-
int i = 0;
62+
int i = 0;
6363
while (token) {
6464
char* endptr;
6565
long int val = strtol(token, &endptr, 0);
@@ -68,7 +68,7 @@ static int get_data_from_parameter(char* input, char* dest, size_t len)
6868
return -1;
6969

7070
dest[i++] = val;
71-
token = strtok(NULL, delim);
71+
token = strtok(NULL, delim);
7272
}
7373

7474
free(str);
@@ -112,7 +112,7 @@ static int get_two_ids(char* input, int* id1, int* id2)
112112
strcpy(str, input);
113113

114114
char* token = strtok(input, delim);
115-
int i = 0;
115+
int i = 0;
116116
while (token) {
117117
char* endptr;
118118
long int val = strtol(token, &endptr, 0);
@@ -188,29 +188,29 @@ static void print_help()
188188

189189
int dev_main(int argc, char* argv[])
190190
{
191-
int vendorid = 0;
192-
int productid = 0;
191+
int vendorid = 0;
192+
int productid = 0;
193193
int interfaceid = 0;
194-
int usagepage = 0;
195-
int usageid = 0;
194+
int usagepage = 0;
195+
int usageid = 0;
196196

197-
int send = 0;
197+
int send = 0;
198198
int send_feature = 0;
199199

200200
int sleep = -1;
201201

202-
int receive = 0;
202+
int receive = 0;
203203
int receivereport = 0;
204204

205205
int timeout = 0;
206206

207207
int print_deviceinfo = 0;
208208

209209
#define BUFFERLENGTH 1024
210-
char* sendbuffer = calloc(BUFFERLENGTH, sizeof(char));
210+
char* sendbuffer = calloc(BUFFERLENGTH, sizeof(char));
211211
char* sendreportbuffer = calloc(BUFFERLENGTH, sizeof(char));
212212

213-
unsigned char* receivebuffer = malloc(sizeof(char) * BUFFERLENGTH);
213+
unsigned char* receivebuffer = malloc(sizeof(char) * BUFFERLENGTH);
214214
unsigned char* receivereportbuffer = malloc(sizeof(char) * BUFFERLENGTH);
215215

216216
struct option opts[] = {
@@ -323,7 +323,7 @@ int dev_main(int argc, char* argv[])
323323
}
324324
case 'g': { // --receive-feature [reportid]
325325
int reportid = 0;
326-
reportid = strtol(optarg, NULL, 10);
326+
reportid = strtol(optarg, NULL, 10);
327327

328328
if (reportid > 255 || reportid < 0) {
329329
fprintf(stderr, "The reportid for --receive-feature must be smaller than 255\n");
@@ -371,7 +371,7 @@ int dev_main(int argc, char* argv[])
371371
return 1;
372372
}
373373

374-
char* hid_path = get_hid_path(vendorid, productid, interfaceid, usagepage, usageid);
374+
char* hid_path = get_hid_path(vendorid, productid, interfaceid, usagepage, usageid);
375375
hid_device* device_handle = NULL;
376376

377377
if (hid_path == NULL) {

src/device.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22

33
const char* const capabilities_str[NUM_CAPABILITIES]
44
= {
5-
[CAP_SIDETONE] = "sidetone",
6-
[CAP_BATTERY_STATUS] = "battery status",
5+
[CAP_SIDETONE] = "sidetone",
6+
[CAP_BATTERY_STATUS] = "battery status",
77
[CAP_NOTIFICATION_SOUND] = "notification sound",
8-
[CAP_LIGHTS] = "lights",
9-
[CAP_INACTIVE_TIME] = "inactive time",
10-
[CAP_CHATMIX_STATUS] = "chatmix",
11-
[CAP_VOICE_PROMPTS] = "voice prompts",
12-
[CAP_ROTATE_TO_MUTE] = "rotate to mute",
8+
[CAP_LIGHTS] = "lights",
9+
[CAP_INACTIVE_TIME] = "inactive time",
10+
[CAP_CHATMIX_STATUS] = "chatmix",
11+
[CAP_VOICE_PROMPTS] = "voice prompts",
12+
[CAP_ROTATE_TO_MUTE] = "rotate to mute",
1313
};
1414

1515
const char capabilities_str_short[NUM_CAPABILITIES]
1616
= {
17-
[CAP_SIDETONE] = 's',
18-
[CAP_BATTERY_STATUS] = 'b',
17+
[CAP_SIDETONE] = 's',
18+
[CAP_BATTERY_STATUS] = 'b',
1919
[CAP_NOTIFICATION_SOUND] = 'n',
20-
[CAP_LIGHTS] = 'l',
21-
[CAP_INACTIVE_TIME] = 'i',
22-
[CAP_CHATMIX_STATUS] = 'm',
23-
[CAP_VOICE_PROMPTS] = 'v',
24-
[CAP_ROTATE_TO_MUTE] = 'r',
20+
[CAP_LIGHTS] = 'l',
21+
[CAP_INACTIVE_TIME] = 'i',
22+
[CAP_CHATMIX_STATUS] = 'm',
23+
[CAP_VOICE_PROMPTS] = 'v',
24+
[CAP_ROTATE_TO_MUTE] = 'r',
2525
};

src/device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct capability_detail {
4646
*/
4747
enum battery_status {
4848
BATTERY_UNAVAILABLE = 65534,
49-
BATTERY_CHARGING = 65535
49+
BATTERY_CHARGING = 65535
5050
};
5151

5252
enum headsetcontrol_errors {

src/devices/corsair_void.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,22 @@ static int void_lights(hid_device* device_handle, uint8_t on);
4949

5050
void void_init(struct device** device)
5151
{
52-
device_void.idVendor = VENDOR_CORSAIR;
52+
device_void.idVendor = VENDOR_CORSAIR;
5353
device_void.idProductsSupported = PRODUCT_IDS;
54-
device_void.numIdProducts = sizeof(PRODUCT_IDS) / sizeof(PRODUCT_IDS[0]);
54+
device_void.numIdProducts = sizeof(PRODUCT_IDS) / sizeof(PRODUCT_IDS[0]);
5555

5656
strncpy(device_void.device_name, "Corsair Headset Device", sizeof(device_void.device_name));
5757

58-
device_void.capabilities = B(CAP_SIDETONE) | B(CAP_BATTERY_STATUS) | B(CAP_NOTIFICATION_SOUND) | B(CAP_LIGHTS);
59-
device_void.capability_details[CAP_SIDETONE] = (struct capability_detail)
60-
{ .usagepage = 0xff00, .usageid = 0x1, .interface = 0 };
61-
device_void.capability_details[CAP_BATTERY_STATUS] = (struct capability_detail)
62-
{ .usagepage = 0xffc5, .usageid = 0x1, .interface = 3 };
63-
device_void.capability_details[CAP_NOTIFICATION_SOUND] = (struct capability_detail)
64-
{ .usagepage = 0xffc5, .usageid = 0x1, .interface = 3 };
65-
device_void.capability_details[CAP_LIGHTS] = (struct capability_detail)
66-
{ .usagepage = 0xffc5, .usageid = 0x1, .interface = 3 };
67-
68-
device_void.send_sidetone = &void_send_sidetone;
69-
device_void.request_battery = &void_request_battery;
58+
device_void.capabilities = B(CAP_SIDETONE) | B(CAP_BATTERY_STATUS) | B(CAP_NOTIFICATION_SOUND) | B(CAP_LIGHTS);
59+
device_void.capability_details[CAP_SIDETONE] = (struct capability_detail) { .usagepage = 0xff00, .usageid = 0x1, .interface = 0 };
60+
device_void.capability_details[CAP_BATTERY_STATUS] = (struct capability_detail) { .usagepage = 0xffc5, .usageid = 0x1, .interface = 3 };
61+
device_void.capability_details[CAP_NOTIFICATION_SOUND] = (struct capability_detail) { .usagepage = 0xffc5, .usageid = 0x1, .interface = 3 };
62+
device_void.capability_details[CAP_LIGHTS] = (struct capability_detail) { .usagepage = 0xffc5, .usageid = 0x1, .interface = 3 };
63+
64+
device_void.send_sidetone = &void_send_sidetone;
65+
device_void.request_battery = &void_request_battery;
7066
device_void.notifcation_sound = &void_notification_sound;
71-
device_void.switch_lights = &void_lights;
67+
device_void.switch_lights = &void_lights;
7268

7369
*device = &device_void;
7470
}

src/devices/logitech_g430.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ static int g430_send_sidetone(hid_device* device_handle, uint8_t num);
1111

1212
void g430_init(struct device** device)
1313
{
14-
device_g430.idVendor = VENDOR_LOGITECH;
14+
device_g430.idVendor = VENDOR_LOGITECH;
1515
device_g430.idProductsSupported = &PRODUCT_ID;
16-
device_g430.numIdProducts = 1;
16+
device_g430.numIdProducts = 1;
1717

1818
strncpy(device_g430.device_name, "Logitech G430", sizeof(device_g430.device_name));
1919

20-
device_g430.capabilities = B(CAP_SIDETONE);
20+
device_g430.capabilities = B(CAP_SIDETONE);
2121
device_g430.send_sidetone = &g430_send_sidetone;
2222

2323
*device = &device_g430;

src/devices/logitech_g432.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ static int g432_send_sidetone(hid_device* device_handle, uint8_t num);
1818

1919
void g432_init(struct device** device)
2020
{
21-
device_g432.idVendor = VENDOR_LOGITECH;
21+
device_g432.idVendor = VENDOR_LOGITECH;
2222
device_g432.idProductsSupported = PRODUCT_IDS;
23-
device_g432.numIdProducts = sizeof(PRODUCT_IDS) / sizeof(PRODUCT_IDS[0]);
23+
device_g432.numIdProducts = sizeof(PRODUCT_IDS) / sizeof(PRODUCT_IDS[0]);
2424

2525
strncpy(device_g432.device_name, "Logitech G432/G433", sizeof(device_g432.device_name));
2626

27-
device_g432.capabilities = B(CAP_SIDETONE);
27+
device_g432.capabilities = B(CAP_SIDETONE);
2828
device_g432.send_sidetone = &g432_send_sidetone;
2929

3030
*device = &device_g432;

src/devices/logitech_g533.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ static int g533_request_battery(hid_device* device_handle);
1616

1717
void g533_init(struct device** device)
1818
{
19-
device_g533.idVendor = VENDOR_LOGITECH;
19+
device_g533.idVendor = VENDOR_LOGITECH;
2020
device_g533.idProductsSupported = &PRODUCT_ID;
21-
device_g533.numIdProducts = 1;
21+
device_g533.numIdProducts = 1;
2222

2323
strncpy(device_g533.device_name, "Logitech G533", sizeof(device_g533.device_name));
2424

25-
device_g533.capabilities = B(CAP_SIDETONE) | B(CAP_BATTERY_STATUS);
25+
device_g533.capabilities = B(CAP_SIDETONE) | B(CAP_BATTERY_STATUS);
2626
device_g533.request_battery = &g533_request_battery;
27-
device_g533.send_sidetone = &g533_send_sidetone;
27+
device_g533.send_sidetone = &g533_send_sidetone;
2828

2929
*device = &device_g533;
3030
}
@@ -67,7 +67,7 @@ static int g533_request_battery(hid_device* device_handle)
6767
int r = 0;
6868
// request battery voltage
6969
uint8_t data_request[HIDPP_LONG_MESSAGE_LENGTH] = { HIDPP_LONG_MESSAGE, HIDPP_DEVICE_RECEIVER, 0x07, 0x01 };
70-
r = hid_write(device_handle, data_request, HIDPP_LONG_MESSAGE_LENGTH);
70+
r = hid_write(device_handle, data_request, HIDPP_LONG_MESSAGE_LENGTH);
7171
if (r < 0)
7272
return r;
7373

src/devices/logitech_g633_g933_935.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,20 @@ static int g933_935_lights(hid_device* device_handle, uint8_t on);
2323

2424
void g933_935_init(struct device** device)
2525
{
26-
device_g933_935.idVendor = VENDOR_LOGITECH;
26+
device_g933_935.idVendor = VENDOR_LOGITECH;
2727
device_g933_935.idProductsSupported = PRODUCT_IDS;
28-
device_g933_935.numIdProducts = sizeof(PRODUCT_IDS) / sizeof(PRODUCT_IDS[0]);
28+
device_g933_935.numIdProducts = sizeof(PRODUCT_IDS) / sizeof(PRODUCT_IDS[0]);
2929
strncpy(device_g933_935.device_name, "Logitech G633/G635/G933/G935", sizeof(device_g933_935.device_name));
3030

3131
device_g933_935.capabilities = B(CAP_SIDETONE) | B(CAP_BATTERY_STATUS) | B(CAP_LIGHTS);
3232
/// TODO: usagepages and ids may not be correct for all features
33-
device_g933_935.capability_details[CAP_SIDETONE] = (struct capability_detail)
34-
{ .usagepage = 0xff43, .usageid = 0x0202 };
35-
device_g933_935.capability_details[CAP_BATTERY_STATUS] = (struct capability_detail)
36-
{ .usagepage = 0xff43, .usageid = 0x0202 };
37-
device_g933_935.capability_details[CAP_LIGHTS] = (struct capability_detail)
38-
{ .usagepage = 0xff43, .usageid = 0x0202 };
39-
40-
device_g933_935.send_sidetone = &g933_935_send_sidetone;
33+
device_g933_935.capability_details[CAP_SIDETONE] = (struct capability_detail) { .usagepage = 0xff43, .usageid = 0x0202 };
34+
device_g933_935.capability_details[CAP_BATTERY_STATUS] = (struct capability_detail) { .usagepage = 0xff43, .usageid = 0x0202 };
35+
device_g933_935.capability_details[CAP_LIGHTS] = (struct capability_detail) { .usagepage = 0xff43, .usageid = 0x0202 };
36+
37+
device_g933_935.send_sidetone = &g933_935_send_sidetone;
4138
device_g933_935.request_battery = &g933_935_request_battery;
42-
device_g933_935.switch_lights = &g933_935_lights;
39+
device_g933_935.switch_lights = &g933_935_lights;
4340

4441
*device = &device_g933_935;
4542
}
@@ -114,7 +111,7 @@ static int g933_935_lights(hid_device* device_handle, uint8_t on)
114111
// off 11 ff 04 3c 01 (0 for logo) 00
115112
// logo and strips can be controlled individually
116113

117-
uint8_t data_on[HIDPP_LONG_MESSAGE_LENGTH] = { HIDPP_LONG_MESSAGE, HIDPP_DEVICE_RECEIVER, 0x04, 0x3c, 0x01, 0x02, 0x00, 0xb6, 0xff, 0x0f, 0xa0, 0x00, 0x64, 0x00, 0x00, 0x00 };
114+
uint8_t data_on[HIDPP_LONG_MESSAGE_LENGTH] = { HIDPP_LONG_MESSAGE, HIDPP_DEVICE_RECEIVER, 0x04, 0x3c, 0x01, 0x02, 0x00, 0xb6, 0xff, 0x0f, 0xa0, 0x00, 0x64, 0x00, 0x00, 0x00 };
118115
uint8_t data_off[HIDPP_LONG_MESSAGE_LENGTH] = { HIDPP_LONG_MESSAGE, HIDPP_DEVICE_RECEIVER, 0x04, 0x3c, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
119116
int res;
120117
res = hid_write(device_handle, on ? data_on : data_off, HIDPP_LONG_MESSAGE_LENGTH);
@@ -124,9 +121,9 @@ static int g933_935_lights(hid_device* device_handle, uint8_t on)
124121
// TODO Investigate further.
125122
usleep(1 * 1000); // wait before next request, otherwise device ignores one of them, on windows at least.
126123
// turn logo lights on/off
127-
uint8_t data_logo_on[HIDPP_LONG_MESSAGE_LENGTH] = { HIDPP_LONG_MESSAGE, HIDPP_DEVICE_RECEIVER, 0x04, 0x3c, 0x00, 0x02, 0x00, 0xb6, 0xff, 0x0f, 0xa0, 0x00, 0x64, 0x00, 0x00, 0x00 };
124+
uint8_t data_logo_on[HIDPP_LONG_MESSAGE_LENGTH] = { HIDPP_LONG_MESSAGE, HIDPP_DEVICE_RECEIVER, 0x04, 0x3c, 0x00, 0x02, 0x00, 0xb6, 0xff, 0x0f, 0xa0, 0x00, 0x64, 0x00, 0x00, 0x00 };
128125
uint8_t data_logo_off[HIDPP_LONG_MESSAGE_LENGTH] = { HIDPP_LONG_MESSAGE, HIDPP_DEVICE_RECEIVER, 0x04, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
129-
res = hid_write(device_handle, on ? data_logo_on : data_logo_off, HIDPP_LONG_MESSAGE_LENGTH);
126+
res = hid_write(device_handle, on ? data_logo_on : data_logo_off, HIDPP_LONG_MESSAGE_LENGTH);
130127

131128
return res;
132129
}

src/devices/logitech_g930.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,18 @@ static int g930_request_battery(hid_device* device_handle);
2222

2323
void g930_init(struct device** device)
2424
{
25-
device_g930.idVendor = VENDOR_LOGITECH;
25+
device_g930.idVendor = VENDOR_LOGITECH;
2626
device_g930.idProductsSupported = &PRODUCT_ID;
27-
device_g930.numIdProducts = 1;
27+
device_g930.numIdProducts = 1;
2828

2929
strncpy(device_g930.device_name, "Logitech G930", sizeof(device_g930.device_name));
3030

3131
device_g930.capabilities = B(CAP_SIDETONE) | B(CAP_BATTERY_STATUS);
3232
/// TODO: usagepages and ids may not be correct for all features
33-
device_g930.capability_details[CAP_SIDETONE] = (struct capability_detail)
34-
{ .usagepage = 0xff00, .usageid = 0x1 };
35-
device_g930.capability_details[CAP_BATTERY_STATUS] = (struct capability_detail)
36-
{ .usagepage = 0xff00, .usageid = 0x1 };
33+
device_g930.capability_details[CAP_SIDETONE] = (struct capability_detail) { .usagepage = 0xff00, .usageid = 0x1 };
34+
device_g930.capability_details[CAP_BATTERY_STATUS] = (struct capability_detail) { .usagepage = 0xff00, .usageid = 0x1 };
3735

38-
device_g930.send_sidetone = &g930_send_sidetone;
36+
device_g930.send_sidetone = &g930_send_sidetone;
3937
device_g930.request_battery = &g930_request_battery;
4038

4139
*device = &device_g930;

src/devices/logitech_gpro.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ static int gpro_send_sidetone(hid_device* device_handle, uint8_t num);
2020

2121
void gpro_init(struct device** device)
2222
{
23-
device_gpro.idVendor = VENDOR_LOGITECH;
23+
device_gpro.idVendor = VENDOR_LOGITECH;
2424
device_gpro.idProductsSupported = PRODUCT_IDS;
25-
device_gpro.numIdProducts = sizeof(PRODUCT_IDS) / sizeof(PRODUCT_IDS[0]);
25+
device_gpro.numIdProducts = sizeof(PRODUCT_IDS) / sizeof(PRODUCT_IDS[0]);
2626

2727
strncpy(device_gpro.device_name, "Logitech G PRO Series", sizeof(device_gpro.device_name));
2828

29-
device_gpro.capabilities = B(CAP_SIDETONE);
29+
device_gpro.capabilities = B(CAP_SIDETONE);
3030
device_gpro.send_sidetone = &gpro_send_sidetone;
3131

3232
*device = &device_gpro;

src/devices/logitech_zone_wired.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ static int zone_wired_switch_rotate_to_mute(hid_device* device_handle, uint8_t o
2727

2828
void zone_wired_init(struct device** device)
2929
{
30-
device_zone_wired.idVendor = VENDOR_LOGITECH;
30+
device_zone_wired.idVendor = VENDOR_LOGITECH;
3131
device_zone_wired.idProductsSupported = PRODUCT_IDS;
32-
device_zone_wired.numIdProducts = sizeof(PRODUCT_IDS) / sizeof(PRODUCT_IDS[0]);
32+
device_zone_wired.numIdProducts = sizeof(PRODUCT_IDS) / sizeof(PRODUCT_IDS[0]);
3333

3434
strncpy(device_zone_wired.device_name, "Logitech Zone Wired/Zone 750", sizeof(device_zone_wired.device_name));
3535

36-
device_zone_wired.capabilities = B(CAP_SIDETONE) | B(CAP_VOICE_PROMPTS) | B(CAP_ROTATE_TO_MUTE);
37-
device_zone_wired.send_sidetone = &zone_wired_send_sidetone;
38-
device_zone_wired.switch_voice_prompts = &zone_wired_switch_voice_prompts;
36+
device_zone_wired.capabilities = B(CAP_SIDETONE) | B(CAP_VOICE_PROMPTS) | B(CAP_ROTATE_TO_MUTE);
37+
device_zone_wired.send_sidetone = &zone_wired_send_sidetone;
38+
device_zone_wired.switch_voice_prompts = &zone_wired_switch_voice_prompts;
3939
device_zone_wired.switch_rotate_to_mute = &zone_wired_switch_rotate_to_mute;
4040

4141
*device = &device_zone_wired;
@@ -44,7 +44,7 @@ void zone_wired_init(struct device** device)
4444
static int zone_wired_send_sidetone(hid_device* device_handle, uint8_t num)
4545
{
4646
// The sidetone volume of the Zone Wired is configured in steps of 10%, with 0x00 = 0% and 0x0A = 100%
47-
uint8_t raw_volume = map(num, 0, 128, 0, 10);
47+
uint8_t raw_volume = map(num, 0, 128, 0, 10);
4848
uint8_t data[MSG_SIZE] = { 0x22, 0xF1, 0x04, 0x00, 0x04, 0x3d, raw_volume, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
4949

5050
return hid_send_feature_report(device_handle, data, MSG_SIZE);

0 commit comments

Comments
 (0)