mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Modify XBOXOLD to catch previous button cases
Getting a bit ahead of myself and forgetting that the enum checks no longer work to maintain the previous aliases.
This commit is contained in:
parent
2120adf283
commit
33975cfca9
2 changed files with 65 additions and 59 deletions
122
XBOXOLD.cpp
122
XBOXOLD.cpp
|
@ -20,6 +20,30 @@
|
||||||
//#define EXTRADEBUG // Uncomment to get even more debugging data
|
//#define EXTRADEBUG // Uncomment to get even more debugging data
|
||||||
//#define PRINTREPORT // Uncomment to print the report send by the Xbox controller
|
//#define PRINTREPORT // Uncomment to print the report send by the Xbox controller
|
||||||
|
|
||||||
|
/** Buttons on the controllers */
|
||||||
|
const uint8_t XBOXOLD_BUTTONS[] PROGMEM = {
|
||||||
|
0x01, // UP
|
||||||
|
0x08, // RIGHT
|
||||||
|
0x02, // DOWN
|
||||||
|
0x04, // LEFT
|
||||||
|
|
||||||
|
0x20, // BACK
|
||||||
|
0x10, // START
|
||||||
|
0x40, // L3
|
||||||
|
0x80, // R3
|
||||||
|
|
||||||
|
// A, B, X, Y, BLACK, WHITE, L1, and R1 are analog buttons
|
||||||
|
4, // BLACK
|
||||||
|
5, // WHTIE
|
||||||
|
6, // L1
|
||||||
|
7, // R1
|
||||||
|
|
||||||
|
1, // B
|
||||||
|
0, // A
|
||||||
|
2, // X
|
||||||
|
3, // Y
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
XBOXOLD::XBOXOLD(USB *p) :
|
XBOXOLD::XBOXOLD(USB *p) :
|
||||||
pUsb(p), // pointer to USB class instance - mandatory
|
pUsb(p), // pointer to USB class instance - mandatory
|
||||||
|
@ -270,74 +294,55 @@ void XBOXOLD::printReport(uint16_t length __attribute__((unused))) { //Uncomment
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t XBOXOLD::getAnalogIndex(ButtonEnum b) {
|
int8_t XBOXOLD::getAnalogIndex(ButtonEnum b) {
|
||||||
// A, B, X, Y, BLACK, WHITE, L, and R are analog buttons
|
// A, B, X, Y, BLACK, WHITE, L1, and R1 are analog buttons
|
||||||
uint8_t out;
|
const int8_t index = ButtonIndex(b);
|
||||||
|
|
||||||
switch (b) {
|
switch (index) {
|
||||||
case A:
|
case ButtonIndex(A):
|
||||||
out = 0; break;
|
case ButtonIndex(B):
|
||||||
case B:
|
case ButtonIndex(X):
|
||||||
out = 1; break;
|
case ButtonIndex(Y):
|
||||||
case X:
|
case ButtonIndex(BLACK):
|
||||||
out = 2; break;
|
case ButtonIndex(WHITE):
|
||||||
case Y:
|
case ButtonIndex(L1):
|
||||||
out = 3; break;
|
case ButtonIndex(R1):
|
||||||
case WHITE:
|
return index;
|
||||||
out = 5; break;
|
default: break;
|
||||||
case BLACK:
|
|
||||||
out = 4; break;
|
|
||||||
case L:
|
|
||||||
case L1:
|
|
||||||
case L2:
|
|
||||||
out = 6; break;
|
|
||||||
case R:
|
|
||||||
case R1:
|
|
||||||
case R2:
|
|
||||||
out = 7; break;
|
|
||||||
default:
|
|
||||||
out = -1; break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t XBOXOLD::getDigitalOffset(ButtonEnum b) {
|
int8_t XBOXOLD::getDigitalIndex(ButtonEnum b) {
|
||||||
// UP, DOWN, LEFT, RIGHT, START, BACK, L3, and R3 are digital buttons
|
// UP, DOWN, LEFT, RIGHT, START, BACK, L3, and R3 are digital buttons
|
||||||
// (these are offets for the bitshift)
|
const int8_t index = ButtonIndex(b);
|
||||||
uint8_t out;
|
|
||||||
|
|
||||||
switch (b) {
|
switch (index) {
|
||||||
case UP:
|
case ButtonIndex(UP):
|
||||||
out = 0; break;
|
case ButtonIndex(DOWN):
|
||||||
case DOWN:
|
case ButtonIndex(LEFT):
|
||||||
out = 1; break;
|
case ButtonIndex(RIGHT):
|
||||||
case LEFT:
|
case ButtonIndex(START):
|
||||||
out = 2; break;
|
case ButtonIndex(BACK):
|
||||||
case RIGHT:
|
case ButtonIndex(L3):
|
||||||
out = 3; break;
|
case ButtonIndex(R3):
|
||||||
case START:
|
return index;
|
||||||
out = 4; break;
|
default: break;
|
||||||
case BACK:
|
|
||||||
out = 5; break;
|
|
||||||
case L3:
|
|
||||||
out = 6; break;
|
|
||||||
case R3:
|
|
||||||
out = 7; break;
|
|
||||||
default:
|
|
||||||
out = -1; break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t XBOXOLD::getButtonPress(ButtonEnum b) {
|
uint8_t XBOXOLD::getButtonPress(ButtonEnum b) {
|
||||||
const int8_t analogIndex = getAnalogIndex(b);
|
const int8_t analogIndex = getAnalogIndex(b);
|
||||||
if (analogIndex >= 0) {
|
if (analogIndex >= 0) {
|
||||||
return buttonValues[analogIndex];
|
const uint8_t buttonIndex = pgm_read_byte(&XBOXOLD_BUTTONS[analogIndex]);
|
||||||
|
return buttonValues[buttonIndex];
|
||||||
}
|
}
|
||||||
const int8_t digitalOffset = getDigitalOffset(b);
|
const int8_t digitalIndex = getDigitalIndex(b);
|
||||||
if (digitalOffset >= 0) {
|
if (digitalIndex >= 0) {
|
||||||
return (ButtonState & (1 << digitalOffset));
|
const uint8_t buttonMask = pgm_read_byte(&XBOXOLD_BUTTONS[digitalIndex]);
|
||||||
|
return (ButtonState & buttonMask);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -345,15 +350,16 @@ uint8_t XBOXOLD::getButtonPress(ButtonEnum b) {
|
||||||
bool XBOXOLD::getButtonClick(ButtonEnum b) {
|
bool XBOXOLD::getButtonClick(ButtonEnum b) {
|
||||||
const int8_t analogIndex = getAnalogIndex(b);
|
const int8_t analogIndex = getAnalogIndex(b);
|
||||||
if (analogIndex >= 0) {
|
if (analogIndex >= 0) {
|
||||||
if (buttonClicked[analogIndex]) {
|
const uint8_t buttonIndex = pgm_read_byte(&XBOXOLD_BUTTONS[analogIndex]);
|
||||||
buttonClicked[analogIndex] = false;
|
if (buttonClicked[buttonIndex]) {
|
||||||
|
buttonClicked[buttonIndex] = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const int8_t digitalOffset = getDigitalOffset(b);
|
const int8_t digitalIndex = getDigitalIndex(b);
|
||||||
if (digitalOffset >= 0) {
|
if (digitalIndex >= 0) {
|
||||||
const uint8_t mask = (1 << digitalOffset);
|
const uint8_t mask = pgm_read_byte(&XBOXOLD_BUTTONS[digitalIndex]);
|
||||||
const bool click = (ButtonClickState & mask);
|
const bool click = (ButtonClickState & mask);
|
||||||
ButtonClickState &= ~mask;
|
ButtonClickState &= ~mask;
|
||||||
return click;
|
return click;
|
||||||
|
|
|
@ -154,7 +154,7 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int8_t getAnalogIndex(ButtonEnum b);
|
static int8_t getAnalogIndex(ButtonEnum b);
|
||||||
static int8_t getDigitalOffset(ButtonEnum b);
|
static int8_t getDigitalIndex(ButtonEnum b);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the controller is successfully initialized.
|
* Called when the controller is successfully initialized.
|
||||||
|
|
Loading…
Reference in a new issue