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/PS3USB.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 | |
kotakku | 0:b1ce54272580 | 18 | #ifndef _ps3usb_h_ |
kotakku | 0:b1ce54272580 | 19 | #define _ps3usb_h_ |
kotakku | 0:b1ce54272580 | 20 | |
kotakku | 0:b1ce54272580 | 21 | #include "Usb.h" |
kotakku | 0:b1ce54272580 | 22 | #include "usbhid.h" |
kotakku | 0:b1ce54272580 | 23 | #include "PS3Enums.h" |
kotakku | 0:b1ce54272580 | 24 | |
kotakku | 0:b1ce54272580 | 25 | /* PS3 data taken from descriptors */ |
kotakku | 0:b1ce54272580 | 26 | #define EP_MAXPKTSIZE 64 // max size for data via USB |
kotakku | 0:b1ce54272580 | 27 | |
kotakku | 0:b1ce54272580 | 28 | /* Names we give to the 3 ps3 pipes - this is only used for setting the bluetooth address into the ps3 controllers */ |
kotakku | 0:b1ce54272580 | 29 | #define PS3_CONTROL_PIPE 0 |
kotakku | 0:b1ce54272580 | 30 | #define PS3_OUTPUT_PIPE 1 |
kotakku | 0:b1ce54272580 | 31 | #define PS3_INPUT_PIPE 2 |
kotakku | 0:b1ce54272580 | 32 | |
kotakku | 0:b1ce54272580 | 33 | //PID and VID of the different devices |
kotakku | 0:b1ce54272580 | 34 | #define PS3_VID 0x054C // Sony Corporation |
kotakku | 0:b1ce54272580 | 35 | #define PS3_PID 0x0268 // PS3 Controller DualShock 3 |
kotakku | 0:b1ce54272580 | 36 | #define PS3NAVIGATION_PID 0x042F // Navigation controller |
kotakku | 0:b1ce54272580 | 37 | #define PS3MOVE_PID 0x03D5 // Motion controller |
kotakku | 0:b1ce54272580 | 38 | |
kotakku | 0:b1ce54272580 | 39 | #define PS3_MAX_ENDPOINTS 3 |
kotakku | 0:b1ce54272580 | 40 | |
kotakku | 0:b1ce54272580 | 41 | /** |
kotakku | 0:b1ce54272580 | 42 | * This class implements support for all the official PS3 Controllers: |
kotakku | 0:b1ce54272580 | 43 | * Dualshock 3, Navigation or a Motion controller via USB. |
kotakku | 0:b1ce54272580 | 44 | * |
kotakku | 0:b1ce54272580 | 45 | * One can only set the color of the bulb, set the rumble, set and get the bluetooth address and calibrate the magnetometer via USB on the Move controller. |
kotakku | 0:b1ce54272580 | 46 | * |
kotakku | 0:b1ce54272580 | 47 | * Information about the protocol can be found at the wiki: https://github.com/felis/USB_Host_Shield_2.0/wiki/PS3-Information. |
kotakku | 0:b1ce54272580 | 48 | */ |
kotakku | 0:b1ce54272580 | 49 | class PS3USB : public USBDeviceConfig { |
kotakku | 0:b1ce54272580 | 50 | public: |
kotakku | 0:b1ce54272580 | 51 | /** |
kotakku | 0:b1ce54272580 | 52 | * Constructor for the PS3USB class. |
kotakku | 0:b1ce54272580 | 53 | * @param pUsb Pointer to USB class instance. |
kotakku | 0:b1ce54272580 | 54 | * @param btadr5,btadr4,btadr3,btadr2,btadr1,btadr0 |
kotakku | 0:b1ce54272580 | 55 | * Pass your dongles Bluetooth address into the constructor, |
kotakku | 0:b1ce54272580 | 56 | * so you are able to pair the controller with a Bluetooth dongle. |
kotakku | 0:b1ce54272580 | 57 | */ |
kotakku | 0:b1ce54272580 | 58 | PS3USB(USB *pUsb, uint8_t btadr5 = 0, uint8_t btadr4 = 0, uint8_t btadr3 = 0, uint8_t btadr2 = 0, uint8_t btadr1 = 0, uint8_t btadr0 = 0); |
kotakku | 0:b1ce54272580 | 59 | |
kotakku | 0:b1ce54272580 | 60 | /** @name USBDeviceConfig implementation */ |
kotakku | 0:b1ce54272580 | 61 | /** |
kotakku | 0:b1ce54272580 | 62 | * Initialize the PS3 Controller. |
kotakku | 0:b1ce54272580 | 63 | * @param parent Hub number. |
kotakku | 0:b1ce54272580 | 64 | * @param port Port number on the hub. |
kotakku | 0:b1ce54272580 | 65 | * @param lowspeed Speed of the device. |
kotakku | 0:b1ce54272580 | 66 | * @return 0 on success. |
kotakku | 0:b1ce54272580 | 67 | */ |
kotakku | 0:b1ce54272580 | 68 | uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed); |
kotakku | 0:b1ce54272580 | 69 | /** |
kotakku | 0:b1ce54272580 | 70 | * Release the USB device. |
kotakku | 0:b1ce54272580 | 71 | * @return 0 on success. |
kotakku | 0:b1ce54272580 | 72 | */ |
kotakku | 0:b1ce54272580 | 73 | uint8_t Release(); |
kotakku | 0:b1ce54272580 | 74 | /** |
kotakku | 0:b1ce54272580 | 75 | * Poll the USB Input endpoins and run the state machines. |
kotakku | 0:b1ce54272580 | 76 | * @return 0 on success. |
kotakku | 0:b1ce54272580 | 77 | */ |
kotakku | 0:b1ce54272580 | 78 | uint8_t Poll(); |
kotakku | 0:b1ce54272580 | 79 | |
kotakku | 0:b1ce54272580 | 80 | /** |
kotakku | 0:b1ce54272580 | 81 | * Get the device address. |
kotakku | 0:b1ce54272580 | 82 | * @return The device address. |
kotakku | 0:b1ce54272580 | 83 | */ |
kotakku | 0:b1ce54272580 | 84 | virtual uint8_t GetAddress() { |
kotakku | 0:b1ce54272580 | 85 | return bAddress; |
kotakku | 0:b1ce54272580 | 86 | }; |
kotakku | 0:b1ce54272580 | 87 | |
kotakku | 0:b1ce54272580 | 88 | /** |
kotakku | 0:b1ce54272580 | 89 | * Used to check if the controller has been initialized. |
kotakku | 0:b1ce54272580 | 90 | * @return True if it's ready. |
kotakku | 0:b1ce54272580 | 91 | */ |
kotakku | 0:b1ce54272580 | 92 | virtual bool isReady() { |
kotakku | 0:b1ce54272580 | 93 | return bPollEnable; |
kotakku | 0:b1ce54272580 | 94 | }; |
kotakku | 0:b1ce54272580 | 95 | |
kotakku | 0:b1ce54272580 | 96 | /** |
kotakku | 0:b1ce54272580 | 97 | * Used by the USB core to check what this driver support. |
kotakku | 0:b1ce54272580 | 98 | * @param vid The device's VID. |
kotakku | 0:b1ce54272580 | 99 | * @param pid The device's PID. |
kotakku | 0:b1ce54272580 | 100 | * @return Returns true if the device's VID and PID matches this driver. |
kotakku | 0:b1ce54272580 | 101 | */ |
kotakku | 0:b1ce54272580 | 102 | virtual bool VIDPIDOK(uint16_t vid, uint16_t pid) { |
kotakku | 0:b1ce54272580 | 103 | return (vid == PS3_VID && (pid == PS3_PID || pid == PS3NAVIGATION_PID || pid == PS3MOVE_PID)); |
kotakku | 0:b1ce54272580 | 104 | }; |
kotakku | 0:b1ce54272580 | 105 | /**@}*/ |
kotakku | 0:b1ce54272580 | 106 | |
kotakku | 0:b1ce54272580 | 107 | /** |
kotakku | 0:b1ce54272580 | 108 | * Used to set the Bluetooth address inside the Dualshock 3 and Navigation controller. |
kotakku | 0:b1ce54272580 | 109 | * Set using LSB first. |
kotakku | 0:b1ce54272580 | 110 | * @param bdaddr Your dongles Bluetooth address. |
kotakku | 0:b1ce54272580 | 111 | */ |
kotakku | 0:b1ce54272580 | 112 | void setBdaddr(uint8_t *bdaddr); |
kotakku | 0:b1ce54272580 | 113 | /** |
kotakku | 0:b1ce54272580 | 114 | * Used to get the Bluetooth address inside the Dualshock 3 and Navigation controller. |
kotakku | 0:b1ce54272580 | 115 | * Will return LSB first. |
kotakku | 0:b1ce54272580 | 116 | * @param bdaddr Your dongles Bluetooth address. |
kotakku | 0:b1ce54272580 | 117 | */ |
kotakku | 0:b1ce54272580 | 118 | void getBdaddr(uint8_t *bdaddr); |
kotakku | 0:b1ce54272580 | 119 | |
kotakku | 0:b1ce54272580 | 120 | /** |
kotakku | 0:b1ce54272580 | 121 | * Used to set the Bluetooth address inside the Move controller. |
kotakku | 0:b1ce54272580 | 122 | * Set using LSB first. |
kotakku | 0:b1ce54272580 | 123 | * @param bdaddr Your dongles Bluetooth address. |
kotakku | 0:b1ce54272580 | 124 | */ |
kotakku | 0:b1ce54272580 | 125 | void setMoveBdaddr(uint8_t *bdaddr); |
kotakku | 0:b1ce54272580 | 126 | /** |
kotakku | 0:b1ce54272580 | 127 | * Used to get the Bluetooth address inside the Move controller. |
kotakku | 0:b1ce54272580 | 128 | * Will return LSB first. |
kotakku | 0:b1ce54272580 | 129 | * @param bdaddr Your dongles Bluetooth address. |
kotakku | 0:b1ce54272580 | 130 | */ |
kotakku | 0:b1ce54272580 | 131 | void getMoveBdaddr(uint8_t *bdaddr); |
kotakku | 0:b1ce54272580 | 132 | /** |
kotakku | 0:b1ce54272580 | 133 | * Used to get the calibration data inside the Move controller. |
kotakku | 0:b1ce54272580 | 134 | * @param data Buffer to store data in. Must be at least 147 bytes |
kotakku | 0:b1ce54272580 | 135 | */ |
kotakku | 0:b1ce54272580 | 136 | void getMoveCalibration(uint8_t *data); |
kotakku | 0:b1ce54272580 | 137 | |
kotakku | 0:b1ce54272580 | 138 | /** @name PS3 Controller functions */ |
kotakku | 0:b1ce54272580 | 139 | /** |
kotakku | 0:b1ce54272580 | 140 | * getButtonPress(ButtonEnum b) will return true as long as the button is held down. |
kotakku | 0:b1ce54272580 | 141 | * |
kotakku | 0:b1ce54272580 | 142 | * While getButtonClick(ButtonEnum b) will only return it once. |
kotakku | 0:b1ce54272580 | 143 | * |
kotakku | 0:b1ce54272580 | 144 | * So you instance if you need to increase a variable once you would use getButtonClick(ButtonEnum b), |
kotakku | 0:b1ce54272580 | 145 | * but if you need to drive a robot forward you would use getButtonPress(ButtonEnum b). |
kotakku | 0:b1ce54272580 | 146 | * @param b ::ButtonEnum to read. |
kotakku | 0:b1ce54272580 | 147 | * @return getButtonPress(ButtonEnum b) will return a true as long as a button is held down, while getButtonClick(ButtonEnum b) will return true once for each button press. |
kotakku | 0:b1ce54272580 | 148 | */ |
kotakku | 0:b1ce54272580 | 149 | bool getButtonPress(ButtonEnum b); |
kotakku | 0:b1ce54272580 | 150 | bool getButtonClick(ButtonEnum b); |
kotakku | 0:b1ce54272580 | 151 | /**@}*/ |
kotakku | 0:b1ce54272580 | 152 | /** @name PS3 Controller functions */ |
kotakku | 0:b1ce54272580 | 153 | /** |
kotakku | 0:b1ce54272580 | 154 | * Used to get the analog value from button presses. |
kotakku | 0:b1ce54272580 | 155 | * @param a The ::ButtonEnum to read. |
kotakku | 0:b1ce54272580 | 156 | * The supported buttons are: |
kotakku | 0:b1ce54272580 | 157 | * ::UP, ::RIGHT, ::DOWN, ::LEFT, ::L1, ::L2, ::R1, ::R2, |
kotakku | 0:b1ce54272580 | 158 | * ::TRIANGLE, ::CIRCLE, ::CROSS, ::SQUARE, and ::T. |
kotakku | 0:b1ce54272580 | 159 | * @return Analog value in the range of 0-255. |
kotakku | 0:b1ce54272580 | 160 | */ |
kotakku | 0:b1ce54272580 | 161 | uint8_t getAnalogButton(ButtonEnum a); |
kotakku | 0:b1ce54272580 | 162 | /** |
kotakku | 0:b1ce54272580 | 163 | * Used to read the analog joystick. |
kotakku | 0:b1ce54272580 | 164 | * @param a ::LeftHatX, ::LeftHatY, ::RightHatX, and ::RightHatY. |
kotakku | 0:b1ce54272580 | 165 | * @return Return the analog value in the range of 0-255. |
kotakku | 0:b1ce54272580 | 166 | */ |
kotakku | 0:b1ce54272580 | 167 | uint8_t getAnalogHat(AnalogHatEnum a); |
kotakku | 0:b1ce54272580 | 168 | /** |
kotakku | 0:b1ce54272580 | 169 | * Used to read the sensors inside the Dualshock 3 controller. |
kotakku | 0:b1ce54272580 | 170 | * @param a |
kotakku | 0:b1ce54272580 | 171 | * The Dualshock 3 has a 3-axis accelerometer and a 1-axis gyro inside. |
kotakku | 0:b1ce54272580 | 172 | * @return Return the raw sensor value. |
kotakku | 0:b1ce54272580 | 173 | */ |
kotakku | 0:b1ce54272580 | 174 | uint16_t getSensor(SensorEnum a); |
kotakku | 0:b1ce54272580 | 175 | /** |
kotakku | 0:b1ce54272580 | 176 | * Use this to get ::Pitch and ::Roll calculated using the accelerometer. |
kotakku | 0:b1ce54272580 | 177 | * @param a Either ::Pitch or ::Roll. |
kotakku | 0:b1ce54272580 | 178 | * @return Return the angle in the range of 0-360. |
kotakku | 0:b1ce54272580 | 179 | */ |
kotakku | 0:b1ce54272580 | 180 | float getAngle(AngleEnum a); |
kotakku | 0:b1ce54272580 | 181 | /** |
kotakku | 0:b1ce54272580 | 182 | * Get the ::StatusEnum from the controller. |
kotakku | 0:b1ce54272580 | 183 | * @param c The ::StatusEnum you want to read. |
kotakku | 0:b1ce54272580 | 184 | * @return True if correct and false if not. |
kotakku | 0:b1ce54272580 | 185 | */ |
kotakku | 0:b1ce54272580 | 186 | bool getStatus(StatusEnum c); |
kotakku | 0:b1ce54272580 | 187 | /** Read all the available statuses from the controller and prints it as a nice formated string. */ |
kotakku | 0:b1ce54272580 | 188 | void printStatusString(); |
kotakku | 0:b1ce54272580 | 189 | |
kotakku | 0:b1ce54272580 | 190 | /** Used to set all LEDs and rumble off. */ |
kotakku | 0:b1ce54272580 | 191 | void setAllOff(); |
kotakku | 0:b1ce54272580 | 192 | /** Turn off rumble. */ |
kotakku | 0:b1ce54272580 | 193 | void setRumbleOff(); |
kotakku | 0:b1ce54272580 | 194 | /** |
kotakku | 0:b1ce54272580 | 195 | * Turn on rumble. |
kotakku | 0:b1ce54272580 | 196 | * @param mode Either ::RumbleHigh or ::RumbleLow. |
kotakku | 0:b1ce54272580 | 197 | */ |
kotakku | 0:b1ce54272580 | 198 | void setRumbleOn(RumbleEnum mode); |
kotakku | 0:b1ce54272580 | 199 | /** |
kotakku | 0:b1ce54272580 | 200 | * Turn on rumble using custom duration and power. |
kotakku | 0:b1ce54272580 | 201 | * @param rightDuration The duration of the right/low rumble effect. |
kotakku | 0:b1ce54272580 | 202 | * @param rightPower The intensity of the right/low rumble effect. |
kotakku | 0:b1ce54272580 | 203 | * @param leftDuration The duration of the left/high rumble effect. |
kotakku | 0:b1ce54272580 | 204 | * @param leftPower The intensity of the left/high rumble effect. |
kotakku | 0:b1ce54272580 | 205 | */ |
kotakku | 0:b1ce54272580 | 206 | void setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower); |
kotakku | 0:b1ce54272580 | 207 | |
kotakku | 0:b1ce54272580 | 208 | /** |
kotakku | 0:b1ce54272580 | 209 | * Set LED value without using the ::LEDEnum. |
kotakku | 0:b1ce54272580 | 210 | * @param value See: ::LEDEnum. |
kotakku | 0:b1ce54272580 | 211 | */ |
kotakku | 0:b1ce54272580 | 212 | void setLedRaw(uint8_t value); |
kotakku | 0:b1ce54272580 | 213 | |
kotakku | 0:b1ce54272580 | 214 | /** Turn all LEDs off. */ |
kotakku | 0:b1ce54272580 | 215 | void setLedOff() { |
kotakku | 0:b1ce54272580 | 216 | setLedRaw(0); |
kotakku | 0:b1ce54272580 | 217 | } |
kotakku | 0:b1ce54272580 | 218 | /** |
kotakku | 0:b1ce54272580 | 219 | * Turn the specific ::LEDEnum off. |
kotakku | 0:b1ce54272580 | 220 | * @param a The ::LEDEnum to turn off. |
kotakku | 0:b1ce54272580 | 221 | */ |
kotakku | 0:b1ce54272580 | 222 | void setLedOff(LEDEnum a); |
kotakku | 0:b1ce54272580 | 223 | /** |
kotakku | 0:b1ce54272580 | 224 | * Turn the specific ::LEDEnum on. |
kotakku | 0:b1ce54272580 | 225 | * @param a The ::LEDEnum to turn on. |
kotakku | 0:b1ce54272580 | 226 | */ |
kotakku | 0:b1ce54272580 | 227 | void setLedOn(LEDEnum a); |
kotakku | 0:b1ce54272580 | 228 | /** |
kotakku | 0:b1ce54272580 | 229 | * Toggle the specific ::LEDEnum. |
kotakku | 0:b1ce54272580 | 230 | * @param a The ::LEDEnum to toggle. |
kotakku | 0:b1ce54272580 | 231 | */ |
kotakku | 0:b1ce54272580 | 232 | void setLedToggle(LEDEnum a); |
kotakku | 0:b1ce54272580 | 233 | |
kotakku | 0:b1ce54272580 | 234 | /** |
kotakku | 0:b1ce54272580 | 235 | * Use this to set the Color using RGB values. |
kotakku | 0:b1ce54272580 | 236 | * @param r,g,b RGB value. |
kotakku | 0:b1ce54272580 | 237 | */ |
kotakku | 0:b1ce54272580 | 238 | void moveSetBulb(uint8_t r, uint8_t g, uint8_t b); |
kotakku | 0:b1ce54272580 | 239 | /** |
kotakku | 0:b1ce54272580 | 240 | * Use this to set the color using the predefined colors in ::ColorsEnum. |
kotakku | 0:b1ce54272580 | 241 | * @param color The desired color. |
kotakku | 0:b1ce54272580 | 242 | */ |
kotakku | 0:b1ce54272580 | 243 | void moveSetBulb(ColorsEnum color); |
kotakku | 0:b1ce54272580 | 244 | /** |
kotakku | 0:b1ce54272580 | 245 | * Set the rumble value inside the Move controller. |
kotakku | 0:b1ce54272580 | 246 | * @param rumble The desired value in the range from 64-255. |
kotakku | 0:b1ce54272580 | 247 | */ |
kotakku | 0:b1ce54272580 | 248 | void moveSetRumble(uint8_t rumble); |
kotakku | 0:b1ce54272580 | 249 | |
kotakku | 0:b1ce54272580 | 250 | /** |
kotakku | 0:b1ce54272580 | 251 | * Used to call your own function when the controller is successfully initialized. |
kotakku | 0:b1ce54272580 | 252 | * @param funcOnInit Function to call. |
kotakku | 0:b1ce54272580 | 253 | */ |
kotakku | 0:b1ce54272580 | 254 | void attachOnInit(void (*funcOnInit)(void)) { |
kotakku | 0:b1ce54272580 | 255 | pFuncOnInit = funcOnInit; |
kotakku | 0:b1ce54272580 | 256 | }; |
kotakku | 0:b1ce54272580 | 257 | /**@}*/ |
kotakku | 0:b1ce54272580 | 258 | |
kotakku | 0:b1ce54272580 | 259 | /** Variable used to indicate if the normal playstation controller is successfully connected. */ |
kotakku | 0:b1ce54272580 | 260 | bool PS3Connected; |
kotakku | 0:b1ce54272580 | 261 | /** Variable used to indicate if the move controller is successfully connected. */ |
kotakku | 0:b1ce54272580 | 262 | bool PS3MoveConnected; |
kotakku | 0:b1ce54272580 | 263 | /** Variable used to indicate if the navigation controller is successfully connected. */ |
kotakku | 0:b1ce54272580 | 264 | bool PS3NavigationConnected; |
kotakku | 0:b1ce54272580 | 265 | |
kotakku | 0:b1ce54272580 | 266 | protected: |
kotakku | 0:b1ce54272580 | 267 | /** Pointer to USB class instance. */ |
kotakku | 0:b1ce54272580 | 268 | USB *pUsb; |
kotakku | 0:b1ce54272580 | 269 | /** Device address. */ |
kotakku | 0:b1ce54272580 | 270 | uint8_t bAddress; |
kotakku | 0:b1ce54272580 | 271 | /** Endpoint info structure. */ |
kotakku | 0:b1ce54272580 | 272 | EpInfo epInfo[PS3_MAX_ENDPOINTS]; |
kotakku | 0:b1ce54272580 | 273 | |
kotakku | 0:b1ce54272580 | 274 | private: |
kotakku | 0:b1ce54272580 | 275 | /** |
kotakku | 0:b1ce54272580 | 276 | * Called when the controller is successfully initialized. |
kotakku | 0:b1ce54272580 | 277 | * Use attachOnInit(void (*funcOnInit)(void)) to call your own function. |
kotakku | 0:b1ce54272580 | 278 | * This is useful for instance if you want to set the LEDs in a specific way. |
kotakku | 0:b1ce54272580 | 279 | */ |
kotakku | 0:b1ce54272580 | 280 | void onInit(); |
kotakku | 0:b1ce54272580 | 281 | void (*pFuncOnInit)(void); // Pointer to function called in onInit() |
kotakku | 0:b1ce54272580 | 282 | |
kotakku | 0:b1ce54272580 | 283 | bool bPollEnable; |
kotakku | 0:b1ce54272580 | 284 | |
kotakku | 0:b1ce54272580 | 285 | uint32_t timer; // used to continuously set PS3 Move controller Bulb and rumble values |
kotakku | 0:b1ce54272580 | 286 | |
kotakku | 0:b1ce54272580 | 287 | uint32_t ButtonState; |
kotakku | 0:b1ce54272580 | 288 | uint32_t OldButtonState; |
kotakku | 0:b1ce54272580 | 289 | uint32_t ButtonClickState; |
kotakku | 0:b1ce54272580 | 290 | |
kotakku | 0:b1ce54272580 | 291 | uint8_t my_bdaddr[6]; // Change to your dongles Bluetooth address in the constructor |
kotakku | 0:b1ce54272580 | 292 | uint8_t readBuf[EP_MAXPKTSIZE]; // General purpose buffer for input data |
kotakku | 0:b1ce54272580 | 293 | uint8_t writeBuf[EP_MAXPKTSIZE]; // General purpose buffer for output data |
kotakku | 0:b1ce54272580 | 294 | |
kotakku | 0:b1ce54272580 | 295 | void readReport(); // read incoming data |
kotakku | 0:b1ce54272580 | 296 | void printReport(); // print incoming date - Uncomment for debugging |
kotakku | 0:b1ce54272580 | 297 | |
kotakku | 0:b1ce54272580 | 298 | /* Private commands */ |
kotakku | 0:b1ce54272580 | 299 | void PS3_Command(uint8_t *data, uint16_t nbytes); |
kotakku | 0:b1ce54272580 | 300 | void enable_sixaxis(); // Command used to enable the Dualshock 3 and Navigation controller to send data via USB |
kotakku | 0:b1ce54272580 | 301 | void Move_Command(uint8_t *data, uint16_t nbytes); |
kotakku | 0:b1ce54272580 | 302 | }; |
kotakku | 0:b1ce54272580 | 303 | #endif |
kotakku | 0:b1ce54272580 | 304 |