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