Skip to content

Commit

Permalink
Change formatting option and fixed format
Browse files Browse the repository at this point in the history
  • Loading branch information
Sapd committed Nov 13, 2021
1 parent ad3f125 commit a183fce
Show file tree
Hide file tree
Showing 19 changed files with 140 additions and 156 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
Language: Cpp
BasedOnStyle: WebKit
AlignConsecutiveMacros: true
AlignConsecutiveAssignments: true
...
28 changes: 14 additions & 14 deletions src/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static void print_devices(unsigned short vendorid, unsigned short productid)
{
struct hid_device_info *devs, *cur_dev;

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

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

dest[i++] = val;
token = strtok(NULL, delim);
token = strtok(NULL, delim);
}

free(str);
Expand Down Expand Up @@ -112,7 +112,7 @@ static int get_two_ids(char* input, int* id1, int* id2)
strcpy(str, input);

char* token = strtok(input, delim);
int i = 0;
int i = 0;
while (token) {
char* endptr;
long int val = strtol(token, &endptr, 0);
Expand Down Expand Up @@ -188,29 +188,29 @@ static void print_help()

int dev_main(int argc, char* argv[])
{
int vendorid = 0;
int productid = 0;
int vendorid = 0;
int productid = 0;
int interfaceid = 0;
int usagepage = 0;
int usageid = 0;
int usagepage = 0;
int usageid = 0;

int send = 0;
int send = 0;
int send_feature = 0;

int sleep = -1;

int receive = 0;
int receive = 0;
int receivereport = 0;

int timeout = 0;

int print_deviceinfo = 0;

#define BUFFERLENGTH 1024
char* sendbuffer = calloc(BUFFERLENGTH, sizeof(char));
char* sendbuffer = calloc(BUFFERLENGTH, sizeof(char));
char* sendreportbuffer = calloc(BUFFERLENGTH, sizeof(char));

unsigned char* receivebuffer = malloc(sizeof(char) * BUFFERLENGTH);
unsigned char* receivebuffer = malloc(sizeof(char) * BUFFERLENGTH);
unsigned char* receivereportbuffer = malloc(sizeof(char) * BUFFERLENGTH);

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

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

char* hid_path = get_hid_path(vendorid, productid, interfaceid, usagepage, usageid);
char* hid_path = get_hid_path(vendorid, productid, interfaceid, usagepage, usageid);
hid_device* device_handle = NULL;

if (hid_path == NULL) {
Expand Down
28 changes: 14 additions & 14 deletions src/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

const char* const capabilities_str[NUM_CAPABILITIES]
= {
[CAP_SIDETONE] = "sidetone",
[CAP_BATTERY_STATUS] = "battery status",
[CAP_SIDETONE] = "sidetone",
[CAP_BATTERY_STATUS] = "battery status",
[CAP_NOTIFICATION_SOUND] = "notification sound",
[CAP_LIGHTS] = "lights",
[CAP_INACTIVE_TIME] = "inactive time",
[CAP_CHATMIX_STATUS] = "chatmix",
[CAP_VOICE_PROMPTS] = "voice prompts",
[CAP_ROTATE_TO_MUTE] = "rotate to mute",
[CAP_LIGHTS] = "lights",
[CAP_INACTIVE_TIME] = "inactive time",
[CAP_CHATMIX_STATUS] = "chatmix",
[CAP_VOICE_PROMPTS] = "voice prompts",
[CAP_ROTATE_TO_MUTE] = "rotate to mute",
};

const char capabilities_str_short[NUM_CAPABILITIES]
= {
[CAP_SIDETONE] = 's',
[CAP_BATTERY_STATUS] = 'b',
[CAP_SIDETONE] = 's',
[CAP_BATTERY_STATUS] = 'b',
[CAP_NOTIFICATION_SOUND] = 'n',
[CAP_LIGHTS] = 'l',
[CAP_INACTIVE_TIME] = 'i',
[CAP_CHATMIX_STATUS] = 'm',
[CAP_VOICE_PROMPTS] = 'v',
[CAP_ROTATE_TO_MUTE] = 'r',
[CAP_LIGHTS] = 'l',
[CAP_INACTIVE_TIME] = 'i',
[CAP_CHATMIX_STATUS] = 'm',
[CAP_VOICE_PROMPTS] = 'v',
[CAP_ROTATE_TO_MUTE] = 'r',
};
2 changes: 1 addition & 1 deletion src/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct capability_detail {
*/
enum battery_status {
BATTERY_UNAVAILABLE = 65534,
BATTERY_CHARGING = 65535
BATTERY_CHARGING = 65535
};

enum headsetcontrol_errors {
Expand Down
26 changes: 11 additions & 15 deletions src/devices/corsair_void.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,22 @@ static int void_lights(hid_device* device_handle, uint8_t on);

void void_init(struct device** device)
{
device_void.idVendor = VENDOR_CORSAIR;
device_void.idVendor = VENDOR_CORSAIR;
device_void.idProductsSupported = PRODUCT_IDS;
device_void.numIdProducts = sizeof(PRODUCT_IDS) / sizeof(PRODUCT_IDS[0]);
device_void.numIdProducts = sizeof(PRODUCT_IDS) / sizeof(PRODUCT_IDS[0]);

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

device_void.capabilities = B(CAP_SIDETONE) | B(CAP_BATTERY_STATUS) | B(CAP_NOTIFICATION_SOUND) | B(CAP_LIGHTS);
device_void.capability_details[CAP_SIDETONE] = (struct capability_detail)
{ .usagepage = 0xff00, .usageid = 0x1, .interface = 0 };
device_void.capability_details[CAP_BATTERY_STATUS] = (struct capability_detail)
{ .usagepage = 0xffc5, .usageid = 0x1, .interface = 3 };
device_void.capability_details[CAP_NOTIFICATION_SOUND] = (struct capability_detail)
{ .usagepage = 0xffc5, .usageid = 0x1, .interface = 3 };
device_void.capability_details[CAP_LIGHTS] = (struct capability_detail)
{ .usagepage = 0xffc5, .usageid = 0x1, .interface = 3 };

device_void.send_sidetone = &void_send_sidetone;
device_void.request_battery = &void_request_battery;
device_void.capabilities = B(CAP_SIDETONE) | B(CAP_BATTERY_STATUS) | B(CAP_NOTIFICATION_SOUND) | B(CAP_LIGHTS);
device_void.capability_details[CAP_SIDETONE] = (struct capability_detail) { .usagepage = 0xff00, .usageid = 0x1, .interface = 0 };
device_void.capability_details[CAP_BATTERY_STATUS] = (struct capability_detail) { .usagepage = 0xffc5, .usageid = 0x1, .interface = 3 };
device_void.capability_details[CAP_NOTIFICATION_SOUND] = (struct capability_detail) { .usagepage = 0xffc5, .usageid = 0x1, .interface = 3 };
device_void.capability_details[CAP_LIGHTS] = (struct capability_detail) { .usagepage = 0xffc5, .usageid = 0x1, .interface = 3 };

device_void.send_sidetone = &void_send_sidetone;
device_void.request_battery = &void_request_battery;
device_void.notifcation_sound = &void_notification_sound;
device_void.switch_lights = &void_lights;
device_void.switch_lights = &void_lights;

*device = &device_void;
}
Expand Down
6 changes: 3 additions & 3 deletions src/devices/logitech_g430.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ static int g430_send_sidetone(hid_device* device_handle, uint8_t num);

void g430_init(struct device** device)
{
device_g430.idVendor = VENDOR_LOGITECH;
device_g430.idVendor = VENDOR_LOGITECH;
device_g430.idProductsSupported = &PRODUCT_ID;
device_g430.numIdProducts = 1;
device_g430.numIdProducts = 1;

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

device_g430.capabilities = B(CAP_SIDETONE);
device_g430.capabilities = B(CAP_SIDETONE);
device_g430.send_sidetone = &g430_send_sidetone;

*device = &device_g430;
Expand Down
6 changes: 3 additions & 3 deletions src/devices/logitech_g432.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ static int g432_send_sidetone(hid_device* device_handle, uint8_t num);

void g432_init(struct device** device)
{
device_g432.idVendor = VENDOR_LOGITECH;
device_g432.idVendor = VENDOR_LOGITECH;
device_g432.idProductsSupported = PRODUCT_IDS;
device_g432.numIdProducts = sizeof(PRODUCT_IDS) / sizeof(PRODUCT_IDS[0]);
device_g432.numIdProducts = sizeof(PRODUCT_IDS) / sizeof(PRODUCT_IDS[0]);

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

device_g432.capabilities = B(CAP_SIDETONE);
device_g432.capabilities = B(CAP_SIDETONE);
device_g432.send_sidetone = &g432_send_sidetone;

*device = &device_g432;
Expand Down
10 changes: 5 additions & 5 deletions src/devices/logitech_g533.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ static int g533_request_battery(hid_device* device_handle);

void g533_init(struct device** device)
{
device_g533.idVendor = VENDOR_LOGITECH;
device_g533.idVendor = VENDOR_LOGITECH;
device_g533.idProductsSupported = &PRODUCT_ID;
device_g533.numIdProducts = 1;
device_g533.numIdProducts = 1;

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

device_g533.capabilities = B(CAP_SIDETONE) | B(CAP_BATTERY_STATUS);
device_g533.capabilities = B(CAP_SIDETONE) | B(CAP_BATTERY_STATUS);
device_g533.request_battery = &g533_request_battery;
device_g533.send_sidetone = &g533_send_sidetone;
device_g533.send_sidetone = &g533_send_sidetone;

*device = &device_g533;
}
Expand Down Expand Up @@ -67,7 +67,7 @@ static int g533_request_battery(hid_device* device_handle)
int r = 0;
// request battery voltage
uint8_t data_request[HIDPP_LONG_MESSAGE_LENGTH] = { HIDPP_LONG_MESSAGE, HIDPP_DEVICE_RECEIVER, 0x07, 0x01 };
r = hid_write(device_handle, data_request, HIDPP_LONG_MESSAGE_LENGTH);
r = hid_write(device_handle, data_request, HIDPP_LONG_MESSAGE_LENGTH);
if (r < 0)
return r;

Expand Down
25 changes: 11 additions & 14 deletions src/devices/logitech_g633_g933_935.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,20 @@ static int g933_935_lights(hid_device* device_handle, uint8_t on);

void g933_935_init(struct device** device)
{
device_g933_935.idVendor = VENDOR_LOGITECH;
device_g933_935.idVendor = VENDOR_LOGITECH;
device_g933_935.idProductsSupported = PRODUCT_IDS;
device_g933_935.numIdProducts = sizeof(PRODUCT_IDS) / sizeof(PRODUCT_IDS[0]);
device_g933_935.numIdProducts = sizeof(PRODUCT_IDS) / sizeof(PRODUCT_IDS[0]);
strncpy(device_g933_935.device_name, "Logitech G633/G635/G933/G935", sizeof(device_g933_935.device_name));

device_g933_935.capabilities = B(CAP_SIDETONE) | B(CAP_BATTERY_STATUS) | B(CAP_LIGHTS);
/// TODO: usagepages and ids may not be correct for all features
device_g933_935.capability_details[CAP_SIDETONE] = (struct capability_detail)
{ .usagepage = 0xff43, .usageid = 0x0202 };
device_g933_935.capability_details[CAP_BATTERY_STATUS] = (struct capability_detail)
{ .usagepage = 0xff43, .usageid = 0x0202 };
device_g933_935.capability_details[CAP_LIGHTS] = (struct capability_detail)
{ .usagepage = 0xff43, .usageid = 0x0202 };

device_g933_935.send_sidetone = &g933_935_send_sidetone;
device_g933_935.capability_details[CAP_SIDETONE] = (struct capability_detail) { .usagepage = 0xff43, .usageid = 0x0202 };
device_g933_935.capability_details[CAP_BATTERY_STATUS] = (struct capability_detail) { .usagepage = 0xff43, .usageid = 0x0202 };
device_g933_935.capability_details[CAP_LIGHTS] = (struct capability_detail) { .usagepage = 0xff43, .usageid = 0x0202 };

device_g933_935.send_sidetone = &g933_935_send_sidetone;
device_g933_935.request_battery = &g933_935_request_battery;
device_g933_935.switch_lights = &g933_935_lights;
device_g933_935.switch_lights = &g933_935_lights;

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

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 };
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 };
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 };
int res;
res = hid_write(device_handle, on ? data_on : data_off, HIDPP_LONG_MESSAGE_LENGTH);
Expand All @@ -124,9 +121,9 @@ static int g933_935_lights(hid_device* device_handle, uint8_t on)
// TODO Investigate further.
usleep(1 * 1000); // wait before next request, otherwise device ignores one of them, on windows at least.
// turn logo lights on/off
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 };
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 };
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 };
res = hid_write(device_handle, on ? data_logo_on : data_logo_off, HIDPP_LONG_MESSAGE_LENGTH);
res = hid_write(device_handle, on ? data_logo_on : data_logo_off, HIDPP_LONG_MESSAGE_LENGTH);

return res;
}
12 changes: 5 additions & 7 deletions src/devices/logitech_g930.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,18 @@ static int g930_request_battery(hid_device* device_handle);

void g930_init(struct device** device)
{
device_g930.idVendor = VENDOR_LOGITECH;
device_g930.idVendor = VENDOR_LOGITECH;
device_g930.idProductsSupported = &PRODUCT_ID;
device_g930.numIdProducts = 1;
device_g930.numIdProducts = 1;

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

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

device_g930.send_sidetone = &g930_send_sidetone;
device_g930.send_sidetone = &g930_send_sidetone;
device_g930.request_battery = &g930_request_battery;

*device = &device_g930;
Expand Down
6 changes: 3 additions & 3 deletions src/devices/logitech_gpro.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ static int gpro_send_sidetone(hid_device* device_handle, uint8_t num);

void gpro_init(struct device** device)
{
device_gpro.idVendor = VENDOR_LOGITECH;
device_gpro.idVendor = VENDOR_LOGITECH;
device_gpro.idProductsSupported = PRODUCT_IDS;
device_gpro.numIdProducts = sizeof(PRODUCT_IDS) / sizeof(PRODUCT_IDS[0]);
device_gpro.numIdProducts = sizeof(PRODUCT_IDS) / sizeof(PRODUCT_IDS[0]);

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

device_gpro.capabilities = B(CAP_SIDETONE);
device_gpro.capabilities = B(CAP_SIDETONE);
device_gpro.send_sidetone = &gpro_send_sidetone;

*device = &device_gpro;
Expand Down
12 changes: 6 additions & 6 deletions src/devices/logitech_zone_wired.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ static int zone_wired_switch_rotate_to_mute(hid_device* device_handle, uint8_t o

void zone_wired_init(struct device** device)
{
device_zone_wired.idVendor = VENDOR_LOGITECH;
device_zone_wired.idVendor = VENDOR_LOGITECH;
device_zone_wired.idProductsSupported = PRODUCT_IDS;
device_zone_wired.numIdProducts = sizeof(PRODUCT_IDS) / sizeof(PRODUCT_IDS[0]);
device_zone_wired.numIdProducts = sizeof(PRODUCT_IDS) / sizeof(PRODUCT_IDS[0]);

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

device_zone_wired.capabilities = B(CAP_SIDETONE) | B(CAP_VOICE_PROMPTS) | B(CAP_ROTATE_TO_MUTE);
device_zone_wired.send_sidetone = &zone_wired_send_sidetone;
device_zone_wired.switch_voice_prompts = &zone_wired_switch_voice_prompts;
device_zone_wired.capabilities = B(CAP_SIDETONE) | B(CAP_VOICE_PROMPTS) | B(CAP_ROTATE_TO_MUTE);
device_zone_wired.send_sidetone = &zone_wired_send_sidetone;
device_zone_wired.switch_voice_prompts = &zone_wired_switch_voice_prompts;
device_zone_wired.switch_rotate_to_mute = &zone_wired_switch_rotate_to_mute;

*device = &device_zone_wired;
Expand All @@ -44,7 +44,7 @@ void zone_wired_init(struct device** device)
static int zone_wired_send_sidetone(hid_device* device_handle, uint8_t num)
{
// The sidetone volume of the Zone Wired is configured in steps of 10%, with 0x00 = 0% and 0x0A = 100%
uint8_t raw_volume = map(num, 0, 128, 0, 10);
uint8_t raw_volume = map(num, 0, 128, 0, 10);
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 };

return hid_send_feature_report(device_handle, data, MSG_SIZE);
Expand Down
Loading

0 comments on commit a183fce

Please sign in to comment.