XOOMの動作状況を聞き処理を変えてみました。 USBケーブルを抜いた際に処理を終了するようにしました。

Dependencies:   mbed

Committer:
abe00makoto
Date:
Fri May 27 18:51:15 2011 +0000
Revision:
3:432e5675d240
Parent:
0:9fb6c423e32c
nexus one support
maybe support add XOOM ,nexus S

Who changed what in which revision?

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