mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Check direct enum comparisons by index
To not break support for users who used the "wrong" control enumeration for that controller, but had their program work because the "wrong" enum used the same ID.
This commit is contained in:
parent
f9a408204d
commit
57afaefd2c
6 changed files with 39 additions and 37 deletions
|
@ -70,9 +70,10 @@ bool PS4Parser::getButtonClick(ButtonEnum b) {
|
|||
}
|
||||
|
||||
uint8_t PS4Parser::getAnalogButton(ButtonEnum b) {
|
||||
if (b == L2) // These are the only analog buttons on the controller
|
||||
const int8_t index = getButtonIndex(b); if (index < 0) return 0;
|
||||
if (index == legacyButtonValues(L2)) // These are the only analog buttons on the controller
|
||||
return ps4Data.trigger[0];
|
||||
else if (b == R2)
|
||||
else if (index == legacyButtonValues(R2))
|
||||
return ps4Data.trigger[1];
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -74,9 +74,10 @@ bool PS5Parser::getButtonClick(ButtonEnum b) {
|
|||
}
|
||||
|
||||
uint8_t PS5Parser::getAnalogButton(ButtonEnum b) {
|
||||
if (b == L2) // These are the only analog buttons on the controller
|
||||
const int8_t index = getButtonIndex(b); if (index < 0) return 0;
|
||||
if (index == legacyButtonValues(L2)) // These are the only analog buttons on the controller
|
||||
return ps5Data.trigger[0];
|
||||
else if (b == R2)
|
||||
else if (index == legacyButtonValues(R2))
|
||||
return ps5Data.trigger[1];
|
||||
return 0;
|
||||
}
|
||||
|
|
14
XBOXONE.cpp
14
XBOXONE.cpp
|
@ -378,29 +378,29 @@ void XBOXONE::readReport() {
|
|||
}
|
||||
|
||||
uint16_t XBOXONE::getButtonPress(ButtonEnum b) {
|
||||
if(b == L2) // These are analog buttons
|
||||
return triggerValue[0];
|
||||
else if(b == R2)
|
||||
return triggerValue[1];
|
||||
const int8_t index = getXboxButtonIndex(b); if (index < 0) return 0;
|
||||
if(index == legacyButtonValues(L2)) // These are analog buttons
|
||||
return triggerValue[0];
|
||||
else if(index == legacyButtonValues(R2))
|
||||
return triggerValue[1];
|
||||
return (bool)(ButtonState & ((uint16_t)pgm_read_word(&XBOX_BUTTONS[index])));
|
||||
}
|
||||
|
||||
bool XBOXONE::getButtonClick(ButtonEnum b) {
|
||||
if(b == L2) {
|
||||
const int8_t index = getXboxButtonIndex(b); if (index < 0) return 0;
|
||||
if(index == legacyButtonValues(L2)) {
|
||||
if(L2Clicked) {
|
||||
L2Clicked = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} else if(b == R2) {
|
||||
} else if(index == legacyButtonValues(R2)) {
|
||||
if(R2Clicked) {
|
||||
R2Clicked = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
const int8_t index = getXboxButtonIndex(b); if (index < 0) return 0;
|
||||
uint16_t button = pgm_read_word(&XBOX_BUTTONS[index]);
|
||||
bool click = (ButtonClickState & button);
|
||||
ButtonClickState &= ~button; // Clear "click" event
|
||||
|
|
|
@ -76,37 +76,37 @@ bool XBOXONESParser::checkDpad(ButtonEnum b) {
|
|||
}
|
||||
|
||||
uint16_t XBOXONESParser::getButtonPress(ButtonEnum b) {
|
||||
if (b == L2)
|
||||
return xboxOneSData.trigger[0];
|
||||
else if (b == R2)
|
||||
return xboxOneSData.trigger[1];
|
||||
else if (b <= LEFT) // Dpad
|
||||
return checkDpad(b);
|
||||
else if (b == XBOX)
|
||||
return xboxButtonState;
|
||||
const int8_t index = getButtonIndex(b); if (index < 0) return 0;
|
||||
if (index == legacyButtonValues(L2))
|
||||
return xboxOneSData.trigger[0];
|
||||
else if (index == legacyButtonValues(R2))
|
||||
return xboxOneSData.trigger[1];
|
||||
else if (index <= LEFT) // Dpad
|
||||
return checkDpad(b);
|
||||
else if (index == legacyButtonValues(XBOX))
|
||||
return xboxButtonState;
|
||||
return xboxOneSData.btn.val & (1UL << pgm_read_byte(&XBOX_ONE_S_BUTTONS[index]));
|
||||
}
|
||||
|
||||
bool XBOXONESParser::getButtonClick(ButtonEnum b) {
|
||||
if(b == L2) {
|
||||
const int8_t index = getButtonIndex(b); if (index < 0) return 0;
|
||||
if(index == legacyButtonValues(L2)) {
|
||||
if(L2Clicked) {
|
||||
L2Clicked = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} else if(b == R2) {
|
||||
} else if(index == legacyButtonValues(R2)) {
|
||||
if(R2Clicked) {
|
||||
R2Clicked = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} else if (b == XBOX) {
|
||||
} else if (index == legacyButtonValues(XBOX)) {
|
||||
bool click = xboxbuttonClickState;
|
||||
xboxbuttonClickState = 0; // Clear "click" event
|
||||
return click;
|
||||
}
|
||||
const int8_t index = getButtonIndex(b); if (index < 0) return 0;
|
||||
uint32_t mask = 1UL << pgm_read_byte(&XBOX_ONE_S_BUTTONS[index]);
|
||||
bool click = buttonClickState.val & mask;
|
||||
buttonClickState.val &= ~mask; // Clear "click" event
|
||||
|
|
14
XBOXRECV.cpp
14
XBOXRECV.cpp
|
@ -408,29 +408,29 @@ void XBOXRECV::printReport(uint8_t controller __attribute__((unused)), uint8_t n
|
|||
}
|
||||
|
||||
uint8_t XBOXRECV::getButtonPress(ButtonEnum b, uint8_t controller) {
|
||||
if(b == L2) // These are analog buttons
|
||||
return (uint8_t)(ButtonState[controller] >> 8);
|
||||
else if(b == R2)
|
||||
return (uint8_t)ButtonState[controller];
|
||||
const int8_t index = getXboxButtonIndex(b); if (index < 0) return 0;
|
||||
if(index == legacyButtonValues(L2)) // These are analog buttons
|
||||
return (uint8_t)(ButtonState[controller] >> 8);
|
||||
else if(index == legacyButtonValues(R2))
|
||||
return (uint8_t)ButtonState[controller];
|
||||
return (bool)(ButtonState[controller] & ((uint32_t)pgm_read_word(&XBOX_BUTTONS[index]) << 16));
|
||||
}
|
||||
|
||||
bool XBOXRECV::getButtonClick(ButtonEnum b, uint8_t controller) {
|
||||
if(b == L2) {
|
||||
const int8_t index = getXboxButtonIndex(b); if (index < 0) return 0;
|
||||
if(index == legacyButtonValues(L2)) {
|
||||
if(L2Clicked[controller]) {
|
||||
L2Clicked[controller] = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} else if(b == R2) {
|
||||
} else if(index == legacyButtonValues(R2)) {
|
||||
if(R2Clicked[controller]) {
|
||||
R2Clicked[controller] = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
const int8_t index = getXboxButtonIndex(b); if (index < 0) return 0;
|
||||
uint16_t button = pgm_read_word(&XBOX_BUTTONS[index]);
|
||||
bool click = (ButtonClickState[controller] & button);
|
||||
ButtonClickState[controller] &= ~button; // clear "click" event
|
||||
|
|
14
XBOXUSB.cpp
14
XBOXUSB.cpp
|
@ -281,29 +281,29 @@ void XBOXUSB::printReport() { //Uncomment "#define PRINTREPORT" to print the rep
|
|||
}
|
||||
|
||||
uint8_t XBOXUSB::getButtonPress(ButtonEnum b) {
|
||||
if(b == L2) // These are analog buttons
|
||||
return (uint8_t)(ButtonState >> 8);
|
||||
else if(b == R2)
|
||||
return (uint8_t)ButtonState;
|
||||
const int8_t index = getXboxButtonIndex(b); if (index < 0) return 0;
|
||||
if(index == legacyButtonValues(L2)) // These are analog buttons
|
||||
return (uint8_t)(ButtonState >> 8);
|
||||
else if(index == legacyButtonValues(R2))
|
||||
return (uint8_t)ButtonState;
|
||||
return (bool)(ButtonState & ((uint32_t)pgm_read_word(&XBOX_BUTTONS[index]) << 16));
|
||||
}
|
||||
|
||||
bool XBOXUSB::getButtonClick(ButtonEnum b) {
|
||||
if(b == L2) {
|
||||
const int8_t index = getXboxButtonIndex(b); if (index < 0) return 0;
|
||||
if(index == legacyButtonValues(L2)) {
|
||||
if(L2Clicked) {
|
||||
L2Clicked = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} else if(b == R2) {
|
||||
} else if(index == legacyButtonValues(R2)) {
|
||||
if(R2Clicked) {
|
||||
R2Clicked = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
const int8_t index = getXboxButtonIndex(b); if (index < 0) return 0;
|
||||
uint16_t button = pgm_read_word(&XBOX_BUTTONS[index]);
|
||||
bool click = (ButtonClickState & button);
|
||||
ButtonClickState &= ~button; // clear "click" event
|
||||
|
|
Loading…
Reference in a new issue