hidpp10: add Leds entry to .device file

For the device I have I do not see a way to get
this information by querying the device.

If the value is set in the .device file it will
override anything that the hidpp10 driver itself
would have found.
This commit is contained in:
Thomas Hindoe Paaboel Andersen
2017-10-01 00:35:50 +02:00
committed by Thomas H. P. Andersen
parent 8edf6e7609
commit a19a79d33a
5 changed files with 40 additions and 2 deletions

View File

@@ -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']

View File

@@ -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

View File

@@ -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,

View File

@@ -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

View File

@@ -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 */
/**