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:
David Madison 2021-03-27 07:22:57 -04:00
parent 89575639b1
commit 6e0748d097
10 changed files with 33 additions and 19 deletions

View file

@ -138,8 +138,10 @@ enum StatusEnum {
Bluetooth = (40 << 8) | 0x16, // Operating by Bluetooth and rumble is turned off
};
inline constexpr int8_t getPS3ButtonIndex(ButtonEnum b) {
return (uint8_t) legacyButtonValues(b) >= (sizeof(PS3_BUTTONS) / sizeof(PS3_BUTTONS[0])) ? -1 : legacyButtonValues(b);
inline int8_t getPS3ButtonIndex(ButtonEnum b) {
const int8_t index = legacyButtonValues(b);
if ((uint8_t) index >= (sizeof(PS3_BUTTONS) / sizeof(PS3_BUTTONS[0]))) return -1;
return index;
}
#endif

View file

@ -32,8 +32,10 @@ enum DPADEnum {
// To enable serial debugging see "settings.h"
//#define PRINTREPORT // Uncomment to print the report send by the PS4 Controller
inline constexpr int8_t PS4Parser::getButtonIndex(ButtonEnum b) {
return (uint8_t) legacyButtonValues(b) >= (sizeof(PS4_BUTTONS) / sizeof(PS4_BUTTONS[0])) ? -1 : legacyButtonValues(b);
int8_t PS4Parser::getButtonIndex(ButtonEnum 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) {

View file

@ -362,7 +362,7 @@ protected:
virtual void sendOutputReport(PS4Output *output) = 0;
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
PS4Data ps4Data;

View file

@ -36,8 +36,10 @@ enum DPADEnum {
// To enable serial debugging see "settings.h"
//#define PRINTREPORT // Uncomment to print the report send by the PS5 Controller
inline constexpr int8_t PS5Parser::getButtonIndex(ButtonEnum b) {
return (uint8_t) legacyButtonValues(b) >= (sizeof(PS5_BUTTONS) / sizeof(PS5_BUTTONS[0])) ? -1 : legacyButtonValues(b);
int8_t PS5Parser::getButtonIndex(ButtonEnum 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) {

View file

@ -403,7 +403,7 @@ protected:
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
PS5Data ps5Data;

12
Wii.cpp
View file

@ -1094,12 +1094,16 @@ void WII::readWiiBalanceBoardCalibration() {
/* WII Commands */
/************************************************************/
inline constexpr int8_t WII::getButtonIndex(ButtonEnum b) {
return (uint8_t)legacyButtonValues(b) >= (sizeof(WII_BUTTONS) / sizeof(WII_BUTTONS[0])) ? -1 : legacyButtonValues(b);
int8_t WII::getButtonIndex(ButtonEnum 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) {
return (uint8_t)legacyButtonValues(b) >= (sizeof(WII_PROCONTROLLER_BUTTONS) / sizeof(WII_PROCONTROLLER_BUTTONS[0])) ? -1 : legacyButtonValues(b);
int8_t WII::getButtonIndexPro(ButtonEnum 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

4
Wii.h
View file

@ -431,8 +431,8 @@ protected:
/**@}*/
private:
static inline constexpr int8_t getButtonIndex(ButtonEnum b);
static inline constexpr int8_t getButtonIndexPro(ButtonEnum b);
static int8_t getButtonIndex(ButtonEnum b);
static int8_t getButtonIndexPro(ButtonEnum b);
void L2CAP_task(); // L2CAP state machine

View file

@ -54,8 +54,10 @@ enum DPADEnum {
DPAD_LEFT_UP = 0x8,
};
inline constexpr 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);
int8_t XBOXONESParser::getButtonIndex(ButtonEnum 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) {

View file

@ -111,7 +111,7 @@ protected:
virtual void sendOutputReport(uint8_t *data, uint8_t nbytes) = 0;
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

View file

@ -62,8 +62,10 @@ const uint16_t XBOX_BUTTONS[] PROGMEM = {
0x0008, // SYNC
};
inline constexpr int8_t getXboxButtonIndex(ButtonEnum b) {
return (uint8_t) legacyButtonValues(b) >= (sizeof(XBOX_BUTTONS) / sizeof(XBOX_BUTTONS[0])) ? -1 : legacyButtonValues(b);
inline int8_t getXboxButtonIndex(ButtonEnum b) {
const int8_t index = legacyButtonValues(b);
if ((uint8_t) index >= (sizeof(XBOX_BUTTONS) / sizeof(XBOX_BUTTONS[0]))) return -1;
return index;
}
#endif