3/5

Dependencies:   mbed

Committer:
la00noix
Date:
Wed Feb 27 04:58:52 2019 +0000
Revision:
0:a56be39653d0
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
la00noix 0:a56be39653d0 1 /*
la00noix 0:a56be39653d0 2 Copyright (c) 2011 Bart Janssens
la00noix 0:a56be39653d0 3
la00noix 0:a56be39653d0 4 Permission is hereby granted, free of charge, to any person obtaining a copy
la00noix 0:a56be39653d0 5 of this software and associated documentation files (the "Software"), to deal
la00noix 0:a56be39653d0 6 in the Software without restriction, including without limitation the rights
la00noix 0:a56be39653d0 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
la00noix 0:a56be39653d0 8 copies of the Software, and to permit persons to whom the Software is
la00noix 0:a56be39653d0 9 furnished to do so, subject to the following conditions:
la00noix 0:a56be39653d0 10
la00noix 0:a56be39653d0 11 The above copyright notice and this permission notice shall be included in
la00noix 0:a56be39653d0 12 all copies or substantial portions of the Software.
la00noix 0:a56be39653d0 13
la00noix 0:a56be39653d0 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
la00noix 0:a56be39653d0 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
la00noix 0:a56be39653d0 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
la00noix 0:a56be39653d0 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
la00noix 0:a56be39653d0 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
la00noix 0:a56be39653d0 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
la00noix 0:a56be39653d0 20 THE SOFTWARE.
la00noix 0:a56be39653d0 21 */
la00noix 0:a56be39653d0 22
la00noix 0:a56be39653d0 23 /* Defines for the PS3 Buttons
la00noix 0:a56be39653d0 24 */
la00noix 0:a56be39653d0 25
la00noix 0:a56be39653d0 26
la00noix 0:a56be39653d0 27 #define BUTTONSELECT 0
la00noix 0:a56be39653d0 28 #define BUTTONLANALOG 1
la00noix 0:a56be39653d0 29 #define BUTTONRANALOG 2
la00noix 0:a56be39653d0 30 #define BUTTONSTART 3
la00noix 0:a56be39653d0 31 #define BUTTONUP 4
la00noix 0:a56be39653d0 32 #define BUTTONRIGHT 5
la00noix 0:a56be39653d0 33 #define BUTTONDOWN 6
la00noix 0:a56be39653d0 34 #define BUTTONLEFT 7
la00noix 0:a56be39653d0 35 #define BUTTONL2 8
la00noix 0:a56be39653d0 36 #define BUTTONR2 9
la00noix 0:a56be39653d0 37 #define BUTTONL1 10
la00noix 0:a56be39653d0 38 #define BUTTONR1 11
la00noix 0:a56be39653d0 39 #define BUTTONTRIANGEL 12
la00noix 0:a56be39653d0 40 #define BUTTONCIRCLE 13
la00noix 0:a56be39653d0 41 #define BUTTONCROSS 14
la00noix 0:a56be39653d0 42 #define BUTTONSQUARE 15
la00noix 0:a56be39653d0 43 #define BUTTONPS 16
la00noix 0:a56be39653d0 44
la00noix 0:a56be39653d0 45
la00noix 0:a56be39653d0 46 /* Defines for the PS3 Joysticks
la00noix 0:a56be39653d0 47 */
la00noix 0:a56be39653d0 48
la00noix 0:a56be39653d0 49 #define LEFTJOYSTICKX 0
la00noix 0:a56be39653d0 50 #define LEFTJOYSTICKY 1
la00noix 0:a56be39653d0 51 #define RIGHTJOYSTICKX 2
la00noix 0:a56be39653d0 52 #define RIGHTJOYSTICKY 3
la00noix 0:a56be39653d0 53
la00noix 0:a56be39653d0 54
la00noix 0:a56be39653d0 55 /* Defines for the PS3 Accelerometers and Gyro
la00noix 0:a56be39653d0 56 */
la00noix 0:a56be39653d0 57
la00noix 0:a56be39653d0 58 #define ACCELOROMETERX 0
la00noix 0:a56be39653d0 59 #define ACCELOROMETERY 1
la00noix 0:a56be39653d0 60 #define ACCELOROMETERZ 2
la00noix 0:a56be39653d0 61 #define GYROMETERZ 3
la00noix 0:a56be39653d0 62
la00noix 0:a56be39653d0 63 /* Defines for the PS3 LED and Rumble
la00noix 0:a56be39653d0 64 */
la00noix 0:a56be39653d0 65 #define PS3LED1 0x01
la00noix 0:a56be39653d0 66 #define PS3LED2 0x02
la00noix 0:a56be39653d0 67 #define PS3LED3 0x04
la00noix 0:a56be39653d0 68 #define PS3LED4 0x08
la00noix 0:a56be39653d0 69 #define PSRUMBLEHIGH 0x10
la00noix 0:a56be39653d0 70 #define PSRUMBLELOW 0x20
la00noix 0:a56be39653d0 71
la00noix 0:a56be39653d0 72 //Structure which describes the type 01 input report
la00noix 0:a56be39653d0 73 typedef struct {
la00noix 0:a56be39653d0 74 u8 ReportType; //Report Type 01
la00noix 0:a56be39653d0 75 u8 Reserved1; // Unknown
la00noix 0:a56be39653d0 76 u16 ButtonState; // Main buttons
la00noix 0:a56be39653d0 77 u8 PSButtonState; // PS button
la00noix 0:a56be39653d0 78 u8 Reserved2; // Unknown
la00noix 0:a56be39653d0 79 u8 LeftStickX; // left Joystick X axis 0 - 255, 128 is mid
la00noix 0:a56be39653d0 80 u8 LeftStickY; // left Joystick Y axis 0 - 255, 128 is mid
la00noix 0:a56be39653d0 81 u8 RightStickX; // right Joystick X axis 0 - 255, 128 is mid
la00noix 0:a56be39653d0 82 u8 RightStickY; // right Joystick Y axis 0 - 255, 128 is mid
la00noix 0:a56be39653d0 83 u8 Reserved3[4]; // Unknown
la00noix 0:a56be39653d0 84 u8 PressureUp; // digital Pad Up button Pressure 0 - 255
la00noix 0:a56be39653d0 85 u8 PressureRight; // digital Pad Right button Pressure 0 - 255
la00noix 0:a56be39653d0 86 u8 PressureDown; // digital Pad Down button Pressure 0 - 255
la00noix 0:a56be39653d0 87 u8 PressureLeft; // digital Pad Left button Pressure 0 - 255
la00noix 0:a56be39653d0 88 u8 PressureL2; // digital Pad L2 button Pressure 0 - 255
la00noix 0:a56be39653d0 89 u8 PressureR2; // digital Pad R2 button Pressure 0 - 255
la00noix 0:a56be39653d0 90 u8 PressureL1; // digital Pad L1 button Pressure 0 - 255
la00noix 0:a56be39653d0 91 u8 PressureR1; // digital Pad R1 button Pressure 0 - 255
la00noix 0:a56be39653d0 92 u8 PressureTriangle; // digital Pad Triangle button Pressure 0 - 255
la00noix 0:a56be39653d0 93 u8 PressureCircle; // digital Pad Circle button Pressure 0 - 255
la00noix 0:a56be39653d0 94 u8 PressureCross; // digital Pad Cross button Pressure 0 - 255
la00noix 0:a56be39653d0 95 u8 PressureSquare; // digital Pad Square button Pressure 0 - 255
la00noix 0:a56be39653d0 96 u8 Reserved4[3]; // Unknown
la00noix 0:a56be39653d0 97 u8 Charge; // charging status ? 02 = charge, 03 = normal
la00noix 0:a56be39653d0 98 u8 Power; // Battery status ?
la00noix 0:a56be39653d0 99 u8 Connection; // Connection Type ?
la00noix 0:a56be39653d0 100 u8 Reserved5[9]; // Unknown
la00noix 0:a56be39653d0 101 u16 AccelX; // X axis accelerometer Big Endian 0 - 1023
la00noix 0:a56be39653d0 102 u16 AccelY; // Y axis accelerometer Big Endian 0 - 1023
la00noix 0:a56be39653d0 103 u16 AccelZ; // Z axis accelerometer Big Endian 0 - 1023
la00noix 0:a56be39653d0 104 u16 GyroZ; // Z axis Gyro Big Endian 0 - 1023
la00noix 0:a56be39653d0 105
la00noix 0:a56be39653d0 106 } ps3report;
la00noix 0:a56be39653d0 107
la00noix 0:a56be39653d0 108 class Ps3USB
la00noix 0:a56be39653d0 109 {
la00noix 0:a56be39653d0 110
la00noix 0:a56be39653d0 111
la00noix 0:a56be39653d0 112 public:
la00noix 0:a56be39653d0 113 Ps3USB(int device, int configuration, int interfaceNumber);
la00noix 0:a56be39653d0 114 int Enable();
la00noix 0:a56be39653d0 115 int SetPair(u8* bdAddr);
la00noix 0:a56be39653d0 116 int ShowPair();
la00noix 0:a56be39653d0 117 int Led(int i);
la00noix 0:a56be39653d0 118 int Rumble(u8 duration_right, u8 power_right, u8 duration_left, u8 power_left);
la00noix 0:a56be39653d0 119 int _count;
la00noix 0:a56be39653d0 120
la00noix 0:a56be39653d0 121 private:
la00noix 0:a56be39653d0 122 int input_ep;
la00noix 0:a56be39653d0 123 int output_ep;
la00noix 0:a56be39653d0 124 int _device;
la00noix 0:a56be39653d0 125 int _configuration;
la00noix 0:a56be39653d0 126 int _interfaceNumber;
la00noix 0:a56be39653d0 127
la00noix 0:a56be39653d0 128 u8 ledrumble[48] ;
la00noix 0:a56be39653d0 129
la00noix 0:a56be39653d0 130 };
la00noix 0:a56be39653d0 131
la00noix 0:a56be39653d0 132 void PS3EventCallback(int device, int endpoint, int status, u8* data, int len, void* userData);
la00noix 0:a56be39653d0 133 int ParsePs3Result(const u8* data, int len, int count);
la00noix 0:a56be39653d0 134
la00noix 0:a56be39653d0 135