diff --git a/PS3Enums.h b/PS3Enums.h index 77c7c536..2c0116e4 100644 --- a/PS3Enums.h +++ b/PS3Enums.h @@ -139,8 +139,8 @@ enum StatusEnum { }; inline int8_t getPS3ButtonIndex(ButtonEnum b) { - const uint8_t index = legacyButtonValues(b); - if (index >= sizeof(PS3_BUTTONS) / sizeof(PS3_BUTTONS[0])) return -1; + const int8_t index = legacyButtonValues(b); + if ((uint8_t) index >= (sizeof(PS3_BUTTONS) / sizeof(PS3_BUTTONS[0]))) return -1; return index; } diff --git a/PS4Parser.cpp b/PS4Parser.cpp index ed619a51..a8353ce5 100644 --- a/PS4Parser.cpp +++ b/PS4Parser.cpp @@ -33,8 +33,8 @@ enum DPADEnum { //#define PRINTREPORT // Uncomment to print the report send by the PS4 Controller int8_t PS4Parser::getButtonIndex(ButtonEnum b) { - const uint8_t index = legacyButtonValues(b); - if (index >= sizeof(PS4_BUTTONS) / sizeof(PS4_BUTTONS[0])) return -1; + const int8_t index = legacyButtonValues(b); + if ((uint8_t) index >= (sizeof(PS4_BUTTONS) / sizeof(PS4_BUTTONS[0]))) return -1; return index; } diff --git a/PS5Parser.cpp b/PS5Parser.cpp index 061ab8fe..b0c6bc0b 100644 --- a/PS5Parser.cpp +++ b/PS5Parser.cpp @@ -37,8 +37,8 @@ enum DPADEnum { //#define PRINTREPORT // Uncomment to print the report send by the PS5 Controller int8_t PS5Parser::getButtonIndex(ButtonEnum b) { - const uint8_t index = legacyButtonValues(b); - if (index >= sizeof(PS5_BUTTONS) / sizeof(PS5_BUTTONS[0])) return -1; + const int8_t index = legacyButtonValues(b); + if ((uint8_t) index >= (sizeof(PS5_BUTTONS) / sizeof(PS5_BUTTONS[0]))) return -1; return index; } diff --git a/PSBuzz.cpp b/PSBuzz.cpp index 0ec452d6..c542c499 100644 --- a/PSBuzz.cpp +++ b/PSBuzz.cpp @@ -50,7 +50,7 @@ uint8_t PSBuzz::OnInitSuccessful() { }; int8_t PSBuzz::getButtonIndex(ButtonEnum b) { - const uint8_t index = legacyButtonValues(b); + const int8_t index = legacyButtonValues(b); if (index > 4) return -1; // 5 buttons, 0-4 inclusive return index; } diff --git a/Wii.cpp b/Wii.cpp index 48ff3739..6073f250 100644 --- a/Wii.cpp +++ b/Wii.cpp @@ -1095,14 +1095,14 @@ void WII::readWiiBalanceBoardCalibration() { /************************************************************/ int8_t WII::getButtonIndex(ButtonEnum b) { - const uint8_t index = legacyButtonValues(b); - if (index >= sizeof(WII_BUTTONS) / sizeof(WII_BUTTONS[0])) return -1; + const int8_t index = legacyButtonValues(b); + if ((uint8_t) index >= (sizeof(WII_BUTTONS) / sizeof(WII_BUTTONS[0]))) return -1; return index; } int8_t WII::getButtonIndexPro(ButtonEnum b) { - const uint8_t index = legacyButtonValues(b); - if (index >= sizeof(WII_PROCONTROLLER_BUTTONS) / sizeof(WII_PROCONTROLLER_BUTTONS[0])) return -1; + const int8_t index = legacyButtonValues(b); + if ((uint8_t) index >= (sizeof(WII_PROCONTROLLER_BUTTONS) / sizeof(WII_PROCONTROLLER_BUTTONS[0]))) return -1; return index; } diff --git a/XBOXONESParser.cpp b/XBOXONESParser.cpp index fce6d776..4c9c23e4 100644 --- a/XBOXONESParser.cpp +++ b/XBOXONESParser.cpp @@ -55,8 +55,8 @@ enum DPADEnum { }; int8_t XBOXONESParser::getButtonIndex(ButtonEnum b) { - const uint8_t index = legacyButtonValues(b); - if (index >= sizeof(XBOX_ONE_S_BUTTONS) / sizeof(XBOX_ONE_S_BUTTONS[0])) return -1; + const int8_t index = legacyButtonValues(b); + if ((uint8_t) index >= (sizeof(XBOX_ONE_S_BUTTONS) / sizeof(XBOX_ONE_S_BUTTONS[0]))) return -1; return index; } diff --git a/controllerEnums.h b/controllerEnums.h index 22c1043a..f2df387d 100644 --- a/controllerEnums.h +++ b/controllerEnums.h @@ -183,87 +183,83 @@ enum ButtonEnum { /**@}*/ }; -inline uint8_t legacyButtonValues(ButtonEnum key) { - uint8_t out; - +inline int8_t legacyButtonValues(ButtonEnum key) { switch (key) { case UP: case RED: - out = 0; break; + return 0; case RIGHT: case YELLOW: - out = 1; break; + return 1; case DOWN: case GREEN: - out = 2; break; + return 2; case LEFT: case ORANGE: - out = 3; break; + return 3; case SELECT: case SHARE: case BACK: case VIEW: case BLUE: case CREATE: - out = 4; break; + return 4; case PLUS: case START: case OPTIONS: case MENU: - out = 5; break; + return 5; case TWO: case L3: - out = 6; break; + return 6; case ONE: case R3: - out = 7; break; + return 7; case MINUS: case L2: case BLACK: - out = 8; break; + return 8; case HOME: case R2: case WHITE: - out = 9; break; + return 9; case Z: case L1: - out = 10; break; + return 10; case C: case R1: - out = 11; break; + return 11; case B: case TRIANGLE: - out = 12; break; + return 12; case A: case CIRCLE: - out = 13; break; + return 13; case CROSS: case X: - out = 14; break; + return 14; case SQUARE: case Y: - out = 15; break; + return 15; case L: case PS: case XBOX: - out = 16; break; + return 16; case R: case MOVE: case TOUCHPAD: - out = 17; break; case SYNC: - out = 17; break; + return 17; case ZL: case T: case MICROPHONE: - out = 18; break; + return 18; case ZR: - out = 19; break; + return 19; default: - out = 0; break; + return -1; } - - return out; + return -1; } /** Joysticks on the PS3 and Xbox controllers. */ diff --git a/xboxEnums.h b/xboxEnums.h index 309a3a8d..037be594 100644 --- a/xboxEnums.h +++ b/xboxEnums.h @@ -63,8 +63,8 @@ const uint16_t XBOX_BUTTONS[] PROGMEM = { }; inline int8_t getXboxButtonIndex(ButtonEnum b) { - const uint8_t index = legacyButtonValues(b); - if (index >= sizeof(XBOX_BUTTONS) / sizeof(XBOX_BUTTONS[0])) return -1; + const int8_t index = legacyButtonValues(b); + if ((uint8_t) index >= (sizeof(XBOX_BUTTONS) / sizeof(XBOX_BUTTONS[0]))) return -1; return index; }