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