diff --git a/data/devices/data-parse-test.py b/data/devices/data-parse-test.py index 52fcee89..fd1108ea 100755 --- a/data/devices/data-parse-test.py +++ b/data/devices/data-parse-test.py @@ -120,7 +120,7 @@ def check_profile_type_str(string): def check_section_hidpp10(section): - permitted = ['Profiles', 'ProfileType', 'DpiRange', 'DpiList', 'DeviceIndex'] + permitted = ['Profiles', 'ProfileType', 'DpiRange', 'DpiList', 'DeviceIndex', 'Leds'] for key in section.keys(): assert(key in permitted) @@ -155,6 +155,13 @@ def check_section_hidpp10(section): except KeyError: pass + try: + leds = int(section['Leds']) + # 10 is arbitrarily chosen + assert(leds > 0 and leds < 10) + except KeyError: + pass + def check_section_hidpp20(section): permitted = ['DeviceIndex'] diff --git a/data/devices/device.example b/data/devices/device.example index 3f34e4c9..ddda1667 100644 --- a/data/devices/device.example +++ b/data/devices/device.example @@ -42,6 +42,9 @@ DpiList=50;200;400;800 # Should be unset unless required # DeviceIndex=1 +# The number of LEDs +Leds=1 + [Driver/hidpp20] # The HID++ 2.0 device index diff --git a/src/driver-hidpp10.c b/src/driver-hidpp10.c index c664e175..8050a9a9 100644 --- a/src/driver-hidpp10.c +++ b/src/driver-hidpp10.c @@ -446,7 +446,7 @@ hidpp10drv_write_resolution_dpi(struct hidpp10_profile *p, static int hidpp10drv_fill_from_profile(struct ratbag_device *device, struct hidpp10_device *dev) { - int rc; + int rc, num_leds; struct hidpp10_profile profile = {0}; unsigned int i; @@ -462,6 +462,11 @@ hidpp10drv_fill_from_profile(struct ratbag_device *device, struct hidpp10_device break; } + /* let the .device file override LED count from the profile */ + num_leds = ratbag_device_data_hidpp10_get_led_count(device->data); + if (num_leds >= 0) + profile.num_leds = num_leds; + ratbag_device_init_profiles(device, dev->profile_count, profile.num_dpi_modes, diff --git a/src/libratbag-data.c b/src/libratbag-data.c index c132b1da..504969e7 100644 --- a/src/libratbag-data.c +++ b/src/libratbag-data.c @@ -60,6 +60,7 @@ struct data_hidpp10 { struct dpi_list *dpi_list; struct dpi_range *dpi_range; + int led_count; }; struct ratbag_device_data { @@ -90,6 +91,7 @@ init_data_hidpp10(struct ratbag *ratbag, data->hidpp10.index = -1; data->hidpp10.profile_count = -1; data->hidpp10.profile_type = NULL; + data->hidpp10.led_count = -1; num = g_key_file_get_integer(keyfile, group, "DeviceIndex", &error); if (num != 0 || !error) @@ -104,6 +106,13 @@ init_data_hidpp10(struct ratbag *ratbag, if (error) g_error_free(error); + error = NULL; + num = g_key_file_get_integer(keyfile, group, "Leds", &error); + if (num > 0 || !error) + data->hidpp10.led_count = num; + if (error) + g_error_free(error); + profile_type = g_key_file_get_string(keyfile, group, "ProfileType", NULL); if (profile_type) data->hidpp10.profile_type = profile_type; @@ -400,6 +409,14 @@ ratbag_device_data_hidpp10_get_dpi_range(const struct ratbag_device_data *data) return data->hidpp10.dpi_range; } +int +ratbag_device_data_hidpp10_get_led_count(const struct ratbag_device_data *data) +{ + assert(data->drivertype == HIDPP10); + + return data->hidpp10.led_count; +} + /* HID++ 2.0 */ int diff --git a/src/libratbag-data.h b/src/libratbag-data.h index b5306952..4aa42cf3 100644 --- a/src/libratbag-data.h +++ b/src/libratbag-data.h @@ -65,6 +65,12 @@ ratbag_device_data_hidpp10_get_dpi_list(const struct ratbag_device_data *data); struct dpi_range * ratbag_device_data_hidpp10_get_dpi_range(const struct ratbag_device_data *data); +/** + * @return The led count index or -1 if not set + */ +int +ratbag_device_data_hidpp10_get_led_count(const struct ratbag_device_data *data); + /* HID++ 2.0 */ /**