Library to use Arduino USB host shield on mbed
ArduinoのUSB Host Shield 2.0をmbedで使えるようにしたライブラリです。
大体のコードがArduinoからそのまま移植可能です。
Arduino UNOやMega用のホストシールド以外にもミニサイズのホストシールドでも使用可能です
シールドについて
3.3VのI/O用にシールドの改造が必要になりますがネット上に記事がたくさんあるのでそちらを参考にしてください
接続例
使い方
Arduinoのコードと違うのはUSBのインスタンスの宣言部分のみです。
ピンを自分で指定できるようにしたので使いやすくなりました。
仕様
- Arduinoのmillis関数、micros関数の移植のために内部でTimerクラスを使用しています。
main.cpp
#include "mbed.h" #include <PS3BT.h> #include <usbhub.h> Serial pc(USBTX, USBRX, 115200); //Nucleo f303k8用 USB Usb(A6, A5, A4, A3, A2); // mosi, miso, sclk, ssel, intr BTD Btd(&Usb); PS3BT PS3(&Btd); int main() { bool printAngle = false; if (Usb.Init() == -1) { pc.printf("\r\nOSC did not start"); while (1); // Halt } pc.printf("\r\nPS3 USB Library Started"); while (1) { Usb.Task(); if (PS3.PS3Connected || PS3.PS3NavigationConnected) { if (PS3.getAnalogHat(LeftHatX) > 137 || PS3.getAnalogHat(LeftHatX) < 117 || PS3.getAnalogHat(LeftHatY) > 137 || PS3.getAnalogHat(LeftHatY) < 117 || PS3.getAnalogHat(RightHatX) > 137 || PS3.getAnalogHat(RightHatX) < 117 || PS3.getAnalogHat(RightHatY) > 137 || PS3.getAnalogHat(RightHatY) < 117) { pc.printf("\r\nLeftHatX: %d", PS3.getAnalogHat(LeftHatX)); pc.printf("\tLeftHatY: %d", PS3.getAnalogHat(LeftHatY)); if (PS3.PS3Connected) { // The Navigation controller only have one joystick pc.printf("\tRightHatX: %d", PS3.getAnalogHat(RightHatX)); pc.printf("\tRightHatY: %d", PS3.getAnalogHat(RightHatY)); } } // Analog button values can be read from almost all buttons if (PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) { pc.printf("\r\nL2: %d", PS3.getAnalogButton(L2)); if (!PS3.PS3NavigationConnected) { pc.printf("\tR2: %d", PS3.getAnalogButton(R2)); } } if (PS3.getButtonClick(PS)) { PS3.disconnect(); pc.printf("\r\nPS"); } if (PS3.getButtonClick(TRIANGLE)) pc.printf("\r\nTriangle"); if (PS3.getButtonClick(CIRCLE)) pc.printf("\r\nCircle"); if (PS3.getButtonClick(CROSS)) pc.printf("\r\nCross"); if (PS3.getButtonClick(SQUARE)) pc.printf("\r\nSquare"); if (PS3.getButtonClick(UP)) { pc.printf("\r\nUp"); PS3.setLedOff(); PS3.setLedOn(CONTROLLER_LED4); } if (PS3.getButtonClick(RIGHT)) { pc.printf("\r\nRight"); PS3.setLedOff(); PS3.setLedOn(CONTROLLER_LED1); } if (PS3.getButtonClick(DOWN)) { pc.printf("\r\nDown"); PS3.setLedOff(); PS3.setLedOn(CONTROLLER_LED2); } if (PS3.getButtonClick(LEFT)) { pc.printf("\r\nLeft"); PS3.setLedOff(); PS3.setLedOn(CONTROLLER_LED3); } if (PS3.getButtonClick(L1)) pc.printf("\r\nL1"); if (PS3.getButtonClick(L3)) pc.printf("\r\nL3"); if (PS3.getButtonClick(R1)) pc.printf("\r\nR1"); if (PS3.getButtonClick(R3)) pc.printf("\r\nR3"); if (PS3.getButtonClick(SELECT)) { pc.printf("\r\nSelect - "); PS3.printStatusString(); } if (PS3.getButtonClick(START)) { pc.printf("\r\nStart"); printAngle = !printAngle; } if (printAngle) { pc.printf("\r\nPitch: %.3lf", PS3.getAngle(Pitch)); pc.printf("\tRoll: %.3lf", PS3.getAngle(Roll)); } } else { pc.printf("not connect\n"); } } }
USB_Host/XBOXRECV.h@1:da31140f2a1c, 2020-05-02 (annotated)
- Committer:
- robo_ichinoseki_a
- Date:
- Sat May 02 05:56:48 2020 +0000
- Revision:
- 1:da31140f2a1c
- Parent:
- 0:b1ce54272580
update
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kotakku | 0:b1ce54272580 | 1 | /* Copyright (C) 2012 Kristian Lauszus, TKJ Electronics. All rights reserved. |
kotakku | 0:b1ce54272580 | 2 | |
kotakku | 0:b1ce54272580 | 3 | This software may be distributed and modified under the terms of the GNU |
kotakku | 0:b1ce54272580 | 4 | General Public License version 2 (GPL2) as published by the Free Software |
kotakku | 0:b1ce54272580 | 5 | Foundation and appearing in the file GPL2.TXT included in the packaging of |
kotakku | 0:b1ce54272580 | 6 | this file. Please note that GPL2 Section 2[b] requires that all works based |
kotakku | 0:b1ce54272580 | 7 | on this software must also be made publicly available under the terms of |
kotakku | 0:b1ce54272580 | 8 | the GPL2 ("Copyleft"). |
kotakku | 0:b1ce54272580 | 9 | |
kotakku | 0:b1ce54272580 | 10 | Contact information |
kotakku | 0:b1ce54272580 | 11 | ------------------- |
kotakku | 0:b1ce54272580 | 12 | |
kotakku | 0:b1ce54272580 | 13 | Kristian Lauszus, TKJ Electronics |
kotakku | 0:b1ce54272580 | 14 | Web : http://www.tkjelectronics.com |
kotakku | 0:b1ce54272580 | 15 | e-mail : kristianl@tkjelectronics.com |
kotakku | 0:b1ce54272580 | 16 | |
kotakku | 0:b1ce54272580 | 17 | getBatteryLevel and checkStatus functions made by timstamp.co.uk found using BusHound from Perisoft.net |
kotakku | 0:b1ce54272580 | 18 | */ |
kotakku | 0:b1ce54272580 | 19 | |
kotakku | 0:b1ce54272580 | 20 | #ifndef _xboxrecv_h_ |
kotakku | 0:b1ce54272580 | 21 | #define _xboxrecv_h_ |
kotakku | 0:b1ce54272580 | 22 | |
kotakku | 0:b1ce54272580 | 23 | #include "Usb.h" |
kotakku | 0:b1ce54272580 | 24 | #include "xboxEnums.h" |
kotakku | 0:b1ce54272580 | 25 | |
kotakku | 0:b1ce54272580 | 26 | /* Data Xbox 360 taken from descriptors */ |
kotakku | 0:b1ce54272580 | 27 | #define EP_MAXPKTSIZE 32 // max size for data via USB |
kotakku | 0:b1ce54272580 | 28 | |
kotakku | 0:b1ce54272580 | 29 | /* Names we give to the 9 Xbox360 pipes */ |
kotakku | 0:b1ce54272580 | 30 | #define XBOX_CONTROL_PIPE 0 |
kotakku | 0:b1ce54272580 | 31 | #define XBOX_INPUT_PIPE_1 1 |
kotakku | 0:b1ce54272580 | 32 | #define XBOX_OUTPUT_PIPE_1 2 |
kotakku | 0:b1ce54272580 | 33 | #define XBOX_INPUT_PIPE_2 3 |
kotakku | 0:b1ce54272580 | 34 | #define XBOX_OUTPUT_PIPE_2 4 |
kotakku | 0:b1ce54272580 | 35 | #define XBOX_INPUT_PIPE_3 5 |
kotakku | 0:b1ce54272580 | 36 | #define XBOX_OUTPUT_PIPE_3 6 |
kotakku | 0:b1ce54272580 | 37 | #define XBOX_INPUT_PIPE_4 7 |
kotakku | 0:b1ce54272580 | 38 | #define XBOX_OUTPUT_PIPE_4 8 |
kotakku | 0:b1ce54272580 | 39 | |
kotakku | 0:b1ce54272580 | 40 | // PID and VID of the different devices |
kotakku | 0:b1ce54272580 | 41 | #define XBOX_VID 0x045E // Microsoft Corporation |
kotakku | 0:b1ce54272580 | 42 | #define MADCATZ_VID 0x1BAD // For unofficial Mad Catz receivers |
kotakku | 0:b1ce54272580 | 43 | #define JOYTECH_VID 0x162E // For unofficial Joytech controllers |
kotakku | 0:b1ce54272580 | 44 | |
kotakku | 0:b1ce54272580 | 45 | #define XBOX_WIRELESS_RECEIVER_PID 0x0719 // Microsoft Wireless Gaming Receiver |
kotakku | 0:b1ce54272580 | 46 | #define XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID 0x0291 // Third party Wireless Gaming Receiver |
kotakku | 0:b1ce54272580 | 47 | |
kotakku | 0:b1ce54272580 | 48 | #define XBOX_MAX_ENDPOINTS 9 |
kotakku | 0:b1ce54272580 | 49 | |
kotakku | 0:b1ce54272580 | 50 | /** |
kotakku | 0:b1ce54272580 | 51 | * This class implements support for a Xbox Wireless receiver. |
kotakku | 0:b1ce54272580 | 52 | * |
kotakku | 0:b1ce54272580 | 53 | * Up to four controllers can connect to one receiver, if more is needed one can use a second receiver via the USBHub class. |
kotakku | 0:b1ce54272580 | 54 | */ |
kotakku | 0:b1ce54272580 | 55 | class XBOXRECV : public USBDeviceConfig { |
kotakku | 0:b1ce54272580 | 56 | public: |
kotakku | 0:b1ce54272580 | 57 | /** |
kotakku | 0:b1ce54272580 | 58 | * Constructor for the XBOXRECV class. |
kotakku | 0:b1ce54272580 | 59 | * @param pUsb Pointer to USB class instance. |
kotakku | 0:b1ce54272580 | 60 | */ |
kotakku | 0:b1ce54272580 | 61 | XBOXRECV(USB *pUsb); |
kotakku | 0:b1ce54272580 | 62 | |
kotakku | 0:b1ce54272580 | 63 | /** @name USBDeviceConfig implementation */ |
kotakku | 0:b1ce54272580 | 64 | /** |
kotakku | 0:b1ce54272580 | 65 | * Address assignment and basic initilization is done here. |
kotakku | 0:b1ce54272580 | 66 | * @param parent Hub number. |
kotakku | 0:b1ce54272580 | 67 | * @param port Port number on the hub. |
kotakku | 0:b1ce54272580 | 68 | * @param lowspeed Speed of the device. |
kotakku | 0:b1ce54272580 | 69 | * @return 0 on success. |
kotakku | 0:b1ce54272580 | 70 | */ |
kotakku | 0:b1ce54272580 | 71 | uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed); |
kotakku | 0:b1ce54272580 | 72 | /** |
kotakku | 0:b1ce54272580 | 73 | * Initialize the Xbox wireless receiver. |
kotakku | 0:b1ce54272580 | 74 | * @param parent Hub number. |
kotakku | 0:b1ce54272580 | 75 | * @param port Port number on the hub. |
kotakku | 0:b1ce54272580 | 76 | * @param lowspeed Speed of the device. |
kotakku | 0:b1ce54272580 | 77 | * @return 0 on success. |
kotakku | 0:b1ce54272580 | 78 | */ |
kotakku | 0:b1ce54272580 | 79 | uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed); |
kotakku | 0:b1ce54272580 | 80 | /** |
kotakku | 0:b1ce54272580 | 81 | * Release the USB device. |
kotakku | 0:b1ce54272580 | 82 | * @return 0 on success. |
kotakku | 0:b1ce54272580 | 83 | */ |
kotakku | 0:b1ce54272580 | 84 | uint8_t Release(); |
kotakku | 0:b1ce54272580 | 85 | /** |
kotakku | 0:b1ce54272580 | 86 | * Poll the USB Input endpoins and run the state machines. |
kotakku | 0:b1ce54272580 | 87 | * @return 0 on success. |
kotakku | 0:b1ce54272580 | 88 | */ |
kotakku | 0:b1ce54272580 | 89 | uint8_t Poll(); |
kotakku | 0:b1ce54272580 | 90 | |
kotakku | 0:b1ce54272580 | 91 | /** |
kotakku | 0:b1ce54272580 | 92 | * Get the device address. |
kotakku | 0:b1ce54272580 | 93 | * @return The device address. |
kotakku | 0:b1ce54272580 | 94 | */ |
kotakku | 0:b1ce54272580 | 95 | virtual uint8_t GetAddress() { |
kotakku | 0:b1ce54272580 | 96 | return bAddress; |
kotakku | 0:b1ce54272580 | 97 | }; |
kotakku | 0:b1ce54272580 | 98 | |
kotakku | 0:b1ce54272580 | 99 | /** |
kotakku | 0:b1ce54272580 | 100 | * Used to check if the controller has been initialized. |
kotakku | 0:b1ce54272580 | 101 | * @return True if it's ready. |
kotakku | 0:b1ce54272580 | 102 | */ |
kotakku | 0:b1ce54272580 | 103 | virtual bool isReady() { |
kotakku | 0:b1ce54272580 | 104 | return bPollEnable; |
kotakku | 0:b1ce54272580 | 105 | }; |
kotakku | 0:b1ce54272580 | 106 | |
kotakku | 0:b1ce54272580 | 107 | /** |
kotakku | 0:b1ce54272580 | 108 | * Used by the USB core to check what this driver support. |
kotakku | 0:b1ce54272580 | 109 | * @param vid The device's VID. |
kotakku | 0:b1ce54272580 | 110 | * @param pid The device's PID. |
kotakku | 0:b1ce54272580 | 111 | * @return Returns true if the device's VID and PID matches this driver. |
kotakku | 0:b1ce54272580 | 112 | */ |
kotakku | 0:b1ce54272580 | 113 | virtual bool VIDPIDOK(uint16_t vid, uint16_t pid) { |
kotakku | 0:b1ce54272580 | 114 | return ((vid == XBOX_VID || vid == MADCATZ_VID || vid == JOYTECH_VID) && (pid == XBOX_WIRELESS_RECEIVER_PID || pid == XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID)); |
kotakku | 0:b1ce54272580 | 115 | }; |
kotakku | 0:b1ce54272580 | 116 | /**@}*/ |
kotakku | 0:b1ce54272580 | 117 | |
kotakku | 0:b1ce54272580 | 118 | /** @name Xbox Controller functions */ |
kotakku | 0:b1ce54272580 | 119 | /** |
kotakku | 0:b1ce54272580 | 120 | * getButtonPress(uint8_t controller, ButtonEnum b) will return true as long as the button is held down. |
kotakku | 0:b1ce54272580 | 121 | * |
kotakku | 0:b1ce54272580 | 122 | * While getButtonClick(uint8_t controller, ButtonEnum b) will only return it once. |
kotakku | 0:b1ce54272580 | 123 | * |
kotakku | 0:b1ce54272580 | 124 | * So you instance if you need to increase a variable once you would use getButtonClick(uint8_t controller, ButtonEnum b), |
kotakku | 0:b1ce54272580 | 125 | * but if you need to drive a robot forward you would use getButtonPress(uint8_t controller, ButtonEnum b). |
kotakku | 0:b1ce54272580 | 126 | * @param b ::ButtonEnum to read. |
kotakku | 0:b1ce54272580 | 127 | * @param controller The controller to read from. Default to 0. |
kotakku | 0:b1ce54272580 | 128 | * @return getButtonClick(uint8_t controller, ButtonEnum b) will return a bool, while getButtonPress(uint8_t controller, ButtonEnum b) will return a byte if reading ::L2 or ::R2. |
kotakku | 0:b1ce54272580 | 129 | */ |
kotakku | 0:b1ce54272580 | 130 | uint8_t getButtonPress(ButtonEnum b, uint8_t controller = 0); |
kotakku | 0:b1ce54272580 | 131 | bool getButtonClick(ButtonEnum b, uint8_t controller = 0); |
kotakku | 0:b1ce54272580 | 132 | /**@}*/ |
kotakku | 0:b1ce54272580 | 133 | |
kotakku | 0:b1ce54272580 | 134 | /** @name Xbox Controller functions */ |
kotakku | 0:b1ce54272580 | 135 | /** |
kotakku | 0:b1ce54272580 | 136 | * Return the analog value from the joysticks on the controller. |
kotakku | 0:b1ce54272580 | 137 | * @param a Either ::LeftHatX, ::LeftHatY, ::RightHatX or ::RightHatY. |
kotakku | 0:b1ce54272580 | 138 | * @param controller The controller to read from. Default to 0. |
kotakku | 0:b1ce54272580 | 139 | * @return Returns a signed 16-bit integer. |
kotakku | 0:b1ce54272580 | 140 | */ |
kotakku | 0:b1ce54272580 | 141 | int16_t getAnalogHat(AnalogHatEnum a, uint8_t controller = 0); |
kotakku | 0:b1ce54272580 | 142 | |
kotakku | 0:b1ce54272580 | 143 | /** |
kotakku | 0:b1ce54272580 | 144 | * Used to disconnect any of the controllers. |
kotakku | 0:b1ce54272580 | 145 | * @param controller The controller to disconnect. Default to 0. |
kotakku | 0:b1ce54272580 | 146 | */ |
kotakku | 0:b1ce54272580 | 147 | void disconnect(uint8_t controller = 0); |
kotakku | 0:b1ce54272580 | 148 | |
kotakku | 0:b1ce54272580 | 149 | /** |
kotakku | 0:b1ce54272580 | 150 | * Turn rumble off and all the LEDs on the specific controller. |
kotakku | 0:b1ce54272580 | 151 | * @param controller The controller to write to. Default to 0. |
kotakku | 0:b1ce54272580 | 152 | */ |
kotakku | 0:b1ce54272580 | 153 | void setAllOff(uint8_t controller = 0) { |
kotakku | 0:b1ce54272580 | 154 | setRumbleOn(0, 0, controller); |
kotakku | 0:b1ce54272580 | 155 | setLedOff(controller); |
kotakku | 0:b1ce54272580 | 156 | }; |
kotakku | 0:b1ce54272580 | 157 | |
kotakku | 0:b1ce54272580 | 158 | /** |
kotakku | 0:b1ce54272580 | 159 | * Turn rumble off the specific controller. |
kotakku | 0:b1ce54272580 | 160 | * @param controller The controller to write to. Default to 0. |
kotakku | 0:b1ce54272580 | 161 | */ |
kotakku | 0:b1ce54272580 | 162 | void setRumbleOff(uint8_t controller = 0) { |
kotakku | 0:b1ce54272580 | 163 | setRumbleOn(0, 0, controller); |
kotakku | 0:b1ce54272580 | 164 | }; |
kotakku | 0:b1ce54272580 | 165 | /** |
kotakku | 0:b1ce54272580 | 166 | * Turn rumble on. |
kotakku | 0:b1ce54272580 | 167 | * @param lValue Left motor (big weight) inside the controller. |
kotakku | 0:b1ce54272580 | 168 | * @param rValue Right motor (small weight) inside the controller. |
kotakku | 0:b1ce54272580 | 169 | * @param controller The controller to write to. Default to 0. |
kotakku | 0:b1ce54272580 | 170 | */ |
kotakku | 0:b1ce54272580 | 171 | void setRumbleOn(uint8_t lValue, uint8_t rValue, uint8_t controller = 0); |
kotakku | 0:b1ce54272580 | 172 | /** |
kotakku | 0:b1ce54272580 | 173 | * Set LED value. Without using the ::LEDEnum or ::LEDModeEnum. |
kotakku | 0:b1ce54272580 | 174 | * @param value See: |
kotakku | 0:b1ce54272580 | 175 | * setLedOff(uint8_t controller), setLedOn(uint8_t controller, LED l), |
kotakku | 0:b1ce54272580 | 176 | * setLedBlink(uint8_t controller, LED l), and setLedMode(uint8_t controller, LEDMode lm). |
kotakku | 0:b1ce54272580 | 177 | * @param controller The controller to write to. Default to 0. |
kotakku | 0:b1ce54272580 | 178 | */ |
kotakku | 0:b1ce54272580 | 179 | void setLedRaw(uint8_t value, uint8_t controller = 0); |
kotakku | 0:b1ce54272580 | 180 | |
kotakku | 0:b1ce54272580 | 181 | /** |
kotakku | 0:b1ce54272580 | 182 | * Turn all LEDs off the specific controller. |
kotakku | 0:b1ce54272580 | 183 | * @param controller The controller to write to. Default to 0. |
kotakku | 0:b1ce54272580 | 184 | */ |
kotakku | 0:b1ce54272580 | 185 | void setLedOff(uint8_t controller = 0) { |
kotakku | 0:b1ce54272580 | 186 | setLedRaw(0, controller); |
kotakku | 0:b1ce54272580 | 187 | }; |
kotakku | 0:b1ce54272580 | 188 | /** |
kotakku | 0:b1ce54272580 | 189 | * Turn on a LED by using ::LEDEnum. |
kotakku | 0:b1ce54272580 | 190 | * @param l ::OFF, ::LED1, ::LED2, ::LED3 and ::LED4 is supported by the Xbox controller. |
kotakku | 0:b1ce54272580 | 191 | * @param controller The controller to write to. Default to 0. |
kotakku | 0:b1ce54272580 | 192 | */ |
kotakku | 0:b1ce54272580 | 193 | void setLedOn(LEDEnum l, uint8_t controller = 0); |
kotakku | 0:b1ce54272580 | 194 | /** |
kotakku | 0:b1ce54272580 | 195 | * Turn on a LED by using ::LEDEnum. |
kotakku | 0:b1ce54272580 | 196 | * @param l ::ALL, ::LED1, ::LED2, ::LED3 and ::LED4 is supported by the Xbox controller. |
kotakku | 0:b1ce54272580 | 197 | * @param controller The controller to write to. Default to 0. |
kotakku | 0:b1ce54272580 | 198 | */ |
kotakku | 0:b1ce54272580 | 199 | void setLedBlink(LEDEnum l, uint8_t controller = 0); |
kotakku | 0:b1ce54272580 | 200 | /** |
kotakku | 0:b1ce54272580 | 201 | * Used to set special LED modes supported by the Xbox controller. |
kotakku | 0:b1ce54272580 | 202 | * @param lm See ::LEDModeEnum. |
kotakku | 0:b1ce54272580 | 203 | * @param controller The controller to write to. Default to 0. |
kotakku | 0:b1ce54272580 | 204 | */ |
kotakku | 0:b1ce54272580 | 205 | void setLedMode(LEDModeEnum lm, uint8_t controller = 0); |
kotakku | 0:b1ce54272580 | 206 | /** |
kotakku | 0:b1ce54272580 | 207 | * Used to get the battery level from the controller. |
kotakku | 0:b1ce54272580 | 208 | * @param controller The controller to read from. Default to 0. |
kotakku | 0:b1ce54272580 | 209 | * @return Returns the battery level as an integer in the range of 0-3. |
kotakku | 0:b1ce54272580 | 210 | */ |
kotakku | 0:b1ce54272580 | 211 | uint8_t getBatteryLevel(uint8_t controller = 0); |
kotakku | 0:b1ce54272580 | 212 | /** |
kotakku | 0:b1ce54272580 | 213 | * Used to check if a button has changed. |
kotakku | 0:b1ce54272580 | 214 | * @param controller The controller to read from. Default to 0. |
kotakku | 0:b1ce54272580 | 215 | * @return True if a button has changed. |
kotakku | 0:b1ce54272580 | 216 | */ |
kotakku | 0:b1ce54272580 | 217 | bool buttonChanged(uint8_t controller = 0); |
kotakku | 0:b1ce54272580 | 218 | |
kotakku | 0:b1ce54272580 | 219 | /** |
kotakku | 0:b1ce54272580 | 220 | * Used to call your own function when the controller is successfully initialized. |
kotakku | 0:b1ce54272580 | 221 | * @param funcOnInit Function to call. |
kotakku | 0:b1ce54272580 | 222 | */ |
kotakku | 0:b1ce54272580 | 223 | void attachOnInit(void (*funcOnInit)(void)) { |
kotakku | 0:b1ce54272580 | 224 | pFuncOnInit = funcOnInit; |
kotakku | 0:b1ce54272580 | 225 | }; |
kotakku | 0:b1ce54272580 | 226 | /**@}*/ |
kotakku | 0:b1ce54272580 | 227 | |
kotakku | 0:b1ce54272580 | 228 | /** True if a wireless receiver is connected. */ |
kotakku | 0:b1ce54272580 | 229 | bool XboxReceiverConnected; |
kotakku | 0:b1ce54272580 | 230 | /** Variable used to indicate if the XBOX 360 controller is successfully connected. */ |
kotakku | 0:b1ce54272580 | 231 | uint8_t Xbox360Connected[4]; |
kotakku | 0:b1ce54272580 | 232 | |
kotakku | 0:b1ce54272580 | 233 | protected: |
kotakku | 0:b1ce54272580 | 234 | /** Pointer to USB class instance. */ |
kotakku | 0:b1ce54272580 | 235 | USB *pUsb; |
kotakku | 0:b1ce54272580 | 236 | /** Device address. */ |
kotakku | 0:b1ce54272580 | 237 | uint8_t bAddress; |
kotakku | 0:b1ce54272580 | 238 | /** Endpoint info structure. */ |
kotakku | 0:b1ce54272580 | 239 | EpInfo epInfo[XBOX_MAX_ENDPOINTS]; |
kotakku | 0:b1ce54272580 | 240 | |
kotakku | 0:b1ce54272580 | 241 | private: |
kotakku | 0:b1ce54272580 | 242 | /** |
kotakku | 0:b1ce54272580 | 243 | * Called when the controller is successfully initialized. |
kotakku | 0:b1ce54272580 | 244 | * Use attachOnInit(void (*funcOnInit)(void)) to call your own function. |
kotakku | 0:b1ce54272580 | 245 | * This is useful for instance if you want to set the LEDs in a specific way. |
kotakku | 0:b1ce54272580 | 246 | * @param controller The initialized controller. |
kotakku | 0:b1ce54272580 | 247 | */ |
kotakku | 0:b1ce54272580 | 248 | void onInit(uint8_t controller); |
kotakku | 0:b1ce54272580 | 249 | void (*pFuncOnInit)(void); // Pointer to function called in onInit() |
kotakku | 0:b1ce54272580 | 250 | |
kotakku | 0:b1ce54272580 | 251 | bool bPollEnable; |
kotakku | 0:b1ce54272580 | 252 | |
kotakku | 0:b1ce54272580 | 253 | /* Variables to store the buttons */ |
kotakku | 0:b1ce54272580 | 254 | uint32_t ButtonState[4]; |
kotakku | 0:b1ce54272580 | 255 | uint32_t OldButtonState[4]; |
kotakku | 0:b1ce54272580 | 256 | uint16_t ButtonClickState[4]; |
kotakku | 0:b1ce54272580 | 257 | int16_t hatValue[4][4]; |
kotakku | 0:b1ce54272580 | 258 | uint16_t controllerStatus[4]; |
kotakku | 0:b1ce54272580 | 259 | bool buttonStateChanged[4]; // True if a button has changed |
kotakku | 0:b1ce54272580 | 260 | |
kotakku | 0:b1ce54272580 | 261 | bool L2Clicked[4]; // These buttons are analog, so we use we use these bools to check if they where clicked or not |
kotakku | 0:b1ce54272580 | 262 | bool R2Clicked[4]; |
kotakku | 0:b1ce54272580 | 263 | |
kotakku | 0:b1ce54272580 | 264 | uint32_t checkStatusTimer; // Timing for checkStatus() signals |
kotakku | 0:b1ce54272580 | 265 | |
kotakku | 0:b1ce54272580 | 266 | uint8_t readBuf[EP_MAXPKTSIZE]; // General purpose buffer for input data |
kotakku | 0:b1ce54272580 | 267 | uint8_t writeBuf[7]; // General purpose buffer for output data |
kotakku | 0:b1ce54272580 | 268 | |
kotakku | 0:b1ce54272580 | 269 | void readReport(uint8_t controller); // read incoming data |
kotakku | 0:b1ce54272580 | 270 | void printReport(uint8_t controller, uint8_t nBytes); // print incoming date - Uncomment for debugging |
kotakku | 0:b1ce54272580 | 271 | |
kotakku | 0:b1ce54272580 | 272 | /* Private commands */ |
kotakku | 0:b1ce54272580 | 273 | void XboxCommand(uint8_t controller, uint8_t* data, uint16_t nbytes); |
kotakku | 0:b1ce54272580 | 274 | void checkStatus(); |
kotakku | 0:b1ce54272580 | 275 | }; |
kotakku | 0:b1ce54272580 | 276 | #endif |
kotakku | 0:b1ce54272580 | 277 |