diff --git a/PS3BT.cpp b/PS3BT.cpp index 0a320b3f..02c54898 100644 --- a/PS3BT.cpp +++ b/PS3BT.cpp @@ -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) diff --git a/PS3BT.h b/PS3BT.h index b9f6bb97..c989b8cc 100644 --- a/PS3BT.h +++ b/PS3BT.h @@ -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); diff --git a/PS3Enums.h b/PS3Enums.h index b8f10c3a..f6622a51 100644 --- a/PS3Enums.h +++ b/PS3Enums.h @@ -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, diff --git a/PS3USB.cpp b/PS3USB.cpp index 79cd1cd4..c1b8f65a 100644 --- a/PS3USB.cpp +++ b/PS3USB.cpp @@ -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) diff --git a/PS3USB.h b/PS3USB.h index f434e268..1735c91a 100644 --- a/PS3USB.h +++ b/PS3USB.h @@ -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); diff --git a/Wii.cpp b/Wii.cpp index 81528095..43694c81 100755 --- a/Wii.cpp +++ b/Wii.cpp @@ -44,7 +44,6 @@ const uint32_t BUTTONS[] PROGMEM = { 0x00004, // DOWN 0x00001, // LEFT - 0x00010, // PLUS 0x00100, // TWO diff --git a/controllerEnums.h b/controllerEnums.h index 9fdbdae0..108e6cc8 100644 --- a/controllerEnums.h +++ b/controllerEnums.h @@ -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 \ No newline at end of file diff --git a/examples/Bluetooth/PS3BT/PS3BT.ino b/examples/Bluetooth/PS3BT/PS3BT.ino index 3b3561e7..9bd63261 100644 --- a/examples/Bluetooth/PS3BT/PS3BT.ino +++ b/examples/Bluetooth/PS3BT/PS3BT.ino @@ -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")); diff --git a/examples/Bluetooth/PS3Multi/PS3Multi.ino b/examples/Bluetooth/PS3Multi/PS3Multi.ino index 595d0b69..98bc19a4 100644 --- a/examples/Bluetooth/PS3Multi/PS3Multi.ino +++ b/examples/Bluetooth/PS3Multi/PS3Multi.ino @@ -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)) { diff --git a/examples/Bluetooth/PS3SPP/PS3SPP.ino b/examples/Bluetooth/PS3SPP/PS3SPP.ino index e857897a..af8c1324 100644 --- a/examples/Bluetooth/PS3SPP/PS3SPP.ino +++ b/examples/Bluetooth/PS3SPP/PS3SPP.ino @@ -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 != "") { diff --git a/examples/PS3USB/PS3USB.ino b/examples/PS3USB/PS3USB.ino index a516175e..36ac61ea 100644 --- a/examples/PS3USB/PS3USB.ino +++ b/examples/PS3USB/PS3USB.ino @@ -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"));