![](/media/cache/profiles/8474b8609e772af467ac0fc4acad4dd4.jpg.50x50_q85.jpg)
A compilation of code from different sources to provide support for a Playstation 3 controller via bluetooth on the m3pi.
Fork of mbed_TANK_PS3 by
ps3BT.h@2:895f70862eb9, 2013-01-01 (annotated)
- Committer:
- srsmitherman
- Date:
- Tue Jan 01 02:10:08 2013 +0000
- Revision:
- 2:895f70862eb9
- Parent:
- 1:ae49669c5e92
M3pi support
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
srsmitherman | 1:ae49669c5e92 | 1 | /* |
srsmitherman | 1:ae49669c5e92 | 2 | Copyright (c) 2011 Bart Janssens |
srsmitherman | 1:ae49669c5e92 | 3 | |
srsmitherman | 1:ae49669c5e92 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
srsmitherman | 1:ae49669c5e92 | 5 | of this software and associated documentation files (the "Software"), to deal |
srsmitherman | 1:ae49669c5e92 | 6 | in the Software without restriction, including without limitation the rights |
srsmitherman | 1:ae49669c5e92 | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
srsmitherman | 1:ae49669c5e92 | 8 | copies of the Software, and to permit persons to whom the Software is |
srsmitherman | 1:ae49669c5e92 | 9 | furnished to do so, subject to the following conditions: |
srsmitherman | 1:ae49669c5e92 | 10 | |
srsmitherman | 1:ae49669c5e92 | 11 | The above copyright notice and this permission notice shall be included in |
srsmitherman | 1:ae49669c5e92 | 12 | all copies or substantial portions of the Software. |
srsmitherman | 1:ae49669c5e92 | 13 | |
srsmitherman | 1:ae49669c5e92 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
srsmitherman | 1:ae49669c5e92 | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
srsmitherman | 1:ae49669c5e92 | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
srsmitherman | 1:ae49669c5e92 | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
srsmitherman | 1:ae49669c5e92 | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
srsmitherman | 1:ae49669c5e92 | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
srsmitherman | 1:ae49669c5e92 | 20 | THE SOFTWARE. |
srsmitherman | 1:ae49669c5e92 | 21 | */ |
srsmitherman | 1:ae49669c5e92 | 22 | |
srsmitherman | 1:ae49669c5e92 | 23 | /* Defines for the PS3 Buttons |
srsmitherman | 1:ae49669c5e92 | 24 | */ |
srsmitherman | 1:ae49669c5e92 | 25 | #ifndef PS3BT_H |
srsmitherman | 1:ae49669c5e92 | 26 | #define PS3BT_H |
srsmitherman | 1:ae49669c5e92 | 27 | |
srsmitherman | 1:ae49669c5e92 | 28 | #include "Utils.h" |
srsmitherman | 1:ae49669c5e92 | 29 | #include <stdio.h> |
srsmitherman | 1:ae49669c5e92 | 30 | |
srsmitherman | 1:ae49669c5e92 | 31 | #define BUTTONSELECT 0 |
srsmitherman | 1:ae49669c5e92 | 32 | #define BUTTONLANALOG 1 |
srsmitherman | 1:ae49669c5e92 | 33 | #define BUTTONRANALOG 2 |
srsmitherman | 1:ae49669c5e92 | 34 | #define BUTTONSTART 3 |
srsmitherman | 1:ae49669c5e92 | 35 | #define BUTTONUP 4 |
srsmitherman | 1:ae49669c5e92 | 36 | #define BUTTONRIGHT 5 |
srsmitherman | 1:ae49669c5e92 | 37 | #define BUTTONDOWN 6 |
srsmitherman | 1:ae49669c5e92 | 38 | #define BUTTONLEFT 7 |
srsmitherman | 1:ae49669c5e92 | 39 | #define BUTTONL2 8 |
srsmitherman | 1:ae49669c5e92 | 40 | #define BUTTONR2 9 |
srsmitherman | 1:ae49669c5e92 | 41 | #define BUTTONL1 10 |
srsmitherman | 1:ae49669c5e92 | 42 | #define BUTTONR1 11 |
srsmitherman | 1:ae49669c5e92 | 43 | #define BUTTONTRIANGEL 12 |
srsmitherman | 1:ae49669c5e92 | 44 | #define BUTTONCIRCLE 13 |
srsmitherman | 1:ae49669c5e92 | 45 | #define BUTTONCROSS 14 |
srsmitherman | 1:ae49669c5e92 | 46 | #define BUTTONSQUARE 15 |
srsmitherman | 1:ae49669c5e92 | 47 | #define BUTTONPS 16 |
srsmitherman | 1:ae49669c5e92 | 48 | |
srsmitherman | 1:ae49669c5e92 | 49 | |
srsmitherman | 1:ae49669c5e92 | 50 | /* Defines for the PS3 Joysticks |
srsmitherman | 1:ae49669c5e92 | 51 | */ |
srsmitherman | 1:ae49669c5e92 | 52 | |
srsmitherman | 1:ae49669c5e92 | 53 | #define LEFTJOYSTICKX 0 |
srsmitherman | 1:ae49669c5e92 | 54 | #define LEFTJOYSTICKY 1 |
srsmitherman | 1:ae49669c5e92 | 55 | #define RIGHTJOYSTICKX 2 |
srsmitherman | 1:ae49669c5e92 | 56 | #define RIGHTJOYSTICKY 3 |
srsmitherman | 1:ae49669c5e92 | 57 | |
srsmitherman | 1:ae49669c5e92 | 58 | |
srsmitherman | 1:ae49669c5e92 | 59 | /* Defines for the PS3 Accelerometers and Gyro |
srsmitherman | 1:ae49669c5e92 | 60 | */ |
srsmitherman | 1:ae49669c5e92 | 61 | |
srsmitherman | 1:ae49669c5e92 | 62 | #define ACCELOROMETERX 0 |
srsmitherman | 1:ae49669c5e92 | 63 | #define ACCELOROMETERY 1 |
srsmitherman | 1:ae49669c5e92 | 64 | #define ACCELOROMETERZ 2 |
srsmitherman | 1:ae49669c5e92 | 65 | #define GYROMETERZ 3 |
srsmitherman | 1:ae49669c5e92 | 66 | |
srsmitherman | 1:ae49669c5e92 | 67 | /* Defines for the PS3 LED and Rumble |
srsmitherman | 1:ae49669c5e92 | 68 | */ |
srsmitherman | 1:ae49669c5e92 | 69 | #define PS3LED1 0x01 |
srsmitherman | 1:ae49669c5e92 | 70 | #define PS3LED2 0x02 |
srsmitherman | 1:ae49669c5e92 | 71 | #define PS3LED3 0x04 |
srsmitherman | 1:ae49669c5e92 | 72 | #define PS3LED4 0x08 |
srsmitherman | 1:ae49669c5e92 | 73 | #define PSRUMBLEHIGH 0x10 |
srsmitherman | 1:ae49669c5e92 | 74 | #define PSRUMBLELOW 0x20 |
srsmitherman | 1:ae49669c5e92 | 75 | |
srsmitherman | 1:ae49669c5e92 | 76 | |
srsmitherman | 1:ae49669c5e92 | 77 | class PS3BT |
srsmitherman | 1:ae49669c5e92 | 78 | { |
srsmitherman | 1:ae49669c5e92 | 79 | |
srsmitherman | 1:ae49669c5e92 | 80 | public: |
srsmitherman | 1:ae49669c5e92 | 81 | void decode(const u8* data); |
srsmitherman | 1:ae49669c5e92 | 82 | void dump(const u8* data); |
srsmitherman | 1:ae49669c5e92 | 83 | |
srsmitherman | 1:ae49669c5e92 | 84 | |
srsmitherman | 1:ae49669c5e92 | 85 | //Structure which describes the type 01 input report |
srsmitherman | 1:ae49669c5e92 | 86 | typedef struct { |
srsmitherman | 1:ae49669c5e92 | 87 | u8 ReportType; //Report Type 01 |
srsmitherman | 1:ae49669c5e92 | 88 | u8 Reserved1; // Unknown |
srsmitherman | 1:ae49669c5e92 | 89 | u16 ButtonState; // Main buttons |
srsmitherman | 1:ae49669c5e92 | 90 | u8 PSButtonState; // PS button |
srsmitherman | 1:ae49669c5e92 | 91 | u8 Reserved2; // Unknown |
srsmitherman | 1:ae49669c5e92 | 92 | u8 LeftStickX; // left Joystick X axis 0 - 255, 128 is mid |
srsmitherman | 1:ae49669c5e92 | 93 | u8 LeftStickY; // left Joystick Y axis 0 - 255, 128 is mid |
srsmitherman | 1:ae49669c5e92 | 94 | u8 RightStickX; // right Joystick X axis 0 - 255, 128 is mid |
srsmitherman | 1:ae49669c5e92 | 95 | u8 RightStickY; // right Joystick Y axis 0 - 255, 128 is mid |
srsmitherman | 1:ae49669c5e92 | 96 | u8 Reserved3[4]; // Unknown |
srsmitherman | 1:ae49669c5e92 | 97 | u8 PressureUp; // digital Pad Up button Pressure 0 - 255 |
srsmitherman | 1:ae49669c5e92 | 98 | u8 PressureRight; // digital Pad Right button Pressure 0 - 255 |
srsmitherman | 1:ae49669c5e92 | 99 | u8 PressureDown; // digital Pad Down button Pressure 0 - 255 |
srsmitherman | 1:ae49669c5e92 | 100 | u8 PressureLeft; // digital Pad Left button Pressure 0 - 255 |
srsmitherman | 1:ae49669c5e92 | 101 | u8 PressureL2; // digital Pad L2 button Pressure 0 - 255 |
srsmitherman | 1:ae49669c5e92 | 102 | u8 PressureR2; // digital Pad R2 button Pressure 0 - 255 |
srsmitherman | 1:ae49669c5e92 | 103 | u8 PressureL1; // digital Pad L1 button Pressure 0 - 255 |
srsmitherman | 1:ae49669c5e92 | 104 | u8 PressureR1; // digital Pad R1 button Pressure 0 - 255 |
srsmitherman | 1:ae49669c5e92 | 105 | u8 PressureTriangle; // digital Pad Triangle button Pressure 0 - 255 |
srsmitherman | 1:ae49669c5e92 | 106 | u8 PressureCircle; // digital Pad Circle button Pressure 0 - 255 |
srsmitherman | 1:ae49669c5e92 | 107 | u8 PressureCross; // digital Pad Cross button Pressure 0 - 255 |
srsmitherman | 1:ae49669c5e92 | 108 | u8 PressureSquare; // digital Pad Square button Pressure 0 - 255 |
srsmitherman | 1:ae49669c5e92 | 109 | u8 Reserved4[3]; // Unknown |
srsmitherman | 1:ae49669c5e92 | 110 | u8 Charge; // charging status ? 02 = charge, 03 = normal |
srsmitherman | 1:ae49669c5e92 | 111 | u8 Power; // Battery status ? |
srsmitherman | 1:ae49669c5e92 | 112 | u8 Connection; // Connection Type ? |
srsmitherman | 1:ae49669c5e92 | 113 | u8 Reserved5[9]; // Unknown |
srsmitherman | 1:ae49669c5e92 | 114 | u16 AccelX; // X axis accelerometer Big Endian 0 - 1023 |
srsmitherman | 1:ae49669c5e92 | 115 | u16 AccelY; // Y axis accelerometer Big Endian 0 - 1023 |
srsmitherman | 1:ae49669c5e92 | 116 | u16 AccelZ; // Z axis accelerometer Big Endian 0 - 1023 |
srsmitherman | 1:ae49669c5e92 | 117 | u16 GyroZ; // Z axis Gyro Big Endian 0 - 1023 |
srsmitherman | 1:ae49669c5e92 | 118 | |
srsmitherman | 1:ae49669c5e92 | 119 | } ps3report; |
srsmitherman | 1:ae49669c5e92 | 120 | }; |
srsmitherman | 1:ae49669c5e92 | 121 | |
srsmitherman | 1:ae49669c5e92 | 122 | #endif |