From e063aa3d2a99b1a3cc2018596db1dfd3781f578a Mon Sep 17 00:00:00 2001 From: Thomas Hindoe Paaboel Andersen Date: Tue, 10 Oct 2017 23:13:54 +0200 Subject: [PATCH] hidpp10: Fix LED read/write With this the LEDs can be read and written on the G9. The G9 is as far as I know the only hid++1.0 mouse with RGB LED. The other mice are monochrome. --- data/devices/logitech-g9.device | 1 + src/driver-hidpp10.c | 45 +++++++++++++++++++++++++++++++++ src/hidpp10.c | 3 +++ 3 files changed, 49 insertions(+) diff --git a/data/devices/logitech-g9.device b/data/devices/logitech-g9.device index fabdee0d..820cbf86 100644 --- a/data/devices/logitech-g9.device +++ b/data/devices/logitech-g9.device @@ -3,6 +3,7 @@ [Device] Name=Logitech G9 DeviceMatch=usb:046d:c048 +LedTypes=dpi Driver=hidpp10 Svg=logitech-g9.svg diff --git a/src/driver-hidpp10.c b/src/driver-hidpp10.c index e50802ba..0ae6af83 100644 --- a/src/driver-hidpp10.c +++ b/src/driver-hidpp10.c @@ -337,6 +337,43 @@ hidpp10drv_write_button(struct hidpp10_profile *profile, return 0; } +static void +hidpp10drv_read_led(struct ratbag_led *led) +{ + struct ratbag_device *device = led->profile->device; + struct hidpp10drv_data *drv_data = ratbag_get_drv_data(device); + struct hidpp10_device *hidpp10 = drv_data->dev; + struct hidpp10_profile profile; + int ret; + + ret = hidpp10_get_profile(hidpp10, led->profile->index, &profile); + if (ret) + return; + + switch (hidpp10->profile_type) { + case HIDPP10_PROFILE_G500: + led->colordepth = RATBAG_LED_COLORDEPTH_RGB_888; + break; + default: + led->colordepth = RATBAG_LED_COLORDEPTH_MONOCHROME; + break; + } + + led->mode = RATBAG_LED_ON; + led->color.red = profile.red; + led->color.green = profile.green; + led->color.blue = profile.blue; +} + +static void +hidpp10drv_write_led(struct hidpp10_profile *profile, + struct ratbag_led *led) +{ + profile->red = led->color.red; + profile->green = led->color.green; + profile->blue = led->color.blue; +} + static int hidpp10drv_set_current_profile(struct ratbag_device *device, unsigned int index) { @@ -351,6 +388,7 @@ hidpp10drv_read_profile(struct ratbag_profile *profile) { struct ratbag_device *device = profile->device; struct ratbag_button *button; + struct ratbag_led *led; struct hidpp10drv_data *drv_data; struct hidpp10_device *hidpp10; struct hidpp10_profile p = {0}; @@ -404,6 +442,9 @@ hidpp10drv_read_profile(struct ratbag_profile *profile) ratbag_profile_for_each_button(profile, button) hidpp10drv_read_button(button); + + ratbag_profile_for_each_led(profile, led) + hidpp10drv_read_led(led); } static int @@ -469,6 +510,7 @@ hidpp10drv_commit(struct ratbag_device *device) struct hidpp10_device *dev = drv_data->dev; struct ratbag_profile *profile; struct ratbag_button *button; + struct ratbag_led *led; struct ratbag_resolution *resolution; struct ratbag_resolution *active_resolution = NULL; struct hidpp10_profile p; @@ -503,6 +545,9 @@ hidpp10drv_commit(struct ratbag_device *device) return RATBAG_ERROR_DEVICE; } + ratbag_profile_for_each_led(profile, led) + hidpp10drv_write_led(&p, led); + if (dev->profile_type != HIDPP10_PROFILE_UNKNOWN) { rc = hidpp10_set_profile(dev, profile->index, &p); if (rc) diff --git a/src/hidpp10.c b/src/hidpp10.c index fa1ee39d..b94945db 100644 --- a/src/hidpp10.c +++ b/src/hidpp10.c @@ -1515,6 +1515,9 @@ hidpp10_read_profile(struct hidpp10_device *dev, uint8_t number) hidpp10_fill_buttons(dev, profile, buttons, PROFILE_NUM_BUTTONS); break; case HIDPP10_PROFILE_G9: + profile->red = p9->red; + profile->green = p9->green; + profile->blue = p9->blue; profile->default_dpi_mode = p9->default_dpi_mode; profile->refresh_rate = p9->usb_refresh_rate ? 1000/p9->usb_refresh_rate : 0;