From 6e63210c2a42b5af295b002f8919a4b0e989ed98 Mon Sep 17 00:00:00 2001 From: David Madison Date: Thu, 1 Jul 2021 04:42:23 -0400 Subject: [PATCH 1/7] Add Xbox trigger enum options Bumper and trigger in place of 1/2, as used on the Playstation controllers. --- controllerEnums.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/controllerEnums.h b/controllerEnums.h index b45d8847..72e86191 100644 --- a/controllerEnums.h +++ b/controllerEnums.h @@ -143,10 +143,10 @@ enum ButtonEnum { BACK, // START, // listed under Playstation buttons - // L1, // listed under Playstation buttons - // R1, // listed under Playstation buttons - // L2, // listed under Playstation buttons - // R2, // listed under Playstation buttons + LB, + RB, + LT, + RT, XBOX, SYNC, @@ -199,10 +199,10 @@ inline constexpr int8_t ButtonIndex(ButtonEnum key) { (key == START || key == OPTIONS || key == MENU || key == PLUS) ? 5 : (key == L3 || key == TWO) ? 6 : (key == R3 || key == ONE) ? 7 : - (key == L2 || key == MINUS || key == BLACK) ? 8 : - (key == R2 || key == HOME || key == WHITE) ? 9 : - (key == L1 || key == Z) ? 10 : - (key == R1 || key == C) ? 11 : + (key == L2 || key == LT || key == MINUS || key == BLACK) ? 8 : + (key == R2 || key == RT || key == HOME || key == WHITE) ? 9 : + (key == L1 || key == LB || key == Z) ? 10 : + (key == R1 || key == RB || key == C) ? 11 : (key == TRIANGLE || key == B) ? 12 : (key == CIRCLE || key == A) ? 13 : (key == CROSS || key == X) ? 14 : From 99e01d3a98d2ff637d875b953ea7d7163dd24056 Mon Sep 17 00:00:00 2001 From: David Madison Date: Thu, 1 Jul 2021 04:56:20 -0400 Subject: [PATCH 2/7] Transform Xbox old trigger enums This is required to get the "correct" output from the trigger and bumper enums, which for legacy reasons do not match up with the L1/L2 keys indices. --- XBOXOLD.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/XBOXOLD.cpp b/XBOXOLD.cpp index 1d38b694..a454d22a 100644 --- a/XBOXOLD.cpp +++ b/XBOXOLD.cpp @@ -293,6 +293,19 @@ void XBOXOLD::printReport(uint16_t length __attribute__((unused))) { //Uncomment } int8_t XBOXOLD::getAnalogIndex(ButtonEnum b) { + // For legacy reasons these mapping indices not match up, + // as the original code uses L1/R1 for the triggers and + // L2/R2 for the white/black buttons. To fix these new enums + // we have to transpose the keys before passing them through + // the button index function + switch (b) { + case(LT): b = L1; break; // normally L2 + case(RT): b = R1; break; // normally R2 + case(LB): b = WHITE; break; // normally L1 + case(RB): b = BLACK; break; // normally R1 + default: break; + } + // A, B, X, Y, BLACK, WHITE, L1, and R1 are analog buttons const int8_t index = ButtonIndex(b); From ac7c1acd9f8759d5f83cee979b8d6474e68e8a69 Mon Sep 17 00:00:00 2001 From: David Madison Date: Sat, 6 Mar 2021 09:36:11 -0500 Subject: [PATCH 3/7] XboxOld: Use VID and PID function check in init Avoiding duplicating the VID/PID check logic in multiple places --- XBOXOLD.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XBOXOLD.cpp b/XBOXOLD.cpp index a454d22a..87e7c644 100644 --- a/XBOXOLD.cpp +++ b/XBOXOLD.cpp @@ -118,7 +118,7 @@ uint8_t XBOXOLD::Init(uint8_t parent, uint8_t port, bool lowspeed) { VID = udd->idVendor; PID = udd->idProduct; - if((VID != XBOX_VID && VID != MADCATZ_VID && VID != JOYTECH_VID) || (PID != XBOX_OLD_PID1 && PID != XBOX_OLD_PID2 && PID != XBOX_OLD_PID3 && PID != XBOX_OLD_PID4)) // Check if VID and PID match + if(!VIDPIDOK(VID, PID)) // Check if VID and PID match goto FailUnknownDevice; // Allocate new address according to device class From 680ddcfc9daaf238461d5d8bc218946abc3eb958 Mon Sep 17 00:00:00 2001 From: David Madison Date: Sat, 6 Mar 2021 09:38:03 -0500 Subject: [PATCH 4/7] XboxOld: Add Logitech Cordless Precision support --- XBOXOLD.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/XBOXOLD.h b/XBOXOLD.h index 9acd3a4e..74ea337a 100644 --- a/XBOXOLD.h +++ b/XBOXOLD.h @@ -34,11 +34,13 @@ #define XBOX_VID 0x045E // Microsoft Corporation #define MADCATZ_VID 0x1BAD // For unofficial Mad Catz controllers #define JOYTECH_VID 0x162E // For unofficial Joytech controllers +#define LOGITECH_VID 0x046D // For official Logitech controllers #define XBOX_OLD_PID1 0x0202 // Original Microsoft Xbox controller (US) #define XBOX_OLD_PID2 0x0285 // Original Microsoft Xbox controller (Japan) #define XBOX_OLD_PID3 0x0287 // Microsoft Microsoft Xbox Controller S #define XBOX_OLD_PID4 0x0289 // Smaller Microsoft Xbox controller (US) +#define XBOX_OLD_PID5 0xCA84 // Logitech Cordless Precision controller #define XBOX_MAX_ENDPOINTS 3 @@ -94,7 +96,7 @@ public: * @return Returns true if the device's VID and PID matches this driver. */ virtual bool VIDPIDOK(uint16_t vid, uint16_t pid) { - return ((vid == XBOX_VID || vid == MADCATZ_VID || vid == JOYTECH_VID) && (pid == XBOX_OLD_PID1 || pid == XBOX_OLD_PID2 || pid == XBOX_OLD_PID3 || pid == XBOX_OLD_PID4)); + return ((vid == XBOX_VID || vid == MADCATZ_VID || vid == JOYTECH_VID || vid == LOGITECH_VID) && (pid == XBOX_OLD_PID1 || pid == XBOX_OLD_PID2 || pid == XBOX_OLD_PID3 || pid == XBOX_OLD_PID4 || pid == XBOX_OLD_PID5)); }; /**@}*/ From 135608c0ce0f2f377d7db626f23180ae1b8f0e0a Mon Sep 17 00:00:00 2001 From: David Madison Date: Thu, 1 Jul 2021 05:08:07 -0400 Subject: [PATCH 5/7] Change Xbox LT/LB/RT/RB references in examples --- examples/Xbox/XBOXOLD/XBOXOLD.ino | 12 +++---- examples/Xbox/XBOXONE/XBOXONE.ino | 30 +++++++++--------- examples/Xbox/XBOXONESBT/XBOXONESBT.ino | 42 ++++++++++++------------- examples/Xbox/XBOXRECV/XBOXRECV.ino | 20 ++++++------ examples/Xbox/XBOXUSB/XBOXUSB.ino | 20 ++++++------ 5 files changed, 62 insertions(+), 62 deletions(-) diff --git a/examples/Xbox/XBOXOLD/XBOXOLD.ino b/examples/Xbox/XBOXOLD/XBOXOLD.ino index 086c3290..9e8e409c 100644 --- a/examples/Xbox/XBOXOLD/XBOXOLD.ino +++ b/examples/Xbox/XBOXOLD/XBOXOLD.ino @@ -97,13 +97,13 @@ void loop() { Serial.print(F("Y: ")); Serial.println(Xbox.getButtonPress(Y)); } - if (Xbox.getButtonPress(L1)) { - Serial.print(F("L1: ")); - Serial.println(Xbox.getButtonPress(L1)); + if (Xbox.getButtonPress(LT)) { + Serial.print(F("LT: ")); + Serial.println(Xbox.getButtonPress(LT)); } - if (Xbox.getButtonPress(R1)) { - Serial.print(F("R1: ")); - Serial.println(Xbox.getButtonPress(R1)); + if (Xbox.getButtonPress(RT)) { + Serial.print(F("RT: ")); + Serial.println(Xbox.getButtonPress(RT)); } } delay(1); diff --git a/examples/Xbox/XBOXONE/XBOXONE.ino b/examples/Xbox/XBOXONE/XBOXONE.ino index b49f4076..05c576ac 100644 --- a/examples/Xbox/XBOXONE/XBOXONE.ino +++ b/examples/Xbox/XBOXONE/XBOXONE.ino @@ -49,15 +49,15 @@ void loop() { Serial.println(); } - if (Xbox.getButtonPress(L2) > 0 || Xbox.getButtonPress(R2) > 0) { - if (Xbox.getButtonPress(L2) > 0) { - Serial.print(F("L2: ")); - Serial.print(Xbox.getButtonPress(L2)); + if (Xbox.getButtonPress(LT) > 0 || Xbox.getButtonPress(RT) > 0) { + if (Xbox.getButtonPress(LT) > 0) { + Serial.print(F("LT: ")); + Serial.print(Xbox.getButtonPress(LT)); Serial.print("\t"); } - if (Xbox.getButtonPress(R2) > 0) { - Serial.print(F("R2: ")); - Serial.print(Xbox.getButtonPress(R2)); + if (Xbox.getButtonPress(RT) > 0) { + Serial.print(F("RT: ")); + Serial.print(Xbox.getButtonPress(RT)); Serial.print("\t"); } Serial.println(); @@ -94,14 +94,14 @@ void loop() { if (Xbox.getButtonClick(SYNC)) Serial.println(F("Sync")); - if (Xbox.getButtonClick(L1)) - Serial.println(F("L1")); - if (Xbox.getButtonClick(R1)) - Serial.println(F("R1")); - if (Xbox.getButtonClick(L2)) - Serial.println(F("L2")); - if (Xbox.getButtonClick(R2)) - Serial.println(F("R2")); + if (Xbox.getButtonClick(LB)) + Serial.println(F("LB")); + if (Xbox.getButtonClick(RB)) + Serial.println(F("RB")); + if (Xbox.getButtonClick(LT)) + Serial.println(F("LT")); + if (Xbox.getButtonClick(RT)) + Serial.println(F("RT")); if (Xbox.getButtonClick(L3)) Serial.println(F("L3")); if (Xbox.getButtonClick(R3)) diff --git a/examples/Xbox/XBOXONESBT/XBOXONESBT.ino b/examples/Xbox/XBOXONESBT/XBOXONESBT.ino index e7d6c419..eed1e255 100644 --- a/examples/Xbox/XBOXONESBT/XBOXONESBT.ino +++ b/examples/Xbox/XBOXONESBT/XBOXONESBT.ino @@ -63,27 +63,27 @@ void loop() { Serial.println(); } - if (Xbox.getButtonPress(L2) > 0 || Xbox.getButtonPress(R2) > 0) { - if (Xbox.getButtonPress(L2) > 0) { - Serial.print(F("L2: ")); - Serial.print(Xbox.getButtonPress(L2)); + if (Xbox.getButtonPress(LT) > 0 || Xbox.getButtonPress(RT) > 0) { + if (Xbox.getButtonPress(LT) > 0) { + Serial.print(F("LT: ")); + Serial.print(Xbox.getButtonPress(LT)); Serial.print("\t"); } - if (Xbox.getButtonPress(R2) > 0) { - Serial.print(F("R2: ")); - Serial.print(Xbox.getButtonPress(R2)); + if (Xbox.getButtonPress(RT) > 0) { + Serial.print(F("RT: ")); + Serial.print(Xbox.getButtonPress(RT)); Serial.print("\t"); } Serial.println(); } // Set rumble effect - static uint16_t oldL2Value, oldR2Value; - if (Xbox.getButtonPress(L2) != oldL2Value || Xbox.getButtonPress(R2) != oldR2Value) { - oldL2Value = Xbox.getButtonPress(L2); - oldR2Value = Xbox.getButtonPress(R2); - uint8_t leftRumble = map(oldL2Value, 0, 1023, 0, 255); // Map the trigger values into a byte - uint8_t rightRumble = map(oldR2Value, 0, 1023, 0, 255); + static uint16_t oldLTValue, oldRTValue; + if (Xbox.getButtonPress(LT) != oldLTValue || Xbox.getButtonPress(RT) != oldRTValue) { + oldLTValue = Xbox.getButtonPress(LT); + oldRTValue = Xbox.getButtonPress(RT); + uint8_t leftRumble = map(oldLTValue, 0, 1023, 0, 255); // Map the trigger values into a byte + uint8_t rightRumble = map(oldRTValue, 0, 1023, 0, 255); if (leftRumble > 0 || rightRumble > 0) Xbox.setRumbleOn(leftRumble, rightRumble, leftRumble, rightRumble); else @@ -108,14 +108,14 @@ void loop() { Xbox.disconnect(); } - if (Xbox.getButtonClick(L1)) - Serial.println(F("L1")); - if (Xbox.getButtonClick(R1)) - Serial.println(F("R1")); - if (Xbox.getButtonClick(L2)) - Serial.println(F("L2")); - if (Xbox.getButtonClick(R2)) - Serial.println(F("R2")); + if (Xbox.getButtonClick(LB)) + Serial.println(F("LB")); + if (Xbox.getButtonClick(RB)) + Serial.println(F("RB")); + if (Xbox.getButtonClick(LT)) + Serial.println(F("LT")); + if (Xbox.getButtonClick(RT)) + Serial.println(F("RT")); if (Xbox.getButtonClick(L3)) Serial.println(F("L3")); if (Xbox.getButtonClick(R3)) diff --git a/examples/Xbox/XBOXRECV/XBOXRECV.ino b/examples/Xbox/XBOXRECV/XBOXRECV.ino index 4b10a63a..9faf28e3 100644 --- a/examples/Xbox/XBOXRECV/XBOXRECV.ino +++ b/examples/Xbox/XBOXRECV/XBOXRECV.ino @@ -32,12 +32,12 @@ void loop() { if (Xbox.XboxReceiverConnected) { for (uint8_t i = 0; i < 4; i++) { if (Xbox.Xbox360Connected[i]) { - if (Xbox.getButtonPress(L2, i) || Xbox.getButtonPress(R2, i)) { - Serial.print("L2: "); - Serial.print(Xbox.getButtonPress(L2, i)); - Serial.print("\tR2: "); - Serial.println(Xbox.getButtonPress(R2, i)); - Xbox.setRumbleOn(Xbox.getButtonPress(L2, i), Xbox.getButtonPress(R2, i), i); + if (Xbox.getButtonPress(LT, i) || Xbox.getButtonPress(RT, i)) { + Serial.print("LT: "); + Serial.print(Xbox.getButtonPress(LT, i)); + Serial.print("\tRT: "); + Serial.println(Xbox.getButtonPress(RT, i)); + Xbox.setRumbleOn(Xbox.getButtonPress(LT, i), Xbox.getButtonPress(RT, i), i); } if (Xbox.getAnalogHat(LeftHatX, i) > 7500 || Xbox.getAnalogHat(LeftHatX, i) < -7500 || Xbox.getAnalogHat(LeftHatY, i) > 7500 || Xbox.getAnalogHat(LeftHatY, i) < -7500 || Xbox.getAnalogHat(RightHatX, i) > 7500 || Xbox.getAnalogHat(RightHatX, i) < -7500 || Xbox.getAnalogHat(RightHatY, i) > 7500 || Xbox.getAnalogHat(RightHatY, i) < -7500) { @@ -93,10 +93,10 @@ void loop() { if (Xbox.getButtonClick(R3, i)) Serial.println(F("R3")); - if (Xbox.getButtonClick(L1, i)) - Serial.println(F("L1")); - if (Xbox.getButtonClick(R1, i)) - Serial.println(F("R1")); + if (Xbox.getButtonClick(LB, i)) + Serial.println(F("LB")); + if (Xbox.getButtonClick(RB, i)) + Serial.println(F("RB")); if (Xbox.getButtonClick(XBOX, i)) { Xbox.setLedMode(ROTATING, i); Serial.print(F("Xbox (Battery: ")); diff --git a/examples/Xbox/XBOXUSB/XBOXUSB.ino b/examples/Xbox/XBOXUSB/XBOXUSB.ino index 29dfbccb..66524a6b 100644 --- a/examples/Xbox/XBOXUSB/XBOXUSB.ino +++ b/examples/Xbox/XBOXUSB/XBOXUSB.ino @@ -29,12 +29,12 @@ void setup() { void loop() { Usb.Task(); if (Xbox.Xbox360Connected) { - if (Xbox.getButtonPress(L2) || Xbox.getButtonPress(R2)) { - Serial.print("L2: "); - Serial.print(Xbox.getButtonPress(L2)); - Serial.print("\tR2: "); - Serial.println(Xbox.getButtonPress(R2)); - Xbox.setRumbleOn(Xbox.getButtonPress(L2), Xbox.getButtonPress(R2)); + if (Xbox.getButtonPress(LT) || Xbox.getButtonPress(RT)) { + Serial.print("LT: "); + Serial.print(Xbox.getButtonPress(LT)); + Serial.print("\tRT: "); + Serial.println(Xbox.getButtonPress(RT)); + Xbox.setRumbleOn(Xbox.getButtonPress(LT), Xbox.getButtonPress(RT)); } else Xbox.setRumbleOn(0, 0); @@ -91,10 +91,10 @@ void loop() { if (Xbox.getButtonClick(R3)) Serial.println(F("R3")); - if (Xbox.getButtonClick(L1)) - Serial.println(F("L1")); - if (Xbox.getButtonClick(R1)) - Serial.println(F("R1")); + if (Xbox.getButtonClick(LB)) + Serial.println(F("LB")); + if (Xbox.getButtonClick(RB)) + Serial.println(F("RB")); if (Xbox.getButtonClick(XBOX)) { Xbox.setLedMode(ROTATING); Serial.println(F("Xbox")); From db31a4d125cad0acce8ff94675fc400c9e073bc5 Mon Sep 17 00:00:00 2001 From: David Madison Date: Mon, 5 Jul 2021 04:22:44 -0400 Subject: [PATCH 6/7] Add Xbox bumper and trigger enums to keywords --- keywords.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/keywords.txt b/keywords.txt index 3c4b7487..caa7920d 100644 --- a/keywords.txt +++ b/keywords.txt @@ -253,6 +253,12 @@ B LITERAL1 X LITERAL1 Y LITERAL1 +LB LITERAL1 +RB LITERAL1 + +LT LITERAL1 +RT LITERAL1 + #################################################### # Syntax Coloring Map For RFCOMM/SPP Library #################################################### From 8e78fc202e804d12ddc68043ad1ffa202b861d5c Mon Sep 17 00:00:00 2001 From: David Madison Date: Mon, 5 Jul 2021 04:26:13 -0400 Subject: [PATCH 7/7] Change Xbox LT/LB/RT/RB rumble ref in example Missed this one in 135608c. --- examples/Xbox/XBOXONE/XBOXONE.ino | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/Xbox/XBOXONE/XBOXONE.ino b/examples/Xbox/XBOXONE/XBOXONE.ino index 05c576ac..67ebadce 100644 --- a/examples/Xbox/XBOXONE/XBOXONE.ino +++ b/examples/Xbox/XBOXONE/XBOXONE.ino @@ -64,12 +64,12 @@ void loop() { } // Set rumble effect - static uint16_t oldL2Value, oldR2Value; - if (Xbox.getButtonPress(L2) != oldL2Value || Xbox.getButtonPress(R2) != oldR2Value) { - oldL2Value = Xbox.getButtonPress(L2); - oldR2Value = Xbox.getButtonPress(R2); - uint8_t leftRumble = map(oldL2Value, 0, 1023, 0, 255); // Map the trigger values into a byte - uint8_t rightRumble = map(oldR2Value, 0, 1023, 0, 255); + static uint16_t oldLTValue, oldRTValue; + if (Xbox.getButtonPress(LT) != oldLTValue || Xbox.getButtonPress(RT) != oldRTValue) { + oldLTValue = Xbox.getButtonPress(LT); + oldRTValue = Xbox.getButtonPress(RT); + uint8_t leftRumble = map(oldLTValue, 0, 1023, 0, 255); // Map the trigger values into a byte + uint8_t rightRumble = map(oldRTValue, 0, 1023, 0, 255); if (leftRumble > 0 || rightRumble > 0) Xbox.setRumbleOn(leftRumble, rightRumble, leftRumble, rightRumble); else