Another fix for multiple controllers

This commit is contained in:
Kristian Sloth Lauszus 2013-01-04 00:19:07 +01:00
parent 47d1a6b8b6
commit 1798f9b338
2 changed files with 9 additions and 9 deletions

View file

@ -346,15 +346,15 @@ void XBOXRECV::readReport(uint8_t controller) {
if(ButtonState[controller] != OldButtonState[controller]) { if(ButtonState[controller] != OldButtonState[controller]) {
ButtonClickState[controller] = (ButtonState[controller] >> 16) & ((~OldButtonState[controller]) >> 16); // Update click state variable, but don't include the two trigger buttons L2 and R2 ButtonClickState[controller] = (ButtonState[controller] >> 16) & ((~OldButtonState[controller]) >> 16); // Update click state variable, but don't include the two trigger buttons L2 and R2
if(((uint8_t)OldButtonState[controller]) == 0 && ((uint8_t)ButtonState[controller]) != 0) // The L2 and R2 buttons are special as they are analog buttons if(((uint8_t)OldButtonState[controller]) == 0 && ((uint8_t)ButtonState[controller]) != 0) // The L2 and R2 buttons are special as they are analog buttons
R2Clicked = true; R2Clicked[controller] = true;
if((uint8_t)(OldButtonState[controller] >> 8) == 0 && (uint8_t)(ButtonState[controller] >> 8) != 0) if((uint8_t)(OldButtonState[controller] >> 8) == 0 && (uint8_t)(ButtonState[controller] >> 8) != 0)
L2Clicked = true; L2Clicked[controller] = true;
OldButtonState[controller] = ButtonState[controller]; OldButtonState[controller] = ButtonState[controller];
} }
} }
void XBOXRECV::printReport(uint8_t controller, uint8_t nBytes) { //Uncomment "#define PRINTREPORT" to print the report send by the Xbox 360 Controller void XBOXRECV::printReport(uint8_t controller, uint8_t nBytes) { //Uncomment "#define PRINTREPORT" to print the report send by the Xbox 360 Controller
#if defined(DEBUG) || defined(PRINTREPORT) #if defined(PRINTREPORT)
if (readBuf == NULL) if (readBuf == NULL)
return; return;
Notify(PSTR("Controller ")); Notify(PSTR("Controller "));
@ -376,15 +376,15 @@ uint8_t XBOXRECV::getButtonPress(uint8_t controller, Button b) {
} }
bool XBOXRECV::getButtonClick(uint8_t controller, Button b) { bool XBOXRECV::getButtonClick(uint8_t controller, Button b) {
if(b == L2) { if(b == L2) {
if(L2Clicked) { if(L2Clicked[controller]) {
L2Clicked = false; L2Clicked[controller] = false;
return true; return true;
} }
return false; return false;
} }
else if(b== R2) { else if(b== R2) {
if(R2Clicked) { if(R2Clicked[controller]) {
R2Clicked = false; R2Clicked[controller] = false;
return true; return true;
} }
return false; return false;

View file

@ -148,8 +148,8 @@ private:
uint16_t ButtonClickState[4]; uint16_t ButtonClickState[4];
int16_t hatValue[4][4]; int16_t hatValue[4][4];
bool L2Clicked; // These buttons are analog, so we use we use these bools to check if they where clicked or not bool L2Clicked[4]; // These buttons are analog, so we use we use these bools to check if they where clicked or not
bool R2Clicked; bool R2Clicked[4];
uint8_t readBuf[EP_MAXPKTSIZE]; // General purpose buffer for input data uint8_t readBuf[EP_MAXPKTSIZE]; // General purpose buffer for input data
uint8_t writeBuf[EP_MAXPKTSIZE]; // General purpose buffer for output data uint8_t writeBuf[EP_MAXPKTSIZE]; // General purpose buffer for output data