Created same syntax for Move controller

This commit is contained in:
Kristian Lauszus 2012-05-28 21:53:20 +02:00
parent 91fbbfad3b
commit 9d6eb2d69b
5 changed files with 76 additions and 61 deletions

View file

@ -441,10 +441,17 @@ bool PS3BT::getButton(Button b)
{ {
if (l2capinbuf == NULL) if (l2capinbuf == NULL)
return false; return false;
if ((l2capinbuf[(uint16_t)b >> 8] & ((uint8_t)b & 0xff)) > 0) if(PS3MoveConnected) {
if((l2capinbuf[((uint16_t)b >> 8)-1] & ((uint8_t)b & 0xff))) // All the buttons locations are shifted one back on the Move controller
return true; return true;
else else
return false; return false;
} else {
if((l2capinbuf[(uint16_t)b >> 8] & ((uint8_t)b & 0xff)))
return true;
else
return false;
}
} }
uint8_t PS3BT::getAnalogButton(AnalogButton a) uint8_t PS3BT::getAnalogButton(AnalogButton a)
{ {

35
PS3BT.h
View file

@ -179,24 +179,24 @@ enum LED
}; };
enum Colors enum Colors
{ {
//Used to set the colors of the move controller // Used to set the colors of the move controller
Red = 0xFF0000,//((255 << 16) | (0 << 8) | 0); Red = 0xFF0000, // r = 255, g = 0, b = 0
Green = 0xFF00,//((0 << 16) | (255 << 8) | 0); Green = 0xFF00, // r = 0, g = 255, b = 0
Blue = 0xFF,//((0 << 16) | (0 << 8) | 255); Blue = 0xFF, // r = 0, g = 0, b = 255
Yellow = 0xFFEB04,//((255 << 16) | (235 << 8) | 4); Yellow = 0xFFEB04, // r = 255, g = 235, b = 4
Lightblue = 0xFFFF,//((0 << 16) | (255 << 8) | 255); Lightblue = 0xFFFF, // r = 0, g = 255, b = 255
Purble = 0xFF00FF,//((255 << 16) | (0 << 8) | 255); Purble = 0xFF00FF, // r = 255, g = 0, b = 255
White = 0xFFFFFF,//((255 << 16) | (255 << 8) | 255); White = 0xFFFFFF, // r = 255, g = 255, b = 255
Off = 0x00,//((0 << 16) | (0 << 8) | 0); Off = 0x00, // r = 0, g = 0, b = 0
}; };
enum Button enum Button
{ {
// byte location | bit location // byte location | bit location
//Sixaxis Dualshcock 3 & Navigation controller // Sixaxis Dualshcock 3 & Navigation controller
SELECT = (11 << 8) | 0x01, SELECT = (11 << 8) | 0x01,
L3 = (11 << 8) | 0x02, L3 = (11 << 8) | 0x02,
R3 = (11 << 8) | 0x04, R3 = (11 << 8) | 0x04,
@ -217,7 +217,13 @@ enum Button
PS = (13 << 8) | 0x01, PS = (13 << 8) | 0x01,
//Playstation Move Controller MOVE = (13/*12*/ << 8) | 0x08, // covers 12 bits - we only need to read the top 8
T = (13/*12*/ << 8) | 0x10, // covers 12 bits - we only need to read the top 8
// These are the true locations for the Move controller, but to make the same syntax for all controllers, it is handled by getButton()
/*
// Playstation Move Controller
SELECT_MOVE = (10 << 8) | 0x01, SELECT_MOVE = (10 << 8) | 0x01,
START_MOVE = (10 << 8) | 0x08, START_MOVE = (10 << 8) | 0x08,
@ -227,8 +233,9 @@ enum Button
SQUARE_MOVE = (11 << 8) | 0x80, SQUARE_MOVE = (11 << 8) | 0x80,
PS_MOVE = (12 << 8) | 0x01, PS_MOVE = (12 << 8) | 0x01,
MOVE_MOVE = (12 << 8) | 0x08,//covers 12 bits - we only need to read the top 8 MOVE_MOVE = (12 << 8) | 0x08, // covers 12 bits - we only need to read the top 8
T_MOVE = (12 << 8) | 0x10,//covers 12 bits - we only need to read the top 8 T_MOVE = (12 << 8) | 0x10, // covers 12 bits - we only need to read the top 8
*/
}; };
enum AnalogButton enum AnalogButton
{ {
@ -248,7 +255,7 @@ enum AnalogButton
SQUARE_ANALOG = 34, SQUARE_ANALOG = 34,
//Playstation Move Controller //Playstation Move Controller
T_MOVE_ANALOG = 15,//Both at byte 14 (last reading) and byte 15 (current reading) T_ANALOG = 15, // Both at byte 14 (last reading) and byte 15 (current reading)
}; };
enum AnalogHat enum AnalogHat
{ {

View file

@ -68,24 +68,24 @@ enum LED
}; };
enum Colors enum Colors
{ {
//Used to set the colors of the move controller // Used to set the colors of the move controller
Red = 0xFF0000,//((255 << 16) | (0 << 8) | 0); Red = 0xFF0000, // r = 255, g = 0, b = 0
Green = 0xFF00,//((0 << 16) | (255 << 8) | 0); Green = 0xFF00, // r = 0, g = 255, b = 0
Blue = 0xFF,//((0 << 16) | (0 << 8) | 255); Blue = 0xFF, // r = 0, g = 0, b = 255
Yellow = 0xFFEB04,//((255 << 16) | (235 << 8) | 4); Yellow = 0xFFEB04, // r = 255, g = 235, b = 4
Lightblue = 0xFFFF,//((0 << 16) | (255 << 8) | 255); Lightblue = 0xFFFF, // r = 0, g = 255, b = 255
Purble = 0xFF00FF,//((255 << 16) | (0 << 8) | 255); Purble = 0xFF00FF, // r = 255, g = 0, b = 255
White = 0xFFFFFF,//((255 << 16) | (255 << 8) | 255); White = 0xFFFFFF, // r = 255, g = 255, b = 255
Off = 0x00,//((0 << 16) | (0 << 8) | 0); Off = 0x00, // r = 0, g = 0, b = 0
}; };
enum Button enum Button
{ {
// byte location | bit location // byte location | bit location
//Sixaxis Dualshcock 3 & Navigation controller // Sixaxis Dualshcock 3 & Navigation controller
SELECT = (2 << 8) | 0x01, SELECT = (2 << 8) | 0x01,
L3 = (2 << 8) | 0x02, L3 = (2 << 8) | 0x02,
R3 = (2 << 8) | 0x04, R3 = (2 << 8) | 0x04,
@ -108,7 +108,7 @@ enum Button
}; };
enum AnalogButton enum AnalogButton
{ {
//Sixaxis Dualshcock 3 & Navigation controller // Sixaxis Dualshcock 3 & Navigation controller
UP_ANALOG = 14, UP_ANALOG = 14,
RIGHT_ANALOG = 15, RIGHT_ANALOG = 15,
DOWN_ANALOG = 16, DOWN_ANALOG = 16,

View file

@ -80,21 +80,29 @@ void loop()
if(PS3.getButton(UP)) { if(PS3.getButton(UP)) {
Serial.print(F(" - Up")); Serial.print(F(" - Up"));
if(PS3.PS3Connected) {
PS3.setAllOff(); PS3.setAllOff();
PS3.setLedOn(LED4); PS3.setLedOn(LED4);
}
} if(PS3.getButton(RIGHT)) { } if(PS3.getButton(RIGHT)) {
Serial.print(F(" - Right")); Serial.print(F(" - Right"));
if(PS3.PS3Connected) {
PS3.setAllOff(); PS3.setAllOff();
PS3.setLedOn(LED1); PS3.setLedOn(LED1);
}
} if(PS3.getButton(DOWN)) { } if(PS3.getButton(DOWN)) {
Serial.print(F(" - Down")); Serial.print(F(" - Down"));
if(PS3.PS3Connected) {
PS3.setAllOff(); PS3.setAllOff();
PS3.setLedOn(LED2); PS3.setLedOn(LED2);
}
} if(PS3.getButton(LEFT)) { } if(PS3.getButton(LEFT)) {
Serial.print(F(" - Left")); Serial.print(F(" - Left"));
if(PS3.PS3Connected) {
PS3.setAllOff(); PS3.setAllOff();
PS3.setLedOn(LED3); PS3.setLedOn(LED3);
} }
}
if(PS3.getButton(L1)) if(PS3.getButton(L1))
Serial.print(F(" - L1")); Serial.print(F(" - L1"));
@ -130,39 +138,39 @@ void loop()
} }
else if(PS3.PS3MoveConnected) else if(PS3.PS3MoveConnected)
{ {
if(PS3.getAnalogButton(T_MOVE_ANALOG) > 0) { if(PS3.getAnalogButton(T_ANALOG) > 0) {
Serial.print(F("T: ")); Serial.print(F("T: "));
Serial.println(PS3.getAnalogButton(T_MOVE_ANALOG)); Serial.println(PS3.getAnalogButton(T_ANALOG));
} if(PS3.buttonPressed) { } if(PS3.buttonPressed) {
Serial.print(F("PS3 Move Controller")); Serial.print(F("PS3 Move Controller"));
if(PS3.getButton(PS_MOVE)) { if(PS3.getButton(PS)) {
Serial.print(F(" - PS")); Serial.print(F(" - PS"));
PS3.disconnect(); PS3.disconnect();
} else { } else {
if(PS3.getButton(SELECT_MOVE)) { if(PS3.getButton(SELECT)) {
Serial.print(F(" - Select")); Serial.print(F(" - Select"));
printTemperature = !printTemperature; printTemperature = !printTemperature;
while(PS3.getButton(SELECT_MOVE)) while(PS3.getButton(SELECT))
Usb.Task(); Usb.Task();
} if(PS3.getButton(START_MOVE)) { } if(PS3.getButton(START)) {
Serial.print(F(" - Start")); Serial.print(F(" - Start"));
printAngle = !printAngle; printAngle = !printAngle;
while(PS3.getButton(START_MOVE)) while(PS3.getButton(START))
Usb.Task(); Usb.Task();
} if(PS3.getButton(TRIANGLE_MOVE)) { } if(PS3.getButton(TRIANGLE)) {
Serial.print(F(" - Triangle")); Serial.print(F(" - Triangle"));
PS3.moveSetBulb(Red); PS3.moveSetBulb(Red);
} if(PS3.getButton(CIRCLE_MOVE)) { } if(PS3.getButton(CIRCLE)) {
Serial.print(F(" - Circle")); Serial.print(F(" - Circle"));
PS3.moveSetBulb(Green); PS3.moveSetBulb(Green);
} if(PS3.getButton(SQUARE_MOVE)) { } if(PS3.getButton(SQUARE)) {
Serial.print(F(" - Square")); Serial.print(F(" - Square"));
PS3.moveSetBulb(Blue); PS3.moveSetBulb(Blue);
} if(PS3.getButton(CROSS_MOVE)) { } if(PS3.getButton(CROSS)) {
Serial.print(F(" - Cross")); Serial.print(F(" - Cross"));
PS3.moveSetBulb(Yellow); PS3.moveSetBulb(Yellow);
} if(PS3.getButton(MOVE_MOVE)) { } if(PS3.getButton(MOVE)) {
PS3.moveSetBulb(Off); PS3.moveSetBulb(Off);
Serial.print(F(" - Move")); Serial.print(F(" - Move"));
Serial.print(F(" - ")); Serial.print(F(" - "));

View file

@ -82,15 +82,8 @@ CIRCLE LITERAL1
CROSS LITERAL1 CROSS LITERAL1
SQUARE LITERAL1 SQUARE LITERAL1
PS LITERAL1 PS LITERAL1
SELECT_MOVE LITERAL1 MOVE LITERAL1
START_MOVE LITERAL1 T LITERAL1
TRIANGLE_MOVE LITERAL1
CIRCLE_MOVE LITERAL1
CROSS_MOVE LITERAL1
SQUARE_MOVE LITERAL1
PS_MOVE LITERAL1
MOVE_MOVE LITERAL1
T_MOVE LITERAL1
UP_ANALOG LITERAL1 UP_ANALOG LITERAL1
RIGHT_ANALOG LITERAL1 RIGHT_ANALOG LITERAL1
@ -104,7 +97,7 @@ TRIANGLE_ANALOG LITERAL1
CIRCLE_ANALOG LITERAL1 CIRCLE_ANALOG LITERAL1
CROSS_ANALOG LITERAL1 CROSS_ANALOG LITERAL1
SQUARE_ANALOG LITERAL1 SQUARE_ANALOG LITERAL1
T_MOVE_ANALOG LITERAL1 T_ANALOG LITERAL1
LeftHatX LITERAL1 LeftHatX LITERAL1
LeftHatY LITERAL1 LeftHatY LITERAL1