mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Revert "Change button index 'get' functions to constexpr"
On second thought, reverting this so that in the case that the function is *not* evaluated at compile-time, the button values function is not called twice.
This commit is contained in:
parent
89575639b1
commit
6e0748d097
10 changed files with 33 additions and 19 deletions
|
@ -138,8 +138,10 @@ enum StatusEnum {
|
||||||
Bluetooth = (40 << 8) | 0x16, // Operating by Bluetooth and rumble is turned off
|
Bluetooth = (40 << 8) | 0x16, // Operating by Bluetooth and rumble is turned off
|
||||||
};
|
};
|
||||||
|
|
||||||
inline constexpr int8_t getPS3ButtonIndex(ButtonEnum b) {
|
inline int8_t getPS3ButtonIndex(ButtonEnum b) {
|
||||||
return (uint8_t) legacyButtonValues(b) >= (sizeof(PS3_BUTTONS) / sizeof(PS3_BUTTONS[0])) ? -1 : legacyButtonValues(b);
|
const int8_t index = legacyButtonValues(b);
|
||||||
|
if ((uint8_t) index >= (sizeof(PS3_BUTTONS) / sizeof(PS3_BUTTONS[0]))) return -1;
|
||||||
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -32,8 +32,10 @@ enum DPADEnum {
|
||||||
// To enable serial debugging see "settings.h"
|
// To enable serial debugging see "settings.h"
|
||||||
//#define PRINTREPORT // Uncomment to print the report send by the PS4 Controller
|
//#define PRINTREPORT // Uncomment to print the report send by the PS4 Controller
|
||||||
|
|
||||||
inline constexpr int8_t PS4Parser::getButtonIndex(ButtonEnum b) {
|
int8_t PS4Parser::getButtonIndex(ButtonEnum b) {
|
||||||
return (uint8_t) legacyButtonValues(b) >= (sizeof(PS4_BUTTONS) / sizeof(PS4_BUTTONS[0])) ? -1 : legacyButtonValues(b);
|
const int8_t index = legacyButtonValues(b);
|
||||||
|
if ((uint8_t) index >= (sizeof(PS4_BUTTONS) / sizeof(PS4_BUTTONS[0]))) return -1;
|
||||||
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PS4Parser::checkDpad(ButtonEnum b) {
|
bool PS4Parser::checkDpad(ButtonEnum b) {
|
||||||
|
|
|
@ -362,7 +362,7 @@ protected:
|
||||||
virtual void sendOutputReport(PS4Output *output) = 0;
|
virtual void sendOutputReport(PS4Output *output) = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static inline constexpr int8_t getButtonIndex(ButtonEnum b);
|
static int8_t getButtonIndex(ButtonEnum b);
|
||||||
bool checkDpad(ButtonEnum b); // Used to check PS4 DPAD buttons
|
bool checkDpad(ButtonEnum b); // Used to check PS4 DPAD buttons
|
||||||
|
|
||||||
PS4Data ps4Data;
|
PS4Data ps4Data;
|
||||||
|
|
|
@ -36,8 +36,10 @@ enum DPADEnum {
|
||||||
// To enable serial debugging see "settings.h"
|
// To enable serial debugging see "settings.h"
|
||||||
//#define PRINTREPORT // Uncomment to print the report send by the PS5 Controller
|
//#define PRINTREPORT // Uncomment to print the report send by the PS5 Controller
|
||||||
|
|
||||||
inline constexpr int8_t PS5Parser::getButtonIndex(ButtonEnum b) {
|
int8_t PS5Parser::getButtonIndex(ButtonEnum b) {
|
||||||
return (uint8_t) legacyButtonValues(b) >= (sizeof(PS5_BUTTONS) / sizeof(PS5_BUTTONS[0])) ? -1 : legacyButtonValues(b);
|
const int8_t index = legacyButtonValues(b);
|
||||||
|
if ((uint8_t) index >= (sizeof(PS5_BUTTONS) / sizeof(PS5_BUTTONS[0]))) return -1;
|
||||||
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PS5Parser::checkDpad(ButtonEnum b) {
|
bool PS5Parser::checkDpad(ButtonEnum b) {
|
||||||
|
|
|
@ -403,7 +403,7 @@ protected:
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static inline constexpr int8_t getButtonIndex(ButtonEnum b);
|
static int8_t getButtonIndex(ButtonEnum b);
|
||||||
bool checkDpad(ButtonEnum b); // Used to check PS5 DPAD buttons
|
bool checkDpad(ButtonEnum b); // Used to check PS5 DPAD buttons
|
||||||
|
|
||||||
PS5Data ps5Data;
|
PS5Data ps5Data;
|
||||||
|
|
12
Wii.cpp
12
Wii.cpp
|
@ -1094,12 +1094,16 @@ void WII::readWiiBalanceBoardCalibration() {
|
||||||
/* WII Commands */
|
/* WII Commands */
|
||||||
/************************************************************/
|
/************************************************************/
|
||||||
|
|
||||||
inline constexpr int8_t WII::getButtonIndex(ButtonEnum b) {
|
int8_t WII::getButtonIndex(ButtonEnum b) {
|
||||||
return (uint8_t)legacyButtonValues(b) >= (sizeof(WII_BUTTONS) / sizeof(WII_BUTTONS[0])) ? -1 : legacyButtonValues(b);
|
const int8_t index = legacyButtonValues(b);
|
||||||
|
if ((uint8_t) index >= (sizeof(WII_BUTTONS) / sizeof(WII_BUTTONS[0]))) return -1;
|
||||||
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline constexpr int8_t WII::getButtonIndexPro(ButtonEnum b) {
|
int8_t WII::getButtonIndexPro(ButtonEnum b) {
|
||||||
return (uint8_t)legacyButtonValues(b) >= (sizeof(WII_PROCONTROLLER_BUTTONS) / sizeof(WII_PROCONTROLLER_BUTTONS[0])) ? -1 : legacyButtonValues(b);
|
const int8_t index = legacyButtonValues(b);
|
||||||
|
if ((uint8_t) index >= (sizeof(WII_PROCONTROLLER_BUTTONS) / sizeof(WII_PROCONTROLLER_BUTTONS[0]))) return -1;
|
||||||
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WII::getButtonPress(ButtonEnum b) { // Return true when a button is pressed
|
bool WII::getButtonPress(ButtonEnum b) { // Return true when a button is pressed
|
||||||
|
|
4
Wii.h
4
Wii.h
|
@ -431,8 +431,8 @@ protected:
|
||||||
/**@}*/
|
/**@}*/
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static inline constexpr int8_t getButtonIndex(ButtonEnum b);
|
static int8_t getButtonIndex(ButtonEnum b);
|
||||||
static inline constexpr int8_t getButtonIndexPro(ButtonEnum b);
|
static int8_t getButtonIndexPro(ButtonEnum b);
|
||||||
|
|
||||||
void L2CAP_task(); // L2CAP state machine
|
void L2CAP_task(); // L2CAP state machine
|
||||||
|
|
||||||
|
|
|
@ -54,8 +54,10 @@ enum DPADEnum {
|
||||||
DPAD_LEFT_UP = 0x8,
|
DPAD_LEFT_UP = 0x8,
|
||||||
};
|
};
|
||||||
|
|
||||||
inline constexpr int8_t XBOXONESParser::getButtonIndex(ButtonEnum b) {
|
int8_t XBOXONESParser::getButtonIndex(ButtonEnum b) {
|
||||||
return (uint8_t) legacyButtonValues(b) >= (sizeof(XBOX_ONE_S_BUTTONS) / sizeof(XBOX_ONE_S_BUTTONS[0])) ? -1 : legacyButtonValues(b);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool XBOXONESParser::checkDpad(ButtonEnum b) {
|
bool XBOXONESParser::checkDpad(ButtonEnum b) {
|
||||||
|
|
|
@ -111,7 +111,7 @@ protected:
|
||||||
virtual void sendOutputReport(uint8_t *data, uint8_t nbytes) = 0;
|
virtual void sendOutputReport(uint8_t *data, uint8_t nbytes) = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static inline constexpr int8_t getButtonIndex(ButtonEnum b);
|
static int8_t getButtonIndex(ButtonEnum b);
|
||||||
|
|
||||||
bool checkDpad(ButtonEnum b); // Used to check Xbox One S DPAD buttons
|
bool checkDpad(ButtonEnum b); // Used to check Xbox One S DPAD buttons
|
||||||
|
|
||||||
|
|
|
@ -62,8 +62,10 @@ const uint16_t XBOX_BUTTONS[] PROGMEM = {
|
||||||
0x0008, // SYNC
|
0x0008, // SYNC
|
||||||
};
|
};
|
||||||
|
|
||||||
inline constexpr int8_t getXboxButtonIndex(ButtonEnum b) {
|
inline int8_t getXboxButtonIndex(ButtonEnum b) {
|
||||||
return (uint8_t) legacyButtonValues(b) >= (sizeof(XBOX_BUTTONS) / sizeof(XBOX_BUTTONS[0])) ? -1 : legacyButtonValues(b);
|
const int8_t index = legacyButtonValues(b);
|
||||||
|
if ((uint8_t) index >= (sizeof(XBOX_BUTTONS) / sizeof(XBOX_BUTTONS[0]))) return -1;
|
||||||
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue