From 54fa8b6fa4fed2e58cbb3453c1909bd1e227d44a Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Tue, 9 Feb 2016 14:42:45 +0100 Subject: [PATCH] drv-hidpp20: implement set_current_profile() Only enabled for PROFILES_8100. Signed-off-by: Benjamin Tissoires --- src/driver-hidpp20.c | 8 +++++++- src/hidpp20.c | 27 +++++++++++++++++++++++++++ src/hidpp20.h | 10 ++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/driver-hidpp20.c b/src/driver-hidpp20.c index c4ebcf6f..63845ca0 100644 --- a/src/driver-hidpp20.c +++ b/src/driver-hidpp20.c @@ -371,7 +371,12 @@ hidpp20drv_current_profile(struct ratbag_device *device) static int hidpp20drv_set_current_profile(struct ratbag_device *device, unsigned int index) { - return -ENOTSUP; + struct hidpp20drv_data *drv_data = ratbag_get_drv_data((struct ratbag_device *)device); + + if (!(drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100)) + return 0; + + return hidpp20_onboard_profiles_set_current_profile(drv_data->dev, index); } static int @@ -700,6 +705,7 @@ hidpp20drv_init_feature(struct ratbag_device *device, uint16_t feature) drv_data->capabilities |= HIDPP_CAP_ONBOARD_PROFILES_8100; hidpp20drv_set_exported_capability(device, RATBAG_DEVICE_CAP_BUTTON_KEY); hidpp20drv_set_exported_capability(device, RATBAG_DEVICE_CAP_SWITCHABLE_RESOLUTION); + hidpp20drv_set_exported_capability(device, RATBAG_DEVICE_CAP_SWITCHABLE_PROFILE); /* we read the profiles once with an incorect profile index * to get the correct number of supported profiles. */ hidpp20drv_read_onboard_profile(device, 0xffffff); diff --git a/src/hidpp20.c b/src/hidpp20.c index 19e7ab33..cf7e46df 100644 --- a/src/hidpp20.c +++ b/src/hidpp20.c @@ -1101,6 +1101,33 @@ hidpp20_onboard_profiles_get_current_profile(struct hidpp20_device *device) return msg.msg.parameters[1]; } +int +hidpp20_onboard_profiles_set_current_profile(struct hidpp20_device *device, + uint8_t index) +{ + uint8_t feature_index; + int rc; + union hidpp20_message msg = { + .msg.report_id = REPORT_ID_SHORT, + .msg.device_idx = device->index, + .msg.address = CMD_ONBOARD_PROFILES_SET_CURRENT_PROFILE, + .msg.parameters[1] = index + 1, + }; + + feature_index = hidpp_root_get_feature_idx(device, + HIDPP_PAGE_ONBOARD_PROFILES); + if (feature_index == 0) + return -ENOTSUP; + + msg.msg.sub_id = feature_index; + + rc = hidpp20_request_command(device, &msg); + if (rc) + return rc; + + return 0; +} + static int hidpp20_onboard_profiles_initialize(struct hidpp20_device *device, unsigned profile_count, diff --git a/src/hidpp20.h b/src/hidpp20.h index 04a6a7e7..457155ea 100644 --- a/src/hidpp20.h +++ b/src/hidpp20.h @@ -386,6 +386,16 @@ hidpp20_onboard_profiles_destroy(struct hidpp20_device *device, */ int hidpp20_onboard_profiles_get_current_profile(struct hidpp20_device *device); +/** + * Sets the current profile index. + * Indexes are 1-indexed. + * + * return 0 or a negative error. + */ +int +hidpp20_onboard_profiles_set_current_profile(struct hidpp20_device *device, + uint8_t index); + /** * parse a given profile from the mouse and fill in the right profile in * profiles_list.