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 <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer
2015-08-21 10:59:06 +10:00
parent 25036f6e3b
commit d361bcb09f

View File

@@ -31,6 +31,7 @@
#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
@@ -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;