unifying: Switch to a floating point HID++ version

This commit is contained in:
Richard Hughes 2017-06-28 14:17:30 +01:00
parent 2c1bd0236c
commit 42b6439892
4 changed files with 17 additions and 15 deletions

View File

@ -111,7 +111,7 @@ static gboolean
lu_device_peripheral_fetch_battery_level (LuDevice *device, GError **error)
{
/* try using HID++2.0 */
if (lu_device_get_hidpp_version (device) >= 2) {
if (lu_device_get_hidpp_version (device) >= 2.f) {
guint8 idx;
idx = lu_device_hidpp_feature_get_idx (device, HIDPP_FEATURE_BATTERY_LEVEL_STATUS);
if (idx != 0x00) {
@ -131,7 +131,7 @@ lu_device_peripheral_fetch_battery_level (LuDevice *device, GError **error)
}
/* try HID++1.0 battery mileage */
if (lu_device_get_hidpp_version (device) == 1) {
if (lu_device_get_hidpp_version (device) == 1.f) {
g_autoptr(LuDeviceHidppMsg) msg = lu_device_hidpp_new ();
msg->report_id = HIDPP_REPORT_ID_SHORT;
msg->device_id = lu_device_get_hidpp_id (device);
@ -175,6 +175,7 @@ lu_device_peripheral_fetch_battery_level (LuDevice *device, GError **error)
static gboolean
lu_device_peripheral_ping (LuDevice *device, GError **error)
{
gdouble version;
g_autoptr(GError) error_local = NULL;
g_autoptr(LuDeviceHidppMsg) msg = lu_device_hidpp_new ();
@ -190,7 +191,7 @@ lu_device_peripheral_ping (LuDevice *device, GError **error)
if (g_error_matches (error_local,
G_IO_ERROR,
G_IO_ERROR_NOT_SUPPORTED)) {
lu_device_set_hidpp_version (device, 0x01);
lu_device_set_hidpp_version (device, 1.f);
return TRUE;
}
if (g_error_matches (error_local,
@ -214,8 +215,9 @@ lu_device_peripheral_ping (LuDevice *device, GError **error)
return FALSE;
}
/* FIXME: minor is in msg->data[1] */
lu_device_set_hidpp_version (device, msg->data[0]);
/* format version in BCD format */
version = (gdouble) msg->data[0] + ((gdouble) msg->data[1]) / 100.f;
lu_device_set_hidpp_version (device, version);
/* success */
return TRUE;

View File

@ -159,7 +159,7 @@ lu_device_runtime_open (LuDevice *device, GError **error)
}
/* this only exists with the original HID++1.0 version */
lu_device_set_hidpp_version (device, 1);
lu_device_set_hidpp_version (device, 1.f);
/* we can flash this */
lu_device_add_flag (device, LU_DEVICE_FLAG_CAN_FLASH);

View File

@ -47,7 +47,7 @@ typedef struct
LuDeviceFlags flags;
guint8 hidpp_id;
guint8 battery_level;
guint8 hidpp_version;
gdouble hidpp_version;
GPtrArray *feature_index;
} LuDevicePrivate;
@ -167,7 +167,7 @@ lu_device_to_string (LuDevice *device)
g_string_append_printf (str, "type:\t\t\t%s\n", lu_device_kind_to_string (priv->kind));
flags_str = lu_device_flags_to_string (priv->flags);
g_string_append_printf (str, "flags:\t\t\t%s\n", flags_str);
g_string_append_printf (str, "hidpp-version:\t\t%u\n", priv->hidpp_version);
g_string_append_printf (str, "hidpp-version:\t\t%.2f\n", priv->hidpp_version);
if (priv->hidpp_id != HIDPP_DEVICE_ID_UNSET)
g_string_append_printf (str, "hidpp-id:\t\t0x%02x\n", (guint) priv->hidpp_id);
if (priv->udev_device_fd > 0)
@ -279,7 +279,7 @@ lu_device_hidpp_send (LuDevice *device,
gsize len = lu_device_hidpp_msg_length (msg);
/* only for HID++2.0 */
if (lu_device_get_hidpp_version (device) >= 2)
if (lu_device_get_hidpp_version (device) >= 2.f)
msg->function_id |= FU_DEVICE_UNIFYING_SW_ID;
lu_device_hidpp_dump (device, "host->device", (guint8 *) msg, len);
@ -616,7 +616,7 @@ lu_device_hidpp_transfer (LuDevice *device, LuDeviceHidppMsg *msg, GError **erro
* connected to an HID++ 1.0 receiver, any feature index
* corresponding to an HID++ 1.0 sub-identifier which could be
* sent by the receiver, must be assigned to a dummy feature */
if (lu_device_get_hidpp_version (device) >= 2 &&
if (lu_device_get_hidpp_version (device) >= 2.f &&
lu_device_hidpp_msg_is_hidpp_10 (msg_tmp)) {
g_debug ("ignoring HID++1.0 reply");
continue;
@ -627,7 +627,7 @@ lu_device_hidpp_transfer (LuDevice *device, LuDeviceHidppMsg *msg, GError **erro
return FALSE;
/* not us */
if (lu_device_get_hidpp_version (device) >= 2 &&
if (lu_device_get_hidpp_version (device) >= 2.f &&
(msg->flags & LU_DEVICE_HIDPP_MSG_FLAG_IGNORE_SWID) == 0) {
if (!lu_device_hidpp_msg_check_swid (msg, msg_tmp)) {
g_debug ("ignoring reply with SwId 0x%02i, expected 0x%02i",
@ -730,7 +730,7 @@ lu_device_set_battery_level (LuDevice *device, guint8 percentage)
priv->battery_level = percentage;
}
guint8
gdouble
lu_device_get_hidpp_version (LuDevice *device)
{
LuDevicePrivate *priv = GET_PRIVATE (device);
@ -738,7 +738,7 @@ lu_device_get_hidpp_version (LuDevice *device)
}
void
lu_device_set_hidpp_version (LuDevice *device, guint8 hidpp_version)
lu_device_set_hidpp_version (LuDevice *device, gdouble hidpp_version)
{
LuDevicePrivate *priv = GET_PRIVATE (device);
priv->hidpp_version = hidpp_version;

View File

@ -127,9 +127,9 @@ void lu_device_set_hidpp_id (LuDevice *device,
guint8 lu_device_get_battery_level (LuDevice *device);
void lu_device_set_battery_level (LuDevice *device,
guint8 percentage);
guint8 lu_device_get_hidpp_version (LuDevice *device);
gdouble lu_device_get_hidpp_version (LuDevice *device);
void lu_device_set_hidpp_version (LuDevice *device,
guint8 hidpp_version);
gdouble hidpp_version);
const gchar *lu_device_get_platform_id (LuDevice *device);
void lu_device_set_platform_id (LuDevice *device,
const gchar *platform_id);