Skip to content

Commit 94cf16c

Browse files
committed
Merge branch 'felfert-switch-lights'
2 parents 3138482 + 68d2e46 commit 94cf16c

7 files changed

Lines changed: 68 additions & 6 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ talking. This differs from a simple loopback via PulseAudio as you won't have an
1818

1919
### Other Features
2020

21-
Corsair Void (Pro) also supports checking of the battery.
21+
Corsair Void (Pro) also supports checking of the battery and switching LED off/on
2222

2323
For more features (like getting battery percentage of other devices, or settings LEDs etc. of specific devices), the protocol of the respective headset must be analyzed further. This can be done by capturing the USB traffic and analyzing it with WireShark or USBlyzer.
2424

@@ -84,6 +84,8 @@ Following options don't work on all devices yet:
8484

8585
`HeadsetControl -n 0|1` sends a notification sound, made by the headset. 0 or 1 are currently supported as values.
8686

87+
`HeadsetControl -l 0|1` switches LED off/on (off almost doubles battery lifetime!).
88+
8789
## Notice
8890

8991
HeadsetControl is distributed in the hope that it will be useful,\

src/device.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
enum capabilities {
1414
CAP_SIDETONE = 1,
1515
CAP_BATTERY_STATUS = 2,
16-
CAP_NOTIFICATION_SOUND = 3
16+
CAP_NOTIFICATION_SOUND = 4,
17+
CAP_LIGHTS = 8,
1718
};
1819

1920
/** @brief Flags for battery status
@@ -54,5 +55,7 @@ struct device
5455
int (*request_battery)(hid_device *hid_device);
5556

5657
int (*notifcation_sound)(hid_device *hid_device, uint8_t soundid);
58+
59+
int (*switch_lights)(hid_device *hid_device, uint8_t on);
5760
};
5861

src/devices/corsair_void.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ static struct device device_void;
1010
static int void_send_sidetone(hid_device *device_handle, uint8_t num);
1111
static int void_request_battery(hid_device *device_handle);
1212
static int void_notification_sound(hid_device *hid_device, uint8_t soundid);
13+
static int void_lights(hid_device *device_handle, uint8_t on);
1314

1415
void void_init(struct device** device)
1516
{
@@ -18,10 +19,11 @@ void void_init(struct device** device)
1819

1920
strcpy(device_void.device_name, "Corsair Void");
2021

21-
device_void.capabilities = CAP_SIDETONE | CAP_BATTERY_STATUS | CAP_NOTIFICATION_SOUND;
22+
device_void.capabilities = CAP_SIDETONE | CAP_BATTERY_STATUS | CAP_NOTIFICATION_SOUND | CAP_LIGHTS;
2223
device_void.send_sidetone = &void_send_sidetone;
2324
device_void.request_battery = &void_request_battery;
2425
device_void.notifcation_sound = &void_notification_sound;
26+
device_void.switch_lights = &void_lights;
2527

2628
*device = &device_void;
2729
}
@@ -75,3 +77,9 @@ static int void_notification_sound(hid_device* device_handle, uint8_t soundid)
7577

7678
return hid_write(device_handle, data, 3);
7779
}
80+
81+
static int void_lights(hid_device* device_handle, uint8_t on)
82+
{
83+
unsigned char data[3] = {0xC8, on ? 0x00 : 0x01, 0x00};
84+
return hid_write(device_handle, data, 3);
85+
}

src/devices/corsair_voidpro.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ static struct device device_voidpro;
1313
static int voidpro_send_sidetone(hid_device *device_handle, uint8_t num);
1414
static int voidpro_request_battery(hid_device *device_handle);
1515
static int voidpro_notification_sound(hid_device *hid_device, uint8_t soundid);
16+
static int voidpro_lights(hid_device* device_handle, uint8_t on);
1617

1718
void voidpro_init(struct device** device)
1819
{
@@ -21,10 +22,11 @@ void voidpro_init(struct device** device)
2122

2223
strcpy(device_voidpro.device_name, "Corsair Void Pro");
2324

24-
device_voidpro.capabilities = CAP_SIDETONE | CAP_BATTERY_STATUS | CAP_NOTIFICATION_SOUND;
25+
device_voidpro.capabilities = CAP_SIDETONE | CAP_BATTERY_STATUS | CAP_NOTIFICATION_SOUND | CAP_LIGHTS;
2526
device_voidpro.send_sidetone = &voidpro_send_sidetone;
2627
device_voidpro.request_battery = &voidpro_request_battery;
2728
device_voidpro.notifcation_sound = &voidpro_notification_sound;
29+
device_voidpro.switch_lights = &voidpro_lights;
2830

2931
*device = &device_voidpro;
3032
}
@@ -90,3 +92,9 @@ static int voidpro_notification_sound(hid_device* device_handle, uint8_t soundid
9092

9193
return hid_write(device_handle, data, 3);
9294
}
95+
96+
static int voidpro_lights(hid_device* device_handle, uint8_t on)
97+
{
98+
unsigned char data[3] = {0xC8, on ? 0x00 : 0x01, 0x00};
99+
return hid_write(device_handle, data, 3);
100+
}

src/devices/corsair_voidpro_wireless.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ static struct device device_voidpro_wireless;
1313
static int voidpro_wireless_send_sidetone(hid_device *device_handle, uint8_t num);
1414
static int voidpro_wireless_request_battery(hid_device *device_handle);
1515
static int voidpro_wireless_notification_sound(hid_device *hid_device, uint8_t soundid);
16+
static int voidpro_wireless_lights(hid_device* device_handle, uint8_t on);
1617

1718
void voidpro_wireless_init(struct device** device)
1819
{
@@ -21,10 +22,11 @@ void voidpro_wireless_init(struct device** device)
2122

2223
strcpy(device_voidpro_wireless.device_name, "Corsair Void Pro Wireless");
2324

24-
device_voidpro_wireless.capabilities = CAP_SIDETONE | CAP_BATTERY_STATUS | CAP_NOTIFICATION_SOUND;
25+
device_voidpro_wireless.capabilities = CAP_SIDETONE | CAP_BATTERY_STATUS | CAP_NOTIFICATION_SOUND | CAP_LIGHTS;
2526
device_voidpro_wireless.send_sidetone = &voidpro_wireless_send_sidetone;
2627
device_voidpro_wireless.request_battery = &voidpro_wireless_request_battery;
2728
device_voidpro_wireless.notifcation_sound = &voidpro_wireless_notification_sound;
29+
device_voidpro_wireless.switch_lights = &voidpro_wireless_lights;
2830

2931
*device = &device_voidpro_wireless;
3032
}
@@ -90,3 +92,9 @@ static int voidpro_wireless_notification_sound(hid_device* device_handle, uint8_
9092

9193
return hid_write(device_handle, data, 3);
9294
}
95+
96+
static int voidpro_wireless_lights(hid_device* device_handle, uint8_t on)
97+
{
98+
unsigned char data[3] = {0xC8, on ? 0x00 : 0x01, 0x00};
99+
return hid_write(device_handle, data, 3);
100+
}

src/main.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,10 @@ int main(int argc, char *argv[])
153153
int sidetone_loudness = -1;
154154
int request_battery = 0;
155155
int notification_sound = -1;
156+
int lights = -1;
156157

157158

158-
while ((c = getopt(argc, argv, "bchs:n:")) != -1)
159+
while ((c = getopt(argc, argv, "bchs:n:l:")) != -1)
159160
{
160161
switch(c) {
161162
case 'b':
@@ -182,12 +183,21 @@ int main(int argc, char *argv[])
182183
case 'c':
183184
short_output = 1;
184185
break;
186+
case 'l':
187+
lights = strtol(optarg, NULL, 10);
188+
if (lights < 0 || lights > 1)
189+
{
190+
printf("Usage: %s -l 0|1\n", argv[0]);
191+
return 1;
192+
}
193+
break;
185194
case 'h':
186195
printf("Headsetcontrol written by Sapd (Denis Arnst)\n\thttps://github.com/Sapd\n\n");
187196
printf("Parameters\n");
188197
printf(" -s level\tSets sidetone, level must be between 0 and 128\n");
189198
printf(" -b\t\tChecks the battery level\n");
190199
printf(" -n soundid\tMakes the headset play a notifiation\n");
200+
printf(" -l 0|1\tSwitch lights (0 = off, 1 = on)\n");
191201
printf(" -c\t\tCut unnecessary output \n");
192202

193203
printf("\n");
@@ -262,6 +272,28 @@ int main(int argc, char *argv[])
262272
}
263273
}
264274

275+
if (lights != -1)
276+
{
277+
if ((device_found.capabilities & CAP_LIGHTS) == 0)
278+
{
279+
PRINT("Error: This headset doesn't support light switching\n");
280+
terminate_hid(&device_handle, &hid_path);
281+
return 1;
282+
}
283+
ret = device_found.switch_lights(device_handle, lights);
284+
285+
if (ret < 0)
286+
{
287+
PRINT("Failed to switch lights. Error: %d: %ls\n", ret, hid_error(device_handle));
288+
terminate_hid(&device_handle, &hid_path);
289+
return 1;
290+
}
291+
else
292+
{
293+
PRINT("Success!\n");
294+
}
295+
}
296+
265297
if (notification_sound != -1)
266298
{
267299
if ((device_found.capabilities & CAP_NOTIFICATION_SOUND) == 0)

0 commit comments

Comments
 (0)