mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Fixed conflict between analog buttons and digital buttons
This commit is contained in:
parent
8ed3fcd3b8
commit
391f5ece4d
11 changed files with 58 additions and 57 deletions
|
@ -69,10 +69,10 @@ bool PS3BT::getButtonClick(Button b) {
|
||||||
ButtonClickState &= ~button; // clear "click" event
|
ButtonClickState &= ~button; // clear "click" event
|
||||||
return click;
|
return click;
|
||||||
}
|
}
|
||||||
uint8_t PS3BT::getAnalogButton(AnalogButton a) {
|
uint8_t PS3BT::getAnalogButton(Button a) {
|
||||||
if (l2capinbuf == NULL)
|
if (l2capinbuf == NULL)
|
||||||
return 0;
|
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) {
|
uint8_t PS3BT::getAnalogHat(AnalogHat a) {
|
||||||
if (l2capinbuf == NULL)
|
if (l2capinbuf == NULL)
|
||||||
|
|
2
PS3BT.h
2
PS3BT.h
|
@ -77,7 +77,7 @@ public:
|
||||||
bool getButtonPress(Button b);
|
bool getButtonPress(Button b);
|
||||||
bool getButtonClick(Button b);
|
bool getButtonClick(Button b);
|
||||||
|
|
||||||
uint8_t getAnalogButton(AnalogButton a);
|
uint8_t getAnalogButton(Button a);
|
||||||
uint8_t getAnalogHat(AnalogHat a);
|
uint8_t getAnalogHat(AnalogHat a);
|
||||||
int16_t getSensor(Sensor a);
|
int16_t getSensor(Sensor a);
|
||||||
double getAngle(Angle a);
|
double getAngle(Angle a);
|
||||||
|
|
44
PS3Enums.h
44
PS3Enums.h
|
@ -38,7 +38,6 @@ const uint32_t BUTTONS[] PROGMEM = {
|
||||||
0x20, // RIGHT
|
0x20, // RIGHT
|
||||||
0x40, // DOWN
|
0x40, // DOWN
|
||||||
0x80, // LEFT
|
0x80, // LEFT
|
||||||
0,0,0,0,0,0,0,0,0, // Skip buttons used by Wii library
|
|
||||||
|
|
||||||
0x01, // SELECT
|
0x01, // SELECT
|
||||||
0x02, // L3
|
0x02, // L3
|
||||||
|
@ -60,6 +59,29 @@ const uint32_t BUTTONS[] PROGMEM = {
|
||||||
0x100000 // T - covers 12 bits - we only need to read the top 8
|
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 {
|
enum Colors {
|
||||||
// Used to set the colors of the move controller
|
// Used to set the colors of the move controller
|
||||||
Red = 0xFF0000, // r = 255, g = 0, b = 0
|
Red = 0xFF0000, // r = 255, g = 0, b = 0
|
||||||
|
@ -73,26 +95,6 @@ enum Colors {
|
||||||
White = 0xFFFFFF, // r = 255, g = 255, b = 255
|
White = 0xFFFFFF, // r = 255, g = 255, b = 255
|
||||||
Off = 0x00, // r = 0, g = 0, b = 0
|
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 {
|
enum AnalogHat {
|
||||||
// Note that the location is shiftet 9 when it's connected via USB
|
// Note that the location is shiftet 9 when it's connected via USB
|
||||||
LeftHatX = 15,
|
LeftHatX = 15,
|
||||||
|
|
|
@ -335,10 +335,10 @@ bool PS3USB::getButtonClick(Button b) {
|
||||||
ButtonClickState &= ~button; // clear "click" event
|
ButtonClickState &= ~button; // clear "click" event
|
||||||
return click;
|
return click;
|
||||||
}
|
}
|
||||||
uint8_t PS3USB::getAnalogButton(AnalogButton a) {
|
uint8_t PS3USB::getAnalogButton(Button a) {
|
||||||
if (readBuf == NULL)
|
if (readBuf == NULL)
|
||||||
return 0;
|
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) {
|
uint8_t PS3USB::getAnalogHat(AnalogHat a) {
|
||||||
if (readBuf == NULL)
|
if (readBuf == NULL)
|
||||||
|
|
2
PS3USB.h
2
PS3USB.h
|
@ -77,7 +77,7 @@ public:
|
||||||
bool getButtonPress(Button b);
|
bool getButtonPress(Button b);
|
||||||
bool getButtonClick(Button b);
|
bool getButtonClick(Button b);
|
||||||
|
|
||||||
uint8_t getAnalogButton(AnalogButton a);
|
uint8_t getAnalogButton(Button a);
|
||||||
uint8_t getAnalogHat(AnalogHat a);
|
uint8_t getAnalogHat(AnalogHat a);
|
||||||
uint16_t getSensor(Sensor a);
|
uint16_t getSensor(Sensor a);
|
||||||
double getAngle(Angle a);
|
double getAngle(Angle a);
|
||||||
|
|
1
Wii.cpp
1
Wii.cpp
|
@ -44,7 +44,6 @@ const uint32_t BUTTONS[] PROGMEM = {
|
||||||
0x00004, // DOWN
|
0x00004, // DOWN
|
||||||
0x00001, // LEFT
|
0x00001, // LEFT
|
||||||
|
|
||||||
|
|
||||||
0x00010, // PLUS
|
0x00010, // PLUS
|
||||||
|
|
||||||
0x00100, // TWO
|
0x00100, // TWO
|
||||||
|
|
|
@ -51,24 +51,24 @@ enum Button {
|
||||||
C = 12,
|
C = 12,
|
||||||
|
|
||||||
/* PS3 controllers buttons */
|
/* PS3 controllers buttons */
|
||||||
SELECT = 13,
|
SELECT = 4,
|
||||||
L3 = 14,
|
L3 = 5,
|
||||||
R3 = 15,
|
R3 = 6,
|
||||||
START = 16,
|
START = 7,
|
||||||
|
|
||||||
L2 = 17,
|
L2 = 8,
|
||||||
R2 = 18,
|
R2 = 9,
|
||||||
L1 = 19,
|
L1 = 10,
|
||||||
R1 = 20,
|
R1 = 11,
|
||||||
TRIANGLE = 21,
|
TRIANGLE = 12,
|
||||||
CIRCLE = 22,
|
CIRCLE = 13,
|
||||||
CROSS = 23,
|
CROSS = 14,
|
||||||
SQUARE = 24,
|
SQUARE = 15,
|
||||||
|
|
||||||
PS = 25,
|
PS = 16,
|
||||||
|
|
||||||
MOVE = 26, // 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 = 27, // 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
|
#endif
|
|
@ -40,12 +40,12 @@ void loop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Analog button values can be read from almost all buttons
|
//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(F("\r\nL2: "));
|
||||||
Serial.print(PS3.getAnalogButton(L2_ANALOG));
|
Serial.print(PS3.getAnalogButton(L2));
|
||||||
if(!PS3.PS3NavigationConnected) {
|
if(!PS3.PS3NavigationConnected) {
|
||||||
Serial.print(F("\tR2: "));
|
Serial.print(F("\tR2: "));
|
||||||
Serial.print(PS3.getAnalogButton(R2_ANALOG));
|
Serial.print(PS3.getAnalogButton(R2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(PS3.getButtonClick(PS)) {
|
if(PS3.getButtonClick(PS)) {
|
||||||
|
@ -117,9 +117,9 @@ void loop() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(PS3.PS3MoveConnected) {
|
else if(PS3.PS3MoveConnected) {
|
||||||
if(PS3.getAnalogButton(T_ANALOG) > 0) {
|
if(PS3.getAnalogButton(T)) {
|
||||||
Serial.print(F("\r\nT: "));
|
Serial.print(F("\r\nT: "));
|
||||||
Serial.print(PS3.getAnalogButton(T_ANALOG));
|
Serial.print(PS3.getAnalogButton(T));
|
||||||
}
|
}
|
||||||
if(PS3.getButtonClick(PS)) {
|
if(PS3.getButtonClick(PS)) {
|
||||||
Serial.print(F("\r\nPS"));
|
Serial.print(F("\r\nPS"));
|
||||||
|
|
|
@ -47,12 +47,12 @@ void loop() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Analog button values can be read from almost all buttons
|
//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(F("\r\nL2: "));
|
||||||
Serial.print(PS3[i]->getAnalogButton(L2_ANALOG));
|
Serial.print(PS3[i]->getAnalogButton(L2));
|
||||||
if(!PS3[i]->PS3NavigationConnected) {
|
if(!PS3[i]->PS3NavigationConnected) {
|
||||||
Serial.print(F("\tR2: "));
|
Serial.print(F("\tR2: "));
|
||||||
Serial.print(PS3[i]->getAnalogButton(R2_ANALOG));
|
Serial.print(PS3[i]->getAnalogButton(R2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(PS3[i]->getButtonClick(PS)) {
|
if(PS3[i]->getButtonClick(PS)) {
|
||||||
|
|
|
@ -63,14 +63,14 @@ void loop() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Analog button values can be read from almost all buttons
|
//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 != "")
|
if(output != "")
|
||||||
output += "\r\n";
|
output += "\r\n";
|
||||||
output += "L2: ";
|
output += "L2: ";
|
||||||
output += PS3.getAnalogButton(L2_ANALOG);
|
output += PS3.getAnalogButton(L2);
|
||||||
if(!PS3.PS3NavigationConnected) {
|
if(!PS3.PS3NavigationConnected) {
|
||||||
output += "\tR2: ";
|
output += "\tR2: ";
|
||||||
output += PS3.getAnalogButton(R2_ANALOG);
|
output += PS3.getAnalogButton(R2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(output != "") {
|
if(output != "") {
|
||||||
|
|
|
@ -36,11 +36,11 @@ void loop() {
|
||||||
Serial.print(PS3.getAnalogHat(RightHatY));
|
Serial.print(PS3.getAnalogHat(RightHatY));
|
||||||
}
|
}
|
||||||
// Analog button values can be read from almost all buttons
|
// 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(F("\r\nL2: "));
|
||||||
Serial.print(PS3.getAnalogButton(L2_ANALOG));
|
Serial.print(PS3.getAnalogButton(L2));
|
||||||
Serial.print(F("\tR2: "));
|
Serial.print(F("\tR2: "));
|
||||||
Serial.print(PS3.getAnalogButton(R2_ANALOG));
|
Serial.print(PS3.getAnalogButton(R2));
|
||||||
}
|
}
|
||||||
if(PS3.getButtonClick(PS))
|
if(PS3.getButtonClick(PS))
|
||||||
Serial.print(F("\r\nPS"));
|
Serial.print(F("\r\nPS"));
|
||||||
|
|
Loading…
Reference in a new issue