From a757180d60930d333c0b397985de51e64f7edf9e Mon Sep 17 00:00:00 2001 From: Yaroslav Chvanov Date: Mon, 24 Jan 2022 16:49:48 +0300 Subject: [PATCH] sinowealth: detect LED count at run-time --- src/driver-sinowealth.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/driver-sinowealth.c b/src/driver-sinowealth.c index d2720497..9ae27fc5 100644 --- a/src/driver-sinowealth.c +++ b/src/driver-sinowealth.c @@ -71,7 +71,13 @@ enum rgb_effect { RGB_BREATHING1 = 0xa, /* single color breathing */ RGB_TAIL = 0x4, RGB_RAVE = 0x7, - RGB_WAVE = 0x9 + RGB_WAVE = 0x9, + + /* The value mice with no LEDs have. + * Unreliable as non-constant. + * Do **not** overwrite it. + */ + RGB_NOT_SUPPORTED = 0xff, }; struct sinowealth_config_report { @@ -145,6 +151,7 @@ _Static_assert(sizeof(struct sinowealth_config_report) == SINOWEALTH_CONFIG_SIZE struct sinowealth_data { bool is_long; unsigned int config_size; + unsigned int led_count; struct sinowealth_config_report config; }; @@ -383,6 +390,9 @@ sinowealth_init_profile(struct ratbag_device *device) struct ratbag_resolution *resolution; struct ratbag_led *led; + struct sinowealth_data *drv_data = device->drv_data; + struct sinowealth_config_report *config = &drv_data->config; + rc = sinowealth_print_fw_version(device); if (rc) return rc; @@ -391,6 +401,15 @@ sinowealth_init_profile(struct ratbag_device *device) if (rc) return rc; + /* LED count. */ + drv_data->led_count = 0; + if (config->rgb_effect != RGB_NOT_SUPPORTED) { + drv_data->led_count += 1; + } + /* We may want to account for the DPI LEDs in the future. + * We don't support them yet, so it's not a priority now. + */ + /* number of DPIs = all DPIs from min to max (inclusive) and "0 DPI" as a special value * to signal a disabled DPI step. */