Merge pull request #651 from dmadison/xbox-one-share

Xbox One USB Share Button
This commit is contained in:
Kristian Sloth Lauszus 2021-07-15 12:22:55 +03:00 committed by GitHub
commit 91c2d239a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 1 deletions

View file

@ -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<uint16_t>(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) {

View file

@ -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;

View file

@ -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"));