BlueUSBをつかってみた

Dependencies:   FatFileSystem mbed

Fork of PS3_BlueUSB by Bart Janssens

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ps3.h Source File

ps3.h

00001 /*
00002 Copyright (c) 2011 Bart Janssens
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a copy
00005 of this software and associated documentation files (the "Software"), to deal
00006 in the Software without restriction, including without limitation the rights
00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008 copies of the Software, and to permit persons to whom the Software is
00009 furnished to do so, subject to the following conditions:
00010 
00011 The above copyright notice and this permission notice shall be included in
00012 all copies or substantial portions of the Software.
00013 
00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020 THE SOFTWARE.
00021 */
00022 
00023 /* Defines for the PS3 Buttons 
00024 */
00025 
00026 
00027 #define BUTTONSELECT    0
00028 #define BUTTONLANALOG   1
00029 #define BUTTONRANALOG   2
00030 #define BUTTONSTART     3
00031 #define BUTTONUP        4
00032 #define BUTTONRIGHT     5
00033 #define BUTTONDOWN      6
00034 #define BUTTONLEFT      7
00035 #define BUTTONL2        8
00036 #define BUTTONR2        9
00037 #define BUTTONL1        10
00038 #define BUTTONR1        11
00039 #define BUTTONTRIANGEL  12
00040 #define BUTTONCIRCLE    13
00041 #define BUTTONCROSS     14
00042 #define BUTTONSQUARE    15
00043 #define BUTTONPS        16
00044 
00045 
00046 /* Defines for the PS3 Joysticks 
00047 */
00048 
00049 #define LEFTJOYSTICKX 0
00050 #define LEFTJOYSTICKY 1
00051 #define RIGHTJOYSTICKX 2
00052 #define RIGHTJOYSTICKY 3
00053 
00054 
00055 /* Defines for the PS3 Accelerometers and Gyro 
00056 */
00057 
00058 #define ACCELOROMETERX 0
00059 #define ACCELOROMETERY 1
00060 #define ACCELOROMETERZ 2
00061 #define GYROMETERZ 3
00062 
00063 /* Defines for the PS3 LED and Rumble 
00064 */
00065 #define PS3LED1 0x01
00066 #define PS3LED2 0x02
00067 #define PS3LED3 0x04
00068 #define PS3LED4 0x08
00069 #define PSRUMBLEHIGH 0x10
00070 #define PSRUMBLELOW 0x20
00071 
00072 //Structure which describes the type 01 input report
00073 typedef struct {        
00074      u8 ReportType;     //Report Type 01
00075      u8 Reserved1;      // Unknown
00076      u16  ButtonState;    // Main buttons
00077      u8 PSButtonState;  // PS button
00078      u8 Reserved2;      // Unknown
00079      u8 LeftStickX;     // left Joystick X axis 0 - 255, 128 is mid
00080      u8 LeftStickY;     // left Joystick Y axis 0 - 255, 128 is mid
00081      u8 RightStickX;    // right Joystick X axis 0 - 255, 128 is mid
00082      u8 RightStickY;    // right Joystick Y axis 0 - 255, 128 is mid
00083      u8 Reserved3[4];   // Unknown
00084      u8 PressureUp;     // digital Pad Up button Pressure 0 - 255
00085      u8 PressureRight;  // digital Pad Right button Pressure 0 - 255
00086      u8 PressureDown;   // digital Pad Down button Pressure 0 - 255
00087      u8 PressureLeft;   // digital Pad Left button Pressure 0 - 255
00088      u8 PressureL2;     // digital Pad L2 button Pressure 0 - 255
00089      u8 PressureR2;     // digital Pad R2 button Pressure 0 - 255
00090      u8 PressureL1;     // digital Pad L1 button Pressure 0 - 255
00091      u8 PressureR1;     // digital Pad R1 button Pressure 0 - 255
00092      u8 PressureTriangle;   // digital Pad Triangle button Pressure 0 - 255
00093      u8 PressureCircle;     // digital Pad Circle button Pressure 0 - 255
00094      u8 PressureCross;      // digital Pad Cross button Pressure 0 - 255
00095      u8 PressureSquare;     // digital Pad Square button Pressure 0 - 255
00096      u8 Reserved4[3];   // Unknown
00097      u8 Charge;         // charging status ? 02 = charge, 03 = normal
00098      u8 Power;          // Battery status ?
00099      u8 Connection;     // Connection Type ?
00100      u8 Reserved5[9];   // Unknown
00101      u16 AccelX;          // X axis accelerometer Big Endian 0 - 1023
00102      u16 AccelY;          // Y axis accelerometer Big Endian 0 - 1023
00103      u16 AccelZ;          // Z axis accelerometer Big Endian 0 - 1023
00104      u16 GyroZ;           // Z axis Gyro Big Endian 0 - 1023
00105     
00106 } ps3report;
00107 
00108 class Ps3USB
00109 {
00110     
00111     
00112     public:
00113     Ps3USB(int device, int configuration, int interfaceNumber);
00114     int Enable();
00115     int SetPair(u8* bdAddr);
00116     int ShowPair();
00117     int Led(int i);
00118     int Rumble(u8 duration_right, u8 power_right, u8 duration_left, u8 power_left);
00119     int _count;
00120     
00121     private:
00122     int input_ep;
00123     int output_ep;
00124     int _device;
00125     int _configuration;
00126     int _interfaceNumber;
00127     
00128     u8 ledrumble[48] ;
00129     
00130 };
00131 
00132 void PS3EventCallback(int device, int endpoint, int status, u8* data, int len, void* userData);
00133 int ParsePs3Result(const u8* data, int len, int count);
00134 
00135