Dependencies:   mbed

Committer:
abe00makoto
Date:
Thu May 26 19:39:37 2011 +0000
Revision:
1:237cfff63ef8
Parent:
0:e939856c1939

        

Who changed what in which revision?

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