Dependents:   Test_Wiimote

Committer:
bediyap
Date:
Sat Dec 17 06:53:39 2011 +0000
Revision:
2:5c2bfbd63297
Add Wii rumble, led on/off support

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bediyap 2:5c2bfbd63297 1 /* Copyright (c) 2011, mbed
bediyap 2:5c2bfbd63297 2 *
bediyap 2:5c2bfbd63297 3 * Permission is hereby granted, free of charge, to any person obtaining a copy
bediyap 2:5c2bfbd63297 4 * of this software and associated documentation files (the "Software"), to deal
bediyap 2:5c2bfbd63297 5 * in the Software without restriction, including without limitation the rights
bediyap 2:5c2bfbd63297 6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
bediyap 2:5c2bfbd63297 7 * copies of the Software, and to permit persons to whom the Software is
bediyap 2:5c2bfbd63297 8 * furnished to do so, subject to the following conditions:
bediyap 2:5c2bfbd63297 9 *
bediyap 2:5c2bfbd63297 10 * The above copyright notice and this permission notice shall be included in
bediyap 2:5c2bfbd63297 11 * all copies or substantial portions of the Software.
bediyap 2:5c2bfbd63297 12 *
bediyap 2:5c2bfbd63297 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
bediyap 2:5c2bfbd63297 14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
bediyap 2:5c2bfbd63297 15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
bediyap 2:5c2bfbd63297 16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
bediyap 2:5c2bfbd63297 17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
bediyap 2:5c2bfbd63297 18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
bediyap 2:5c2bfbd63297 19 * THE SOFTWARE.
bediyap 2:5c2bfbd63297 20 */
bediyap 2:5c2bfbd63297 21
bediyap 2:5c2bfbd63297 22 // Simple decoder class for Wii Remote data
bediyap 2:5c2bfbd63297 23
bediyap 2:5c2bfbd63297 24 #ifndef WIIMOTE_H
bediyap 2:5c2bfbd63297 25 #define WIIMOTE_H
bediyap 2:5c2bfbd63297 26
bediyap 2:5c2bfbd63297 27 #include <stdint.h>
bediyap 2:5c2bfbd63297 28
bediyap 2:5c2bfbd63297 29 const int WIILED1 = 0x10;
bediyap 2:5c2bfbd63297 30 const int WIILED2 = 0x20;
bediyap 2:5c2bfbd63297 31 const int WIILED3 = 0x40;
bediyap 2:5c2bfbd63297 32 const int WIILED4 = 0x80;
bediyap 2:5c2bfbd63297 33 const int WIIRUMBLE = 0x01;
bediyap 2:5c2bfbd63297 34
bediyap 2:5c2bfbd63297 35 class Wiimote {
bediyap 2:5c2bfbd63297 36
bediyap 2:5c2bfbd63297 37 int _control; // Sockets for control (out) and interrupt (in)
bediyap 2:5c2bfbd63297 38 public:
bediyap 2:5c2bfbd63297 39 Wiimote();
bediyap 2:5c2bfbd63297 40 void setControl(const int& control);
bediyap 2:5c2bfbd63297 41 void decode(char *data);
bediyap 2:5c2bfbd63297 42 void dump();
bediyap 2:5c2bfbd63297 43 void turnOn(const int i);
bediyap 2:5c2bfbd63297 44 void turnOff(const int i);
bediyap 2:5c2bfbd63297 45 void toggle(const int i);
bediyap 2:5c2bfbd63297 46 bool isOn(const int i);
bediyap 2:5c2bfbd63297 47
bediyap 2:5c2bfbd63297 48 // buttons
bediyap 2:5c2bfbd63297 49 uint32_t left:1;
bediyap 2:5c2bfbd63297 50 uint32_t right:1;
bediyap 2:5c2bfbd63297 51 uint32_t down:1;
bediyap 2:5c2bfbd63297 52 uint32_t up:1;
bediyap 2:5c2bfbd63297 53 uint32_t plus:1;
bediyap 2:5c2bfbd63297 54 uint32_t two:1;
bediyap 2:5c2bfbd63297 55 uint32_t one:1;
bediyap 2:5c2bfbd63297 56 uint32_t a:1;
bediyap 2:5c2bfbd63297 57 uint32_t b:1;
bediyap 2:5c2bfbd63297 58 uint32_t minus:1;
bediyap 2:5c2bfbd63297 59 uint32_t home:1;
bediyap 2:5c2bfbd63297 60
bediyap 2:5c2bfbd63297 61 // accelerometers
bediyap 2:5c2bfbd63297 62 uint16_t rawx;
bediyap 2:5c2bfbd63297 63 uint16_t rawy;
bediyap 2:5c2bfbd63297 64 uint16_t rawz;
bediyap 2:5c2bfbd63297 65
bediyap 2:5c2bfbd63297 66 float x;
bediyap 2:5c2bfbd63297 67 float y;
bediyap 2:5c2bfbd63297 68 float z;
bediyap 2:5c2bfbd63297 69 float wheel;
bediyap 2:5c2bfbd63297 70
bediyap 2:5c2bfbd63297 71 // LED, Rumble status
bediyap 2:5c2bfbd63297 72 uint32_t ledRumbleState;
bediyap 2:5c2bfbd63297 73 };
bediyap 2:5c2bfbd63297 74
bediyap 2:5c2bfbd63297 75 #endif
bediyap 2:5c2bfbd63297 76