From: Florian Echtler <floe@butterbrot.org>
To: David Herrmann <dh.herrmann@googlemail.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: Wii Balance Board vs. bluez
Date: Sat, 15 Sep 2012 17:31:08 +0200 [thread overview]
Message-ID: <50549F3C.8050406@butterbrot.org> (raw)
In-Reply-To: <CANq1E4TRWGTdpiXsrR3uUp+n1jtptRnSaOp++LBKqyiRM0=eGg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1697 bytes --]
Hello David,
On 14.09.2012 11:02, David Herrmann wrote:
> On Thu, Sep 13, 2012 at 2:35 PM, Florian Echtler <floe@butterbrot.org> wrote:
>> I've attached an additional patch on top of yours to also read the
>> calibration data (24 bytes at address 0xa40024). Calibration data is applied
>> in handler_balance_board, resulting values are in units of 10 grams.
>> Although this looks correct to me, I'm not getting any events with my patch
>> applied - I suspect some connection to the min/max input values. Do you have
>> any ideas what's wrong?
> Ah, yeah I forgot to change the min/max values of ABS_HAT**. I will
> fix that. The calibration data looks also nice. I have no idea what
> went wrong, but you should definitely initialize it to some sane value
> and fallback to this if you cannot read the data from the device. I
> would also like to split this into two patches. The first one without
> calibration and the second one applies the calibration data.
> I will try to resend these this afternoon, otherwise, I will not have
> time until Sunday afternoon. Sorry.
never mind - I tested my patch again and noticed that the driver wasn't
able to read all 24 calibration bytes in one go, which was the root
cause for not getting any data (I am simply disabling the extension when
not getting proper calibration data).
I fixed this by doing two reads of 12 bytes each instead. I've also
fixed some signedness issues with the data calculation - I've attached
the updated version, which I think should now be ready for integration.
Can you submit both patches to the list when you get around to it (and
have tested it yourself)?
Many thanks!
Florian
--
SENT FROM MY DEC VT50 TERMINAL
[-- Attachment #2: balance_calibration_v2.patch --]
[-- Type: text/x-patch, Size: 2742 bytes --]
diff -u a/hid-wiimote-ext.c b/hid-wiimote-ext.c
--- a/hid-wiimote-ext.c 2012-09-13 21:04:01.600494774 +0200
+++ b/hid-wiimote-ext.c 2012-09-15 17:21:57.292848979 +0200
@@ -28,6 +28,7 @@
bool mp_plugged;
bool motionp;
__u8 ext_type;
+ __u16 calib[4][3];
};
enum wiiext_type {
@@ -127,6 +128,7 @@
static __u8 ext_read(struct wiimote_ext *ext)
{
ssize_t ret;
+ __u8 buf[24], i, j, offs = 0;
__u8 rmem[2], wmem;
__u8 type = WIIEXT_NONE;
@@ -159,6 +161,28 @@
rmem[0], rmem[1]);
}
+ /* get balance board calibration */
+ if (type == WIIEXT_BALANCE_BOARD) {
+
+ /* retrieve 24 bytes of calibration data */
+ /* read requests > 16 do not work => read in two batches */
+ ret = wiimote_cmd_read(ext->wdata, 0xa40024 , buf , 12);
+ ret += wiimote_cmd_read(ext->wdata, 0xa40024+12, buf+12, 12);
+
+ /* failed to read calibration data => disable balance board */
+ if (ret != 24)
+ type = WIIEXT_NONE;
+
+ for ( i = 0; i < 3; i++ ) {
+ for ( j = 0 ; j < 4 ; j++ ) {
+ ext->calib[j][i] = ((__u16)buf[offs]<<8 | (__u16)buf[offs+1]);
+ offs += 2;
+ /* printk("calib[%d][%d] = %d\n",j,i,ext->calib[j][i]); */
+ }
+ }
+
+ }
+
wiimote_cmd_release(ext->wdata);
return type;
@@ -517,7 +541,8 @@
static void handler_balance_board(struct wiimote_ext *ext, const __u8 *payload)
{
- __s16 tr, br, tl, bl;
+ __s32 tmp, val[4]; /* tr, br, tl, bl */
+ __u8 i;
/* Byte | 8 7 6 5 4 3 2 1 |
* -----+--------------------------+
@@ -540,19 +565,24 @@
* The balance-board is never reported interleaved with motionp.
*/
- tr = payload[0] << 8;
- tr |= payload[1];
- br = payload[2] << 8;
- br |= payload[3];
- tl = payload[4] << 8;
- tl |= payload[5];
- bl = payload[6] << 8;
- bl |= payload[7];
-
- input_report_abs(ext->input, ABS_HAT0X, tl);
- input_report_abs(ext->input, ABS_HAT0Y, tr);
- input_report_abs(ext->input, ABS_HAT1X, bl);
- input_report_abs(ext->input, ABS_HAT1Y, br);
+ val[0] = (__u16)payload[0] << 8 | (__u16)payload[1];
+ val[1] = (__u16)payload[2] << 8 | (__u16)payload[3];
+ val[2] = (__u16)payload[4] << 8 | (__u16)payload[5];
+ val[3] = (__u16)payload[6] << 8 | (__u16)payload[7];
+
+ /* apply calibration data */
+ for ( i = 0; i < 4; i++ ) {
+ if (val[i] < ext->calib[i][1])
+ tmp = (1700 * (__s32)(val[i] - ext->calib[i][0])) / (__s32)(ext->calib[i][1] - ext->calib[i][0]);
+ else
+ tmp = (1700 * (__s32)(val[i] - ext->calib[i][1])) / (__s32)(ext->calib[i][2] - ext->calib[i][1]) + 1700;
+ val[i] = tmp;
+ }
+
+ input_report_abs(ext->input, ABS_HAT0X, val[0]);
+ input_report_abs(ext->input, ABS_HAT0Y, val[1]);
+ input_report_abs(ext->input, ABS_HAT1X, val[2]);
+ input_report_abs(ext->input, ABS_HAT1Y, val[3]);
input_sync(ext->input);
}
next prev parent reply other threads:[~2012-09-15 15:31 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-12 20:50 Wii Balance Board vs. bluez Florian Echtler
2012-09-12 21:10 ` David Herrmann
2012-09-13 5:59 ` Florian Echtler
2012-09-13 14:38 ` David Herrmann
2012-09-13 14:39 ` David Herrmann
2012-09-13 21:35 ` Florian Echtler
2012-09-14 9:02 ` David Herrmann
2012-09-15 15:31 ` Florian Echtler [this message]
2012-09-17 9:47 ` David Herrmann
2012-09-17 10:32 ` David Herrmann
2012-09-17 15:01 ` Florian Echtler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50549F3C.8050406@butterbrot.org \
--to=floe@butterbrot.org \
--cc=dh.herrmann@googlemail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).