mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Merge pull request #651 from dmadison/xbox-one-share
Xbox One USB Share Button
This commit is contained in:
commit
91c2d239a2
3 changed files with 25 additions and 1 deletions
19
XBOXONE.cpp
19
XBOXONE.cpp
|
@ -360,6 +360,11 @@ void XBOXONE::readReport() {
|
||||||
hatValue[RightHatX] = (int16_t)(((uint16_t)readBuf[15] << 8) | readBuf[14]);
|
hatValue[RightHatX] = (int16_t)(((uint16_t)readBuf[15] << 8) | readBuf[14]);
|
||||||
hatValue[RightHatY] = (int16_t)(((uint16_t)readBuf[17] << 8) | readBuf[16]);
|
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);
|
//Notify(PSTR("\r\nButtonState"), 0x80);
|
||||||
//PrintHex<uint16_t>(ButtonState, 0x80);
|
//PrintHex<uint16_t>(ButtonState, 0x80);
|
||||||
|
|
||||||
|
@ -378,6 +383,11 @@ void XBOXONE::readReport() {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t XBOXONE::getButtonPress(ButtonEnum b) {
|
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;
|
const int8_t index = getButtonIndexXbox(b); if (index < 0) return 0;
|
||||||
if(index == ButtonIndex(L2)) // These are analog buttons
|
if(index == ButtonIndex(L2)) // These are analog buttons
|
||||||
return triggerValue[0];
|
return triggerValue[0];
|
||||||
|
@ -387,6 +397,15 @@ uint16_t XBOXONE::getButtonPress(ButtonEnum b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool XBOXONE::getButtonClick(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;
|
const int8_t index = getButtonIndexXbox(b); if (index < 0) return 0;
|
||||||
if(index == ButtonIndex(L2)) {
|
if(index == ButtonIndex(L2)) {
|
||||||
if(L2Clicked) {
|
if(L2Clicked) {
|
||||||
|
|
|
@ -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 L2Clicked; // These buttons are analog, so we use we use these bools to check if they where clicked or not
|
||||||
bool R2Clicked;
|
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 readBuf[XBOX_ONE_EP_MAXPKTSIZE]; // General purpose buffer for input data
|
||||||
uint8_t cmdCounter;
|
uint8_t cmdCounter;
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ void setup() {
|
||||||
Serial.print(F("\r\nOSC did not start"));
|
Serial.print(F("\r\nOSC did not start"));
|
||||||
while (1); //halt
|
while (1); //halt
|
||||||
}
|
}
|
||||||
Serial.print(F("\r\nXBOX USB Library Started"));
|
Serial.print(F("\r\nXBOX ONE USB Library Started"));
|
||||||
}
|
}
|
||||||
void loop() {
|
void loop() {
|
||||||
Usb.Task();
|
Usb.Task();
|
||||||
|
@ -93,6 +93,8 @@ void loop() {
|
||||||
Serial.println(F("Xbox"));
|
Serial.println(F("Xbox"));
|
||||||
if (Xbox.getButtonClick(SYNC))
|
if (Xbox.getButtonClick(SYNC))
|
||||||
Serial.println(F("Sync"));
|
Serial.println(F("Sync"));
|
||||||
|
if (Xbox.getButtonClick(SHARE))
|
||||||
|
Serial.println(F("Share"));
|
||||||
|
|
||||||
if (Xbox.getButtonClick(L1))
|
if (Xbox.getButtonClick(L1))
|
||||||
Serial.println(F("L1"));
|
Serial.println(F("L1"));
|
||||||
|
|
Loading…
Reference in a new issue