うおーるぼっとをWiiリモコンでコントロールする新しいプログラムです。 以前のものより、Wiiリモコンが早く繋がる様になりました。 It is a program which controls A with the Wii remote. ※ A Bluetooth dongle and a Wii remote control are needed.

Dependencies:   USBHost mbed FATFileSystem mbed-rtos

Committer:
jksoft
Date:
Mon Jun 10 16:01:50 2013 +0000
Revision:
0:fccb789424fc
1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:fccb789424fc 1 /* Copyright (c) 2011, mbed
jksoft 0:fccb789424fc 2 *
jksoft 0:fccb789424fc 3 * Permission is hereby granted, free of charge, to any person obtaining a copy
jksoft 0:fccb789424fc 4 * of this software and associated documentation files (the "Software"), to deal
jksoft 0:fccb789424fc 5 * in the Software without restriction, including without limitation the rights
jksoft 0:fccb789424fc 6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
jksoft 0:fccb789424fc 7 * copies of the Software, and to permit persons to whom the Software is
jksoft 0:fccb789424fc 8 * furnished to do so, subject to the following conditions:
jksoft 0:fccb789424fc 9 *
jksoft 0:fccb789424fc 10 * The above copyright notice and this permission notice shall be included in
jksoft 0:fccb789424fc 11 * all copies or substantial portions of the Software.
jksoft 0:fccb789424fc 12 *
jksoft 0:fccb789424fc 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jksoft 0:fccb789424fc 14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jksoft 0:fccb789424fc 15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
jksoft 0:fccb789424fc 16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jksoft 0:fccb789424fc 17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jksoft 0:fccb789424fc 18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
jksoft 0:fccb789424fc 19 * THE SOFTWARE.
jksoft 0:fccb789424fc 20 */
jksoft 0:fccb789424fc 21
jksoft 0:fccb789424fc 22 // Simple decode class for Wii Remote data
jksoft 0:fccb789424fc 23
jksoft 0:fccb789424fc 24 #include "Wiimote.h"
jksoft 0:fccb789424fc 25
jksoft 0:fccb789424fc 26 // Wii Report Formats:
jksoft 0:fccb789424fc 27 // * http://wiibrew.org/wiki/Wiimote#0x37:_Core_Buttons_and_Accelerometer_with_10_IR_bytes_and_6_Extension_Bytes
jksoft 0:fccb789424fc 28 // * http://wiki.wiimoteproject.com/Reports#0x37_BTN_.2B_XLR_.2B_IR_.2B_6_EXT
jksoft 0:fccb789424fc 29
jksoft 0:fccb789424fc 30 // Input Report 0x37:
jksoft 0:fccb789424fc 31 //
jksoft 0:fccb789424fc 32 // 0 [ ? | X(1:0) | PLUS | UP | DOWN | RIGHT | LEFT ]
jksoft 0:fccb789424fc 33 // 1 [ HOME | Z(1) | Y(1) | MINUS | A | B | ONE | TWO ]
jksoft 0:fccb789424fc 34 // 2 [ X(9:2) ]
jksoft 0:fccb789424fc 35 // 3 [ Y(9:2) ]
jksoft 0:fccb789424fc 36 // 4 [ Z(9:2) ]
jksoft 0:fccb789424fc 37 //
jksoft 0:fccb789424fc 38
jksoft 0:fccb789424fc 39 #include <stdio.h>
jksoft 0:fccb789424fc 40 #include <math.h>
jksoft 0:fccb789424fc 41
jksoft 0:fccb789424fc 42 #define WII_ZERO 0x206
jksoft 0:fccb789424fc 43 #define WII_1G 0x6A
jksoft 0:fccb789424fc 44
jksoft 0:fccb789424fc 45 void Wiimote::decode(char* data) {
jksoft 0:fccb789424fc 46
jksoft 0:fccb789424fc 47 // read buttons
jksoft 0:fccb789424fc 48 left = (data[0] >> 0) & 0x1;
jksoft 0:fccb789424fc 49 right = (data[0] >> 1) & 0x1;
jksoft 0:fccb789424fc 50 down = (data[0] >> 2) & 0x1;
jksoft 0:fccb789424fc 51 up = (data[0] >> 3) & 0x1;
jksoft 0:fccb789424fc 52 plus = (data[0] >> 4) & 0x1;
jksoft 0:fccb789424fc 53 two = (data[1] >> 0) & 0x1;
jksoft 0:fccb789424fc 54 one = (data[1] >> 1) & 0x1;
jksoft 0:fccb789424fc 55 b = (data[1] >> 2) & 0x1;
jksoft 0:fccb789424fc 56 a = (data[1] >> 3) & 0x1;
jksoft 0:fccb789424fc 57 minus = (data[1] >> 4) & 0x1;
jksoft 0:fccb789424fc 58 home = (data[1] >> 7) & 0x1;
jksoft 0:fccb789424fc 59
jksoft 0:fccb789424fc 60 // read accelerometers
jksoft 0:fccb789424fc 61 rawx = (data[2] << 2) | (data[0] & 0x60) >> 5;
jksoft 0:fccb789424fc 62 rawy = (data[3] << 2) | (data[1] & 0x20) >> 4;
jksoft 0:fccb789424fc 63 rawz = (data[4] << 2) | (data[1] & 0x40) >> 5;
jksoft 0:fccb789424fc 64
jksoft 0:fccb789424fc 65 // calculate accelerometer gravity
jksoft 0:fccb789424fc 66 x = (float)((int)rawx - WII_ZERO) / (float)WII_1G;
jksoft 0:fccb789424fc 67 y = (float)((int)rawy - WII_ZERO) / (float)WII_1G;
jksoft 0:fccb789424fc 68 z = (float)((int)rawz - WII_ZERO) / (float)WII_1G;
jksoft 0:fccb789424fc 69
jksoft 0:fccb789424fc 70 // calculate wheel angle
jksoft 0:fccb789424fc 71 wheel = atan2(-y, -x) * (180.0 / 3.141592);
jksoft 0:fccb789424fc 72 }
jksoft 0:fccb789424fc 73
jksoft 0:fccb789424fc 74 void Wiimote::dump() {
jksoft 0:fccb789424fc 75 printf("%d%d%d%d%d%d%d%d%d%d%d %.3f %.3f %.3f %.2f\n", left, right, down, up, plus, two, one, b, a, minus, home, x, y, z, wheel);
jksoft 0:fccb789424fc 76 }
jksoft 0:fccb789424fc 77
jksoft 0:fccb789424fc 78
jksoft 0:fccb789424fc 79 // Accelerometer data
jksoft 0:fccb789424fc 80 // y-
jksoft 0:fccb789424fc 81 // +---+ +--+
jksoft 0:fccb789424fc 82 // | + | + B
jksoft 0:fccb789424fc 83 // | A | A |
jksoft 0:fccb789424fc 84 // | | | |
jksoft 0:fccb789424fc 85 // x+ | | x- z+ | | z-
jksoft 0:fccb789424fc 86 // | 1 | 1 |
jksoft 0:fccb789424fc 87 // | 2 | 2 |
jksoft 0:fccb789424fc 88 // +---+ +--+
jksoft 0:fccb789424fc 89 // y+
jksoft 0:fccb789424fc 90 //
jksoft 0:fccb789424fc 91 // x+ 0x19B
jksoft 0:fccb789424fc 92 // x0 0x205
jksoft 0:fccb789424fc 93 // x- 0x26E
jksoft 0:fccb789424fc 94 //
jksoft 0:fccb789424fc 95 // y+ 0x19C 0x6A
jksoft 0:fccb789424fc 96 // y0 0x206
jksoft 0:fccb789424fc 97 // y- 0x26E 0x68
jksoft 0:fccb789424fc 98 //
jksoft 0:fccb789424fc 99 // z+ 0x19C
jksoft 0:fccb789424fc 100 // z0 0x208
jksoft 0:fccb789424fc 101 // z- 0x26E