David Rimer
/
Gigatron_Emulator
A small emulator for the gigatron created for the STM32F746G-DISCO and an NES wii controller
WiiClassicControllerReader/WiiClassicControllerReader.h@1:4c1f3d32fceb, 2020-03-05 (annotated)
- Committer:
- davidr99
- Date:
- Thu Mar 05 01:33:52 2020 +0000
- Revision:
- 1:4c1f3d32fceb
Emulator all one project
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
davidr99 | 1:4c1f3d32fceb | 1 | /* |
davidr99 | 1:4c1f3d32fceb | 2 | * WiiClassicControllerReader. A program allowing the output of one or two |
davidr99 | 1:4c1f3d32fceb | 3 | * Wii Classic Controllers to be read via I2C and decoded for use, using the mbed |
davidr99 | 1:4c1f3d32fceb | 4 | * microcontroller and its associated libraries. |
davidr99 | 1:4c1f3d32fceb | 5 | * |
davidr99 | 1:4c1f3d32fceb | 6 | * Written by Alfredo Guerrero <alfredog83@gmail.com> for the mbedGC open-source |
davidr99 | 1:4c1f3d32fceb | 7 | * game console <http://www.mbedgc.com>. Based on the original code for |
davidr99 | 1:4c1f3d32fceb | 8 | * the WiiNunchuckReader written by Petras Saduikis <petras@petras.co.uk>. |
davidr99 | 1:4c1f3d32fceb | 9 | * |
davidr99 | 1:4c1f3d32fceb | 10 | * This file is part of WiiClassicControllerReader. |
davidr99 | 1:4c1f3d32fceb | 11 | * |
davidr99 | 1:4c1f3d32fceb | 12 | * WiiClassicControllerReader is free software: you can redistribute it and/or modify |
davidr99 | 1:4c1f3d32fceb | 13 | * it under the terms of the GNU General Public License as published by |
davidr99 | 1:4c1f3d32fceb | 14 | * the Free Software Foundation, either version 3 of the License, or |
davidr99 | 1:4c1f3d32fceb | 15 | * (at your option) any later version. |
davidr99 | 1:4c1f3d32fceb | 16 | * |
davidr99 | 1:4c1f3d32fceb | 17 | * WiiClassicControllerReader is distributed in the hope that it will be useful, |
davidr99 | 1:4c1f3d32fceb | 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
davidr99 | 1:4c1f3d32fceb | 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
davidr99 | 1:4c1f3d32fceb | 20 | * GNU General Public License for more details. |
davidr99 | 1:4c1f3d32fceb | 21 | * |
davidr99 | 1:4c1f3d32fceb | 22 | * You can find a copy of the GNU General Public License at <http://www.gnu.org/licenses/>. |
davidr99 | 1:4c1f3d32fceb | 23 | */ |
davidr99 | 1:4c1f3d32fceb | 24 | |
davidr99 | 1:4c1f3d32fceb | 25 | #ifndef ALFREDOG83_WIICLASSICCONTROLLERREADER_H |
davidr99 | 1:4c1f3d32fceb | 26 | #define ALFREDOG83_WIICLASSICCONTROLLERREADER_H |
davidr99 | 1:4c1f3d32fceb | 27 | |
davidr99 | 1:4c1f3d32fceb | 28 | #include <mbed.h> |
davidr99 | 1:4c1f3d32fceb | 29 | #include "WiiClassicControllerDefs.h" |
davidr99 | 1:4c1f3d32fceb | 30 | |
davidr99 | 1:4c1f3d32fceb | 31 | typedef unsigned char BYTE; |
davidr99 | 1:4c1f3d32fceb | 32 | |
davidr99 | 1:4c1f3d32fceb | 33 | class WiiClassicControllerReader |
davidr99 | 1:4c1f3d32fceb | 34 | { |
davidr99 | 1:4c1f3d32fceb | 35 | public: |
davidr99 | 1:4c1f3d32fceb | 36 | // constructors |
davidr99 | 1:4c1f3d32fceb | 37 | WiiClassicControllerReader(PinName sda, PinName scl); |
davidr99 | 1:4c1f3d32fceb | 38 | |
davidr99 | 1:4c1f3d32fceb | 39 | // functions |
davidr99 | 1:4c1f3d32fceb | 40 | void RequestRead(); |
davidr99 | 1:4c1f3d32fceb | 41 | |
davidr99 | 1:4c1f3d32fceb | 42 | // accessors |
davidr99 | 1:4c1f3d32fceb | 43 | int getLJoyX() const { return ljoyX; } |
davidr99 | 1:4c1f3d32fceb | 44 | int getLJoyY() const { return ljoyY; } |
davidr99 | 1:4c1f3d32fceb | 45 | int getRJoyX() const { return rjoyX; } |
davidr99 | 1:4c1f3d32fceb | 46 | int getRJoyY() const { return rjoyY; } |
davidr99 | 1:4c1f3d32fceb | 47 | int getButtonX() const { return buttonX; } |
davidr99 | 1:4c1f3d32fceb | 48 | int getButtonY() const { return buttonY; } |
davidr99 | 1:4c1f3d32fceb | 49 | int getButtonA() const { return buttonA; } |
davidr99 | 1:4c1f3d32fceb | 50 | int getButtonB() const { return buttonB; } |
davidr99 | 1:4c1f3d32fceb | 51 | int getButtonLT() const { return buttonLT; } |
davidr99 | 1:4c1f3d32fceb | 52 | int getButtonRT() const { return buttonRT; } |
davidr99 | 1:4c1f3d32fceb | 53 | int getButtonLC() const { return buttonLC; } |
davidr99 | 1:4c1f3d32fceb | 54 | int getButtonRC() const { return buttonRC; } |
davidr99 | 1:4c1f3d32fceb | 55 | int getButtonZL() const { return buttonZL; } |
davidr99 | 1:4c1f3d32fceb | 56 | int getButtonZR() const { return buttonZR; } |
davidr99 | 1:4c1f3d32fceb | 57 | int getButtonSELECT() const { return buttonSELECT; } |
davidr99 | 1:4c1f3d32fceb | 58 | int getButtonHOME() const { return buttonHOME; } |
davidr99 | 1:4c1f3d32fceb | 59 | int getButtonSTART() const { return buttonSTART; } |
davidr99 | 1:4c1f3d32fceb | 60 | int getButtonDU() const { return buttonDU; } |
davidr99 | 1:4c1f3d32fceb | 61 | int getButtonDD() const { return buttonDD; } |
davidr99 | 1:4c1f3d32fceb | 62 | int getButtonDL() const { return buttonDL; } |
davidr99 | 1:4c1f3d32fceb | 63 | int getButtonDR() const { return buttonDR; } |
davidr99 | 1:4c1f3d32fceb | 64 | int getBufferSize() const { return sizeof(readBuf); } |
davidr99 | 1:4c1f3d32fceb | 65 | char* getReadBuf() { return readBuf; } |
davidr99 | 1:4c1f3d32fceb | 66 | |
davidr99 | 1:4c1f3d32fceb | 67 | bool ControllerWriteCmd(); |
davidr99 | 1:4c1f3d32fceb | 68 | bool ControllerReadCmd(); |
davidr99 | 1:4c1f3d32fceb | 69 | void ControllerDecode(); |
davidr99 | 1:4c1f3d32fceb | 70 | |
davidr99 | 1:4c1f3d32fceb | 71 | private: |
davidr99 | 1:4c1f3d32fceb | 72 | // classic controls states |
davidr99 | 1:4c1f3d32fceb | 73 | int ljoyX; |
davidr99 | 1:4c1f3d32fceb | 74 | int ljoyY; |
davidr99 | 1:4c1f3d32fceb | 75 | int rjoyX; |
davidr99 | 1:4c1f3d32fceb | 76 | int rjoyY; |
davidr99 | 1:4c1f3d32fceb | 77 | int buttonY; |
davidr99 | 1:4c1f3d32fceb | 78 | int buttonX; |
davidr99 | 1:4c1f3d32fceb | 79 | int buttonB; |
davidr99 | 1:4c1f3d32fceb | 80 | int buttonA; |
davidr99 | 1:4c1f3d32fceb | 81 | int buttonLT; |
davidr99 | 1:4c1f3d32fceb | 82 | int buttonRT; |
davidr99 | 1:4c1f3d32fceb | 83 | int buttonLC; |
davidr99 | 1:4c1f3d32fceb | 84 | int buttonRC; |
davidr99 | 1:4c1f3d32fceb | 85 | int buttonZL; |
davidr99 | 1:4c1f3d32fceb | 86 | int buttonZR; |
davidr99 | 1:4c1f3d32fceb | 87 | int buttonSELECT; |
davidr99 | 1:4c1f3d32fceb | 88 | int buttonHOME; |
davidr99 | 1:4c1f3d32fceb | 89 | int buttonSTART; |
davidr99 | 1:4c1f3d32fceb | 90 | int buttonDU; |
davidr99 | 1:4c1f3d32fceb | 91 | int buttonDD; |
davidr99 | 1:4c1f3d32fceb | 92 | int buttonDL; |
davidr99 | 1:4c1f3d32fceb | 93 | int buttonDR; |
davidr99 | 1:4c1f3d32fceb | 94 | |
davidr99 | 1:4c1f3d32fceb | 95 | // classic init state |
davidr99 | 1:4c1f3d32fceb | 96 | bool controllerInit; |
davidr99 | 1:4c1f3d32fceb | 97 | |
davidr99 | 1:4c1f3d32fceb | 98 | // classic I2C port |
davidr99 | 1:4c1f3d32fceb | 99 | I2C controllerPort; |
davidr99 | 1:4c1f3d32fceb | 100 | |
davidr99 | 1:4c1f3d32fceb | 101 | // read data |
davidr99 | 1:4c1f3d32fceb | 102 | char readBuf[CONTROLLER_READLEN]; |
davidr99 | 1:4c1f3d32fceb | 103 | |
davidr99 | 1:4c1f3d32fceb | 104 | // functions |
davidr99 | 1:4c1f3d32fceb | 105 | bool ControllerInit(); |
davidr99 | 1:4c1f3d32fceb | 106 | bool ControllerRead(); |
davidr99 | 1:4c1f3d32fceb | 107 | //void ControllerDecode(); |
davidr99 | 1:4c1f3d32fceb | 108 | }; |
davidr99 | 1:4c1f3d32fceb | 109 | |
davidr99 | 1:4c1f3d32fceb | 110 | #endif |