diff --git a/XBOXONE.cpp b/XBOXONE.cpp index f84a090f..1acf1af4 100644 --- a/XBOXONE.cpp +++ b/XBOXONE.cpp @@ -360,6 +360,11 @@ void XBOXONE::readReport() { hatValue[RightHatX] = (int16_t)(((uint16_t)readBuf[15] << 8) | readBuf[14]); hatValue[RightHatY] = (int16_t)(((uint16_t)readBuf[17] << 8) | readBuf[16]); + // Read and store share button separately + const bool newShare = (readBuf[22] & 0x01) ? 1 : 0; + shareClicked = ((sharePressed != newShare) && newShare) ? 1 : 0; + sharePressed = newShare; + //Notify(PSTR("\r\nButtonState"), 0x80); //PrintHex(ButtonState, 0x80); @@ -378,6 +383,11 @@ void XBOXONE::readReport() { } uint16_t XBOXONE::getButtonPress(ButtonEnum b) { + // special handling for 'SHARE' button due to index collision with 'BACK', + // since the 'SHARE' value originally came from the PS4 controller and + // the 'SHARE' button was added to Xbox later with the Series S/X controllers + if (b == SHARE) return sharePressed; + const int8_t index = getButtonIndexXbox(b); if (index < 0) return 0; if(index == ButtonIndex(L2)) // These are analog buttons return triggerValue[0]; @@ -387,6 +397,15 @@ uint16_t XBOXONE::getButtonPress(ButtonEnum b) { } bool XBOXONE::getButtonClick(ButtonEnum b) { + // special handling for 'SHARE' button, ibid the above + if (b == SHARE) { + if (shareClicked) { + shareClicked = false; + return true; + } + return false; + } + const int8_t index = getButtonIndexXbox(b); if (index < 0) return 0; if(index == ButtonIndex(L2)) { if(L2Clicked) { diff --git a/XBOXONE.h b/XBOXONE.h index c89f558c..b1c84d63 100644 --- a/XBOXONE.h +++ b/XBOXONE.h @@ -231,6 +231,9 @@ private: bool L2Clicked; // These buttons are analog, so we use we use these bools to check if they where clicked or not bool R2Clicked; + bool sharePressed; // This button doesn't fit in the bitfield + bool shareClicked; + uint8_t readBuf[XBOX_ONE_EP_MAXPKTSIZE]; // General purpose buffer for input data uint8_t cmdCounter; diff --git a/examples/Xbox/XBOXONE/XBOXONE.ino b/examples/Xbox/XBOXONE/XBOXONE.ino index b49f4076..196037b5 100644 --- a/examples/Xbox/XBOXONE/XBOXONE.ino +++ b/examples/Xbox/XBOXONE/XBOXONE.ino @@ -21,7 +21,7 @@ void setup() { Serial.print(F("\r\nOSC did not start")); while (1); //halt } - Serial.print(F("\r\nXBOX USB Library Started")); + Serial.print(F("\r\nXBOX ONE USB Library Started")); } void loop() { Usb.Task(); @@ -93,6 +93,8 @@ void loop() { Serial.println(F("Xbox")); if (Xbox.getButtonClick(SYNC)) Serial.println(F("Sync")); + if (Xbox.getButtonClick(SHARE)) + Serial.println(F("Share")); if (Xbox.getButtonClick(L1)) Serial.println(F("L1"));