[Bluez-devel] Logitech Cordless Desktop Bluetooth (MX900 + Elite keyboard), bthid and a patch

Vesa Halttunen
2004-06-20T12:53:48Z

[-- Attachment #1: Type: text/plain, Size: 1463 bytes --]

Hi,

I have a Logitech Cordless Desktop Bluetooth (an MX900 mouse and an
Elite keyboard). I've been using them in HCI mode by using hid2hci, hcid
and bthid. This setup has been working somewhat OK but I had a
problem: if I typed specific character sequences very rapidly - the
word "sources", for example, some characters got repeated and so that
"sources" came out as "sourceces". The behaviour was consistent.

Today I took a look at what is causing the problem. By debugging
parser.c I found out that when I type "ces" rapidly the device reports
input events for "c down", "ce down", then 6 times "key 1 down", then
"ce down", then "ces down"... Because the "key 1 down" event got mapped
into "no keys down" it caused the repetition of "ce".

I have no idea what the "key 1 down" event is supposed to be but I wrote
a small hack to get the problem fixed. What I'm doing is use -1 as a
special value for keys_down so that if keys_down == -1 the input event
will be ignored. If a "key 1 down" event is received I ignore the event
by using keys_down = 1.

I don't know if this solution makes any sense with any other keyboard
than this but it seems to work for me - no more duplicate characters.
If anyone knows what the strange "key 1 down" event is and knows a
better way to fix this I'm happy to hear about it. However, a patch
that works for me is attached to this message.

Regards,

-Vesa
--
· Vesa Halttunen - http://www.jormas.com/~vesuri/ ·

[-- Attachment #2: bluez-utils2-hid-parser.c-vesuri-patch.diff --]
[-- Type: text/x-patch, Size: 1473 bytes --]

--- parser.c 2004-06-20 15:30:49.000000000 +0300
+++ parser.c-vesuri 2004-06-20 15:30:24.000000000 +0300
@@ -158,8 +158,8 @@
gst.logical_min,
gst.logical_max,
gst.report_size);
- if (local_ct && (val & RPT_VAR &&
- usage++ == loc[k].usage_max ||
+ if (local_ct && ((val & RPT_VAR &&
+ usage++ == loc[k].usage_max) ||
!(val & RPT_VAR))) {
if (k < local_ct - 1)
k++;
@@ -375,10 +375,14 @@

case 0x0007: /* Keyboard */
//any_keyboard = 1;
- if (val && usage & 0xffff) {
- butt = hid_to_linux[usage & 0xffff];
- if (butt)
- parser->key_down[parser->keys_down++] = butt;
+ if (val && (usage & 0xffff)) {
+ if ((usage & 0xffff) == 1) {
+ parser->keys_down = -1;
+ } else {
+ butt = hid_to_linux[usage & 0xffff];
+ if (butt)
+ parser->key_down[parser->keys_down++] = butt;
+ }
}
return;

@@ -494,7 +498,7 @@
struct hid_report *r = NULL;
struct hid_field *f;
int prev_key_down[32];
- int prev_keys_down;
+ int prev_keys_down = 0;

if (!parser)
return -ENODEV;
@@ -519,9 +523,12 @@
return -EINVAL;
}

- for (i = 0; i < parser->keys_down; i++)
- prev_key_down[i] = parser->key_down[i];
- prev_keys_down = parser->keys_down;
+ if(parser->keys_down >= 0) {
+ for (i = 0; i < parser->keys_down; i++) {
+ prev_key_down[i] = parser->key_down[i];
+ }
+ prev_keys_down = parser->keys_down;
+ }
parser->keys_down = 0;

for (i = 0; i < r->num_fields; i++) {