From 26493aceaf094b508cf637f3f006c01f8338c4d0 Mon Sep 17 00:00:00 2001 From: Thomas Hindoe Paaboel Andersen Date: Tue, 24 Jul 2018 09:24:31 +0200 Subject: [PATCH] G600: fix setting resolution --- src/driver-logitech-g600.c | 53 ++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/src/driver-logitech-g600.c b/src/driver-logitech-g600.c index b9326f17..160edbcf 100644 --- a/src/driver-logitech-g600.c +++ b/src/driver-logitech-g600.c @@ -264,12 +264,29 @@ logitech_g600_get_active_profile_and_resolution(struct ratbag_device *device) return 0; } +static int +logitech_g600_set_current_resolution(struct ratbag_device *device, unsigned int index) +{ + uint8_t buf[] = {LOGITECH_G600_REPORT_ID_SET_ACTIVE, 0x40 | (index << 1), 0x00, 0x00}; + int ret; + + log_debug(device->ratbag, "Setting active resolution to %d\n", index); + + if (index >= LOGITECH_G600_NUM_DPI) + return -EINVAL; + + ret = ratbag_hidraw_raw_request(device, buf[0], buf, sizeof(buf), + HID_FEATURE_REPORT, HID_REQ_SET_REPORT); + + return ret == sizeof(buf) ? 0 : ret; +} + static int logitech_g600_set_active_profile(struct ratbag_device *device, unsigned int index) { struct ratbag_profile *profile; uint8_t buf[] = {LOGITECH_G600_REPORT_ID_SET_ACTIVE, 0x80 | (index << 4), 0x00, 0x00}; - int ret; + int ret, active_resolution = 0; if (index >= LOGITECH_G600_NUM_PROFILES) return -EINVAL; @@ -289,27 +306,19 @@ logitech_g600_set_active_profile(struct ratbag_device *device, unsigned int inde ratbag_profile_for_each_resolution(profile, resolution) { resolution->is_active = resolution->is_default; + + if (resolution->is_active) + active_resolution = resolution->index; } } + ret = logitech_g600_set_current_resolution(device, active_resolution); + if (ret < 0) + return ret; + return 0; } -static int -logitech_g600_set_current_resolution(struct ratbag_device *device, unsigned int index) -{ - uint8_t buf[] = {LOGITECH_G600_REPORT_ID_SET_ACTIVE, 0x40 | (index << 1), 0x00, 0x00}; - int ret; - - if (index >= LOGITECH_G600_NUM_DPI) - return -EINVAL; - - ret = ratbag_hidraw_raw_request(device, buf[0], buf, sizeof(buf), - HID_FEATURE_REPORT, HID_REQ_SET_REPORT); - - return ret == sizeof(buf) ? 0 : ret; -} - static void logitech_g600_read_button(struct ratbag_button *button) { @@ -435,7 +444,7 @@ logitech_g600_read_profile(struct ratbag_profile *profile) resolution->dpi_y = report->dpi[resolution->index] * 50; resolution->hz = 1000 / (report->frequency + 1); resolution->is_default = report->dpi_default - 1U == resolution->index; - resolution->is_active = false; //is set in a separate call + resolution->is_active = resolution->is_default; ratbag_resolution_set_dpi_list_from_range(resolution, LOGITECH_G600_DPI_MIN, @@ -525,7 +534,7 @@ logitech_g600_write_profile(struct ratbag_profile *profile) struct ratbag_led *led; uint8_t *buf; - int rc; + int rc, active_resolution = 0; pdata = &drv_data->profile_data[profile->index]; report = &pdata->report; @@ -537,7 +546,7 @@ logitech_g600_write_profile(struct ratbag_profile *profile) report->dpi_default = resolution->index + 1; if (profile->is_active && resolution->is_active) - logitech_g600_set_current_resolution(device, resolution->index); + active_resolution = resolution->index; /* The same hz is used for all resolutions */ if (resolution->index == 0) @@ -615,6 +624,12 @@ logitech_g600_write_profile(struct ratbag_profile *profile) return rc; } + if (profile->is_active) { + rc = logitech_g600_set_current_resolution(device, active_resolution); + if (rc < 0) + return rc; + } + return 0; }