Shinichiro Nakamura
/
Drive2ChoroQ
This is a demonstration of two Choro Q Hybrid cars.
extlib/WiiNunchuck/WiiNunchuckReader.h@0:d825f8dae2be, 2010-11-22 (annotated)
- Committer:
- shintamainjp
- Date:
- Mon Nov 22 12:23:23 2010 +0000
- Revision:
- 0:d825f8dae2be
Initial version.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shintamainjp | 0:d825f8dae2be | 1 | /* |
shintamainjp | 0:d825f8dae2be | 2 | * WiiNunchuckReader. A program allowing the output of one or two |
shintamainjp | 0:d825f8dae2be | 3 | * Wii Nunchucks to be read via I2C and decoded for use, using the mbed |
shintamainjp | 0:d825f8dae2be | 4 | * microcontroller and its associated libraries. |
shintamainjp | 0:d825f8dae2be | 5 | * |
shintamainjp | 0:d825f8dae2be | 6 | * Copyright (C) <2009> Petras Saduikis <petras@petras.co.uk> |
shintamainjp | 0:d825f8dae2be | 7 | * |
shintamainjp | 0:d825f8dae2be | 8 | * This file is part of WiiNunchuckReader. |
shintamainjp | 0:d825f8dae2be | 9 | * |
shintamainjp | 0:d825f8dae2be | 10 | * WiiNunchuckReader is free software: you can redistribute it and/or modify |
shintamainjp | 0:d825f8dae2be | 11 | * it under the terms of the GNU General Public License as published by |
shintamainjp | 0:d825f8dae2be | 12 | * the Free Software Foundation, either version 3 of the License, or |
shintamainjp | 0:d825f8dae2be | 13 | * (at your option) any later version. |
shintamainjp | 0:d825f8dae2be | 14 | * |
shintamainjp | 0:d825f8dae2be | 15 | * WiiNunchuckReader is distributed in the hope that it will be useful, |
shintamainjp | 0:d825f8dae2be | 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
shintamainjp | 0:d825f8dae2be | 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
shintamainjp | 0:d825f8dae2be | 18 | * GNU General Public License for more details. |
shintamainjp | 0:d825f8dae2be | 19 | * |
shintamainjp | 0:d825f8dae2be | 20 | * You should have received a copy of the GNU General Public License |
shintamainjp | 0:d825f8dae2be | 21 | * along with WiiNunchuckReader. If not, see <http://www.gnu.org/licenses/>. |
shintamainjp | 0:d825f8dae2be | 22 | */ |
shintamainjp | 0:d825f8dae2be | 23 | |
shintamainjp | 0:d825f8dae2be | 24 | #ifndef SNATCH59_WIINUNCHUCKREADER_H |
shintamainjp | 0:d825f8dae2be | 25 | #define SNATCH59_WIINUNCHUCKREADER_H |
shintamainjp | 0:d825f8dae2be | 26 | |
shintamainjp | 0:d825f8dae2be | 27 | #include <mbed.h> |
shintamainjp | 0:d825f8dae2be | 28 | #include "WiiNunchuckDefs.h" |
shintamainjp | 0:d825f8dae2be | 29 | |
shintamainjp | 0:d825f8dae2be | 30 | typedef unsigned char BYTE; |
shintamainjp | 0:d825f8dae2be | 31 | |
shintamainjp | 0:d825f8dae2be | 32 | class WiiNunchuckReader { |
shintamainjp | 0:d825f8dae2be | 33 | public: |
shintamainjp | 0:d825f8dae2be | 34 | // constructors |
shintamainjp | 0:d825f8dae2be | 35 | WiiNunchuckReader(PinName sda, PinName scl); |
shintamainjp | 0:d825f8dae2be | 36 | |
shintamainjp | 0:d825f8dae2be | 37 | // functions |
shintamainjp | 0:d825f8dae2be | 38 | void RequestRead(); |
shintamainjp | 0:d825f8dae2be | 39 | |
shintamainjp | 0:d825f8dae2be | 40 | // accessors |
shintamainjp | 0:d825f8dae2be | 41 | int getJoyX() const { |
shintamainjp | 0:d825f8dae2be | 42 | return joyX; |
shintamainjp | 0:d825f8dae2be | 43 | } |
shintamainjp | 0:d825f8dae2be | 44 | int getJoyY() const { |
shintamainjp | 0:d825f8dae2be | 45 | return joyY; |
shintamainjp | 0:d825f8dae2be | 46 | } |
shintamainjp | 0:d825f8dae2be | 47 | int getAccelX() const { |
shintamainjp | 0:d825f8dae2be | 48 | return accelX; |
shintamainjp | 0:d825f8dae2be | 49 | } |
shintamainjp | 0:d825f8dae2be | 50 | int getAccelY() const { |
shintamainjp | 0:d825f8dae2be | 51 | return accelY; |
shintamainjp | 0:d825f8dae2be | 52 | } |
shintamainjp | 0:d825f8dae2be | 53 | int getAccelZ() const { |
shintamainjp | 0:d825f8dae2be | 54 | return accelZ; |
shintamainjp | 0:d825f8dae2be | 55 | } |
shintamainjp | 0:d825f8dae2be | 56 | int getButtonC() const { |
shintamainjp | 0:d825f8dae2be | 57 | return buttonC; |
shintamainjp | 0:d825f8dae2be | 58 | } |
shintamainjp | 0:d825f8dae2be | 59 | int getButtonZ() const { |
shintamainjp | 0:d825f8dae2be | 60 | return buttonZ; |
shintamainjp | 0:d825f8dae2be | 61 | } |
shintamainjp | 0:d825f8dae2be | 62 | int getBufferSize() const { |
shintamainjp | 0:d825f8dae2be | 63 | return sizeof(readBuf); |
shintamainjp | 0:d825f8dae2be | 64 | } |
shintamainjp | 0:d825f8dae2be | 65 | char* getReadBuf() { |
shintamainjp | 0:d825f8dae2be | 66 | return readBuf; |
shintamainjp | 0:d825f8dae2be | 67 | } |
shintamainjp | 0:d825f8dae2be | 68 | |
shintamainjp | 0:d825f8dae2be | 69 | private: |
shintamainjp | 0:d825f8dae2be | 70 | // nunchuck controls states |
shintamainjp | 0:d825f8dae2be | 71 | int joyX; |
shintamainjp | 0:d825f8dae2be | 72 | int joyY; |
shintamainjp | 0:d825f8dae2be | 73 | int accelX; |
shintamainjp | 0:d825f8dae2be | 74 | int accelY; |
shintamainjp | 0:d825f8dae2be | 75 | int accelZ; |
shintamainjp | 0:d825f8dae2be | 76 | int buttonC; |
shintamainjp | 0:d825f8dae2be | 77 | int buttonZ; |
shintamainjp | 0:d825f8dae2be | 78 | |
shintamainjp | 0:d825f8dae2be | 79 | // nunchuck init state |
shintamainjp | 0:d825f8dae2be | 80 | bool nunchuckInit; |
shintamainjp | 0:d825f8dae2be | 81 | |
shintamainjp | 0:d825f8dae2be | 82 | // nunchuck I2C port |
shintamainjp | 0:d825f8dae2be | 83 | I2C nunchuckPort; |
shintamainjp | 0:d825f8dae2be | 84 | |
shintamainjp | 0:d825f8dae2be | 85 | // read data |
shintamainjp | 0:d825f8dae2be | 86 | char readBuf[NUNCHUCK_READLEN]; |
shintamainjp | 0:d825f8dae2be | 87 | |
shintamainjp | 0:d825f8dae2be | 88 | // functions |
shintamainjp | 0:d825f8dae2be | 89 | bool NunchuckInit(); |
shintamainjp | 0:d825f8dae2be | 90 | bool NunchuckRead(); |
shintamainjp | 0:d825f8dae2be | 91 | void NunchuckDecode(); |
shintamainjp | 0:d825f8dae2be | 92 | void DecodeAdditional(); |
shintamainjp | 0:d825f8dae2be | 93 | }; |
shintamainjp | 0:d825f8dae2be | 94 | |
shintamainjp | 0:d825f8dae2be | 95 | #endif |