From d361bcb09fcf96c123804ad713da486c9b4fdc2d Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 21 Aug 2015 10:59:06 +1000 Subject: [PATCH] hidpp22: add a helper to not log some HID++ errors The 2.0 GetProtocolVersion request will fail on 1.0 devices but there is no equivalent for 1.0. The doc even suggests to detect this error to determine whether a device is a 1.0 device. Thus, make it conditional on whether we print the error or not (log it as debug message if turned off). This should be reconsidered when we have everything in place and can think about refacturing. Signed-off-by: Peter Hutterer --- src/hidpp20.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/hidpp20.c b/src/hidpp20.c index de798dc6..6cb90325 100644 --- a/src/hidpp20.c +++ b/src/hidpp20.c @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -78,8 +79,9 @@ hidpp20_write_command(struct ratbag_device *device, uint8_t *cmd, int size) return res; } -int -hidpp20_request_command(struct ratbag_device *device, union hidpp20_message *msg) +static int +hidpp20_request_command_allow_error(struct ratbag_device *device, union hidpp20_message *msg, + bool allow_error) { struct ratbag *ratbag = device->ratbag; union hidpp20_message read_buffer; @@ -128,11 +130,18 @@ hidpp20_request_command(struct ratbag_device *device, union hidpp20_message *msg read_buffer.msg.address == msg->msg.sub_id && read_buffer.msg.parameters[0] == msg->msg.address) { hidpp_err = read_buffer.msg.parameters[1]; - log_error(ratbag, - " HID++ error from the device (%d): %s (%02x)\n", - read_buffer.msg.device_idx, - hidpp_errors[hidpp_err] ? hidpp_errors[hidpp_err] : "Undocumented error code", - hidpp_err); + if (allow_error) + log_debug(ratbag, + " HID++ error from the device (%d): %s (%02x)\n", + read_buffer.msg.device_idx, + hidpp_errors[hidpp_err] ? hidpp_errors[hidpp_err] : "Undocumented error code", + hidpp_err); + else + log_error(ratbag, + " HID++ error from the device (%d): %s (%02x)\n", + read_buffer.msg.device_idx, + hidpp_errors[hidpp_err] ? hidpp_errors[hidpp_err] : "Undocumented error code", + hidpp_err); break; } } while (ret > 0); @@ -155,6 +164,12 @@ out_err: return ret; } +int +hidpp20_request_command(struct ratbag_device *device, union hidpp20_message *msg) +{ + return hidpp20_request_command_allow_error(device, msg, false); +} + static inline uint16_t hidpp20_get_unaligned_u16(uint8_t *buf) { @@ -212,7 +227,7 @@ hidpp20_root_get_protocol_version(struct ratbag_device *device, .msg.address = CMD_ROOT_GET_PROTOCOL_VERSION, }; - rc = hidpp20_request_command(device, &msg); + rc = hidpp20_request_command_allow_error(device, &msg, true); if (rc == ERR_INVALID_SUBID) { *major = 1;