|
| 1 | +/* |
| 2 | + * Project Teensy XInput Library |
| 3 | + * @author David Madison |
| 4 | + * @link github.com/dmadison/TeensyXInput |
| 5 | + * @license MIT - Copyright (c) 2018 David Madison |
| 6 | + * |
| 7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | + * of this software and associated documentation files (the "Software"), to deal |
| 9 | + * in the Software without restriction, including without limitation the rights |
| 10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | + * copies of the Software, and to permit persons to whom the Software is |
| 12 | + * furnished to do so, subject to the following conditions: |
| 13 | + * |
| 14 | + * The above copyright notice and this permission notice shall be included in |
| 15 | + * all copies or substantial portions of the Software. |
| 16 | + * |
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 | + * THE SOFTWARE. |
| 24 | + * |
| 25 | + * Example: WiiClassicController |
| 26 | + * Description: Maps the inputs from a Wii Classic Controller to an emulated |
| 27 | + * Xbox 360 gamepad using XInput. Requires using the |
| 28 | + * NintendoExtensionCtrl library and an extension adapter. |
| 29 | + */ |
| 30 | + |
| 31 | +#include <XInput.h> |
| 32 | +#include <NintendoExtensionCtrl.h> // Library for the Wii controller communication |
| 33 | + |
| 34 | +ClassicController classic; |
| 35 | + |
| 36 | +void setup() { |
| 37 | + classic.begin(); |
| 38 | + |
| 39 | + while (!classic.connect()) { |
| 40 | + delay(1000); // Controller not connected |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +void loop() { |
| 45 | + if(classic.update()) { // Get new data! |
| 46 | + XInput.setJoystick(JOY_LEFT, map((classic.leftJoyX() << 2), 0, 255, -32768, 32767), map((classic.leftJoyY() << 2), 0, 255, -32768, 32767)); |
| 47 | + XInput.setJoystick(JOY_RIGHT, map((classic.rightJoyX() << 3), 0, 255, -32768, 32767), map((classic.rightJoyY() << 3), 0, 255, -32768, 32767)); |
| 48 | + |
| 49 | + XInput.setButton(BUTTON_A, classic.buttonB()); |
| 50 | + XInput.setButton(BUTTON_B, classic.buttonA()); |
| 51 | + XInput.setButton(BUTTON_X, classic.buttonY()); |
| 52 | + XInput.setButton(BUTTON_Y, classic.buttonX()); |
| 53 | + |
| 54 | + XInput.setButton(BUTTON_START, classic.buttonPlus()); |
| 55 | + XInput.setButton(BUTTON_BACK, classic.buttonMinus()); |
| 56 | + XInput.setButton(BUTTON_LOGO, classic.buttonHome()); |
| 57 | + |
| 58 | + XInput.setDpad(classic.dpadUp(), classic.dpadDown(), classic.dpadLeft(), classic.dpadRight()); |
| 59 | + |
| 60 | + XInput.setTrigger(TRIGGER_LEFT, classic.triggerL() << 3); |
| 61 | + XInput.setTrigger(TRIGGER_RIGHT, classic.triggerR() << 3); |
| 62 | + |
| 63 | + XInput.setButton(BUTTON_LB, classic.buttonZL()); |
| 64 | + XInput.setButton(BUTTON_RB, classic.buttonZR()); |
| 65 | + |
| 66 | + // XInput.setButton(BUTTON_L3, classic.buttonZL()); // The Classic Controller doesn't have L3 and R3 |
| 67 | + // XInput.setButton(BUTTON_R3, classic.buttonZR()); // but you can uncomment these to check that they work |
| 68 | + |
| 69 | + XInput.send(); |
| 70 | + XInput.receive(); |
| 71 | + } |
| 72 | + else { // Data is bad :( |
| 73 | + classic.reconnect(); |
| 74 | + } |
| 75 | +} |
0 commit comments