From 24f7319a6f8c8b560b84dd03f9f1685c76b36cbf Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Tue, 20 Oct 2015 17:23:27 -0400 Subject: [PATCH] hidpp20: read the button count from the mouse When using onboard profiles, it looks like we have the button count. Signed-off-by: Benjamin Tissoires --- src/driver-hidpp20.c | 2 ++ src/hidpp20.c | 37 +++++++++++++++++++++++++++++++++++-- src/hidpp20.h | 1 + 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/driver-hidpp20.c b/src/driver-hidpp20.c index 447689c1..e7cb19d2 100644 --- a/src/driver-hidpp20.c +++ b/src/driver-hidpp20.c @@ -350,6 +350,8 @@ hidpp20drv_read_onboard_profile(struct ratbag_device *device, unsigned index) rc = hidpp20_onboard_profiles_allocate(drv_data->dev, &drv_data->profiles); if (rc < 0) return rc; + + device->num_buttons = drv_data->profiles->num_buttons; } rc = hidpp20_onboard_profiles_read(drv_data->dev, index, drv_data->profiles); diff --git a/src/hidpp20.c b/src/hidpp20.c index 74340299..2e23cc73 100644 --- a/src/hidpp20.c +++ b/src/hidpp20.c @@ -991,6 +991,38 @@ hidpp20_onboard_profiles_get_current_profile(struct hidpp20_device *device, return msg.msg.parameters[1]; } +static int +hidpp20_onboard_profiles_initialize(struct hidpp20_device *device, + unsigned profile_count, + struct hidpp20_profiles *profiles_list) +{ + 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_GET_PROFILES_DESCR, + }; + + 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; + + profiles_list->num_buttons = msg.msg.parameters[5] <= 16 ? msg.msg.parameters[5] : 16; + profiles_list->num_profiles = profile_count; + /* FIXME: actually retrieve the correct values */ + profiles_list->num_modes = 5; + + return 0; +} + int hidpp20_onboard_profiles_allocate(struct hidpp20_device *device, struct hidpp20_profiles **profiles_list) @@ -1021,8 +1053,9 @@ hidpp20_onboard_profiles_allocate(struct hidpp20_device *device, profiles->profiles[i].enabled = d[2]; } - profiles->num_profiles = profile_count; - profiles->num_modes = 5; + hidpp20_onboard_profiles_initialize(device, + profile_count, + profiles); *profiles_list = profiles; diff --git a/src/hidpp20.h b/src/hidpp20.h index c930c032..d136421a 100644 --- a/src/hidpp20.h +++ b/src/hidpp20.h @@ -275,6 +275,7 @@ struct hidpp20_profile { struct hidpp20_profiles { uint8_t num_profiles; + uint8_t num_buttons; uint8_t num_modes; struct hidpp20_profile profiles[5]; };