Fixed conflict between analog buttons and digital buttons

This commit is contained in:
Kristian Sloth Lauszus 2013-01-27 22:02:33 +01:00
parent 8ed3fcd3b8
commit 391f5ece4d
11 changed files with 58 additions and 57 deletions

View file

@ -69,10 +69,10 @@ bool PS3BT::getButtonClick(Button b) {
ButtonClickState &= ~button; // clear "click" event
return click;
}
uint8_t PS3BT::getAnalogButton(AnalogButton a) {
uint8_t PS3BT::getAnalogButton(Button a) {
if (l2capinbuf == NULL)
return 0;
return (uint8_t)(l2capinbuf[(uint16_t)a]);
return (uint8_t)(l2capinbuf[pgm_read_byte(&ANALOGBUTTONS[(uint8_t)a])]);
}
uint8_t PS3BT::getAnalogHat(AnalogHat a) {
if (l2capinbuf == NULL)

View file

@ -77,7 +77,7 @@ public:
bool getButtonPress(Button b);
bool getButtonClick(Button b);
uint8_t getAnalogButton(AnalogButton a);
uint8_t getAnalogButton(Button a);
uint8_t getAnalogHat(AnalogHat a);
int16_t getSensor(Sensor a);
double getAngle(Angle a);

View file

@ -38,7 +38,6 @@ const uint32_t BUTTONS[] PROGMEM = {
0x20, // RIGHT
0x40, // DOWN
0x80, // LEFT
0,0,0,0,0,0,0,0,0, // Skip buttons used by Wii library
0x01, // SELECT
0x02, // L3
@ -60,6 +59,29 @@ const uint32_t BUTTONS[] PROGMEM = {
0x100000 // T - covers 12 bits - we only need to read the top 8
};
const uint8_t ANALOGBUTTONS[] PROGMEM = {
// Note that the location is shiftet 9 when it's connected via USB
// Sixaxis Dualshcock 3 & Navigation controller
23, // UP_ANALOG
24, // RIGHT_ANALOG
25, // DOWN_ANALOG
26, // LEFT_ANALOG
0,0,0,0, // Skip SELECT, L3, R3 and START
27, // L2_ANALOG
28, // R2_ANALOG
29, // L1_ANALOG
30, // R1_ANALOG
31, // TRIANGLE_ANALOG
32, // CIRCLE_ANALOG
33, // CROSS_ANALOG
34, // SQUARE_ANALOG
0,0, // Skip PS and MOVE
//Playstation Move Controller
15 // T_ANALOG - Both at byte 14 (last reading) and byte 15 (current reading)
};
enum Colors {
// Used to set the colors of the move controller
Red = 0xFF0000, // r = 255, g = 0, b = 0
@ -73,26 +95,6 @@ enum Colors {
White = 0xFFFFFF, // r = 255, g = 255, b = 255
Off = 0x00, // r = 0, g = 0, b = 0
};
enum AnalogButton {
// Note that the location is shiftet 9 when it's connected via USB
// Sixaxis Dualshcock 3 & Navigation controller
UP_ANALOG = 23,
RIGHT_ANALOG = 24,
DOWN_ANALOG = 25,
LEFT_ANALOG = 26,
L2_ANALOG = 27,
R2_ANALOG = 28,
L1_ANALOG = 29,
R1_ANALOG = 30,
TRIANGLE_ANALOG = 31,
CIRCLE_ANALOG = 32,
CROSS_ANALOG = 33,
SQUARE_ANALOG = 34,
//Playstation Move Controller
T_ANALOG = 15, // Both at byte 14 (last reading) and byte 15 (current reading)
};
enum AnalogHat {
// Note that the location is shiftet 9 when it's connected via USB
LeftHatX = 15,

View file

@ -335,10 +335,10 @@ bool PS3USB::getButtonClick(Button b) {
ButtonClickState &= ~button; // clear "click" event
return click;
}
uint8_t PS3USB::getAnalogButton(AnalogButton a) {
uint8_t PS3USB::getAnalogButton(Button a) {
if (readBuf == NULL)
return 0;
return (uint8_t)(readBuf[((uint16_t)a)-9]);
return (uint8_t)(readBuf[(pgm_read_byte(&ANALOGBUTTONS[(uint8_t)a]))-9]);
}
uint8_t PS3USB::getAnalogHat(AnalogHat a) {
if (readBuf == NULL)

View file

@ -77,7 +77,7 @@ public:
bool getButtonPress(Button b);
bool getButtonClick(Button b);
uint8_t getAnalogButton(AnalogButton a);
uint8_t getAnalogButton(Button a);
uint8_t getAnalogHat(AnalogHat a);
uint16_t getSensor(Sensor a);
double getAngle(Angle a);

View file

@ -44,7 +44,6 @@ const uint32_t BUTTONS[] PROGMEM = {
0x00004, // DOWN
0x00001, // LEFT
0x00010, // PLUS
0x00100, // TWO

View file

@ -51,24 +51,24 @@ enum Button {
C = 12,
/* PS3 controllers buttons */
SELECT = 13,
L3 = 14,
R3 = 15,
START = 16,
SELECT = 4,
L3 = 5,
R3 = 6,
START = 7,
L2 = 17,
R2 = 18,
L1 = 19,
R1 = 20,
TRIANGLE = 21,
CIRCLE = 22,
CROSS = 23,
SQUARE = 24,
L2 = 8,
R2 = 9,
L1 = 10,
R1 = 11,
TRIANGLE = 12,
CIRCLE = 13,
CROSS = 14,
SQUARE = 15,
PS = 25,
PS = 16,
MOVE = 26, // covers 12 bits - we only need to read the top 8
T = 27, // covers 12 bits - we only need to read the top 8
MOVE = 17, // covers 12 bits - we only need to read the top 8
T = 18, // covers 12 bits - we only need to read the top 8
};
#endif

View file

@ -40,12 +40,12 @@ void loop() {
}
//Analog button values can be read from almost all buttons
if(PS3.getAnalogButton(L2_ANALOG) > 0 || PS3.getAnalogButton(R2_ANALOG) > 0) {
if(PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) {
Serial.print(F("\r\nL2: "));
Serial.print(PS3.getAnalogButton(L2_ANALOG));
Serial.print(PS3.getAnalogButton(L2));
if(!PS3.PS3NavigationConnected) {
Serial.print(F("\tR2: "));
Serial.print(PS3.getAnalogButton(R2_ANALOG));
Serial.print(PS3.getAnalogButton(R2));
}
}
if(PS3.getButtonClick(PS)) {
@ -117,9 +117,9 @@ void loop() {
}
}
else if(PS3.PS3MoveConnected) {
if(PS3.getAnalogButton(T_ANALOG) > 0) {
if(PS3.getAnalogButton(T)) {
Serial.print(F("\r\nT: "));
Serial.print(PS3.getAnalogButton(T_ANALOG));
Serial.print(PS3.getAnalogButton(T));
}
if(PS3.getButtonClick(PS)) {
Serial.print(F("\r\nPS"));

View file

@ -47,12 +47,12 @@ void loop() {
}
}
//Analog button values can be read from almost all buttons
if(PS3[i]->getAnalogButton(L2_ANALOG) > 0 || PS3[i]->getAnalogButton(R2_ANALOG) > 0) {
if(PS3[i]->getAnalogButton(L2) || PS3[i]->getAnalogButton(R2)) {
Serial.print(F("\r\nL2: "));
Serial.print(PS3[i]->getAnalogButton(L2_ANALOG));
Serial.print(PS3[i]->getAnalogButton(L2));
if(!PS3[i]->PS3NavigationConnected) {
Serial.print(F("\tR2: "));
Serial.print(PS3[i]->getAnalogButton(R2_ANALOG));
Serial.print(PS3[i]->getAnalogButton(R2));
}
}
if(PS3[i]->getButtonClick(PS)) {

View file

@ -63,14 +63,14 @@ void loop() {
}
}
//Analog button values can be read from almost all buttons
if(PS3.getAnalogButton(L2_ANALOG) || PS3.getAnalogButton(R2_ANALOG)) {
if(PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) {
if(output != "")
output += "\r\n";
output += "L2: ";
output += PS3.getAnalogButton(L2_ANALOG);
output += PS3.getAnalogButton(L2);
if(!PS3.PS3NavigationConnected) {
output += "\tR2: ";
output += PS3.getAnalogButton(R2_ANALOG);
output += PS3.getAnalogButton(R2);
}
}
if(output != "") {

View file

@ -36,11 +36,11 @@ void loop() {
Serial.print(PS3.getAnalogHat(RightHatY));
}
// Analog button values can be read from almost all buttons
if(PS3.getAnalogButton(L2_ANALOG) > 0 || PS3.getAnalogButton(R2_ANALOG) > 0) {
if(PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) {
Serial.print(F("\r\nL2: "));
Serial.print(PS3.getAnalogButton(L2_ANALOG));
Serial.print(PS3.getAnalogButton(L2));
Serial.print(F("\tR2: "));
Serial.print(PS3.getAnalogButton(R2_ANALOG));
Serial.print(PS3.getAnalogButton(R2));
}
if(PS3.getButtonClick(PS))
Serial.print(F("\r\nPS"));