[PATCH 3/3] hidpp: remove unnecessary HID++ 2.0 code
Peter Wu
lekensteyn at gmail.com
Mon Aug 19 02:53:14 PDT 2013
From: Peter Wu <lekensteyn at gmail.com>
The device name and type can be queried from the receiver which does
not mind if a paired device is using HID++ 2.0 or 1.0. Therefore remove
the hidpp20-specific code which also removes indirection of an
uninitialised "map" variable.
The following code was buggy:
msg.feature_idx = map->idx;
...
map = ...;
if (map != NULL) {
...
}
...
priv->model = ...;
It should have become:
map = ...;
if (map != NULL) {
...
priv->model = ...;
}
... but since the HID++ 2.0 code is not necessary, just remove it.
Signed-off-by: Peter Wu <lekensteyn at gmail.com>
---
src/linux/hidpp-device.c | 79 +++---------------------------------------------
1 file changed, 5 insertions(+), 74 deletions(-)
diff --git a/src/linux/hidpp-device.c b/src/linux/hidpp-device.c
index 7866482..4948355 100644
--- a/src/linux/hidpp-device.c
+++ b/src/linux/hidpp-device.c
@@ -575,7 +575,6 @@ hidpp_device_refresh (HidppDevice *device,
gboolean ret = TRUE;
GString *name = NULL;
HidppMessage msg = { };
- guint i;
guint len;
HidppDevicePrivate *priv = device->priv;
guchar error_code = 0;
@@ -660,9 +659,9 @@ hidpp_device_refresh (HidppDevice *device,
// hidpp_device_map_add (device,
// HIDPP_FEATURE_I_FIRMWARE_INFO,
// "IFirmwareInfo");
- hidpp_device_map_add (device,
- HIDPP_FEATURE_GET_DEVICE_NAME_TYPE,
- "GetDeviceNameType");
+// hidpp_device_map_add (device,
+// HIDPP_FEATURE_GET_DEVICE_NAME_TYPE,
+// "GetDeviceNameType");
hidpp_device_map_add (device,
HIDPP_FEATURE_BATTERY_LEVEL_STATUS,
"BatteryLevelStatus");
@@ -680,7 +679,7 @@ hidpp_device_refresh (HidppDevice *device,
/* the device type can always be queried using HID++ 1.0 on the
* receiver, regardless of the device version. */
- if (priv->version <= 1) {
+ if (priv->version <= 1 || priv->version == 2) {
msg.type = HIDPP_MSG_TYPE_SHORT;
msg.device_idx = HIDPP_RECEIVER_ADDRESS;
msg.feature_idx = HIDPP_READ_LONG_REGISTER;
@@ -714,40 +713,6 @@ hidpp_device_refresh (HidppDevice *device,
priv->kind = HIDPP_DEVICE_KIND_UNKNOWN;
break;
}
- } else if (priv->version == 2) {
-
- /* send a BatteryLevelStatus report */
- map = hidpp_device_map_get_by_feature (device, HIDPP_FEATURE_GET_DEVICE_NAME_TYPE);
- if (map != NULL) {
- msg.type = HIDPP_MSG_TYPE_SHORT;
- msg.device_idx = priv->device_idx;
- msg.feature_idx = map->idx;
- msg.function_idx = HIDPP_FEATURE_GET_DEVICE_NAME_TYPE_FN_GET_TYPE;
- msg.s.params[0] = 0x00;
- msg.s.params[1] = 0x00;
- msg.s.params[2] = 0x00;
- ret = hidpp_device_cmd (device,
- &msg, &msg,
- error);
- if (!ret)
- goto out;
- switch (msg.s.params[0]) {
- case 0: /* keyboard */
- case 2: /* numpad */
- priv->kind = HIDPP_DEVICE_KIND_KEYBOARD;
- break;
- case 3: /* mouse */
- case 4: /* touchpad */
- case 5: /* trackball */
- priv->kind = HIDPP_DEVICE_KIND_MOUSE;
- break;
- case 1: /* remote-control */
- case 6: /* presenter */
- case 7: /* receiver */
- priv->kind = HIDPP_DEVICE_KIND_UNKNOWN;
- break;
- }
- }
}
}
@@ -755,7 +720,7 @@ hidpp_device_refresh (HidppDevice *device,
if ((refresh_flags & HIDPP_REFRESH_FLAGS_MODEL) > 0) {
/* the device name can always be queried using HID++ 1.0 on the
* receiver, regardless of the device version. */
- if (priv->version <= 1) {
+ if (priv->version <= 1 || priv->version == 2) {
msg.type = HIDPP_MSG_TYPE_SHORT;
msg.device_idx = HIDPP_RECEIVER_ADDRESS;
msg.feature_idx = HIDPP_READ_LONG_REGISTER;
@@ -774,40 +739,6 @@ hidpp_device_refresh (HidppDevice *device,
name = g_string_new ("");
g_string_append_len (name, msg.l.params + 2, len);
priv->model = g_strdup (name->str);
- } else if (priv->version == 2) {
- msg.type = HIDPP_MSG_TYPE_SHORT;
- msg.device_idx = priv->device_idx;
- msg.feature_idx = map->idx;
- msg.function_idx = HIDPP_FEATURE_GET_DEVICE_NAME_TYPE_FN_GET_COUNT;
- msg.s.params[0] = 0x00;
- msg.s.params[1] = 0x00;
- msg.s.params[2] = 0x00;
- map = hidpp_device_map_get_by_feature (device, HIDPP_FEATURE_GET_DEVICE_NAME_TYPE);
- if (map != NULL) {
- ret = hidpp_device_cmd (device,
- &msg, &msg,
- error);
- if (!ret)
- goto out;
- }
- len = msg.s.params[0];
- name = g_string_new ("");
- for (i = 0; i < len; i +=4 ) {
- msg.type = HIDPP_MSG_TYPE_SHORT;
- msg.device_idx = priv->device_idx;
- msg.feature_idx = map->idx;
- msg.function_idx = HIDPP_FEATURE_GET_DEVICE_NAME_TYPE_FN_GET_NAME;
- msg.s.params[0] = i;
- msg.s.params[1] = 0x00;
- msg.s.params[2] = 0x00;
- ret = hidpp_device_cmd (device,
- &msg, &msg,
- error);
- if (!ret)
- goto out;
- g_string_append_len (name, msg.s.params, 4);
- }
- priv->model = g_strdup (name->str);
}
}
--
1.8.3.4
More information about the devkit-devel
mailing list