mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Change button index 'get' functions to constexpr
This commit is contained in:
parent
2fe5574e71
commit
89575639b1
10 changed files with 19 additions and 33 deletions
|
@ -138,10 +138,8 @@ 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 int8_t getPS3ButtonIndex(ButtonEnum b) {
|
inline constexpr int8_t getPS3ButtonIndex(ButtonEnum b) {
|
||||||
const int8_t index = legacyButtonValues(b);
|
return (uint8_t) legacyButtonValues(b) >= (sizeof(PS3_BUTTONS) / sizeof(PS3_BUTTONS[0])) ? -1 : legacyButtonValues(b);
|
||||||
if ((uint8_t) index >= (sizeof(PS3_BUTTONS) / sizeof(PS3_BUTTONS[0]))) return -1;
|
|
||||||
return index;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -32,10 +32,8 @@ 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
|
||||||
|
|
||||||
int8_t PS4Parser::getButtonIndex(ButtonEnum b) {
|
inline constexpr int8_t PS4Parser::getButtonIndex(ButtonEnum b) {
|
||||||
const int8_t index = legacyButtonValues(b);
|
return (uint8_t) legacyButtonValues(b) >= (sizeof(PS4_BUTTONS) / sizeof(PS4_BUTTONS[0])) ? -1 : 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 int8_t getButtonIndex(ButtonEnum b);
|
static inline constexpr 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,10 +36,8 @@ 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
|
||||||
|
|
||||||
int8_t PS5Parser::getButtonIndex(ButtonEnum b) {
|
inline constexpr int8_t PS5Parser::getButtonIndex(ButtonEnum b) {
|
||||||
const int8_t index = legacyButtonValues(b);
|
return (uint8_t) legacyButtonValues(b) >= (sizeof(PS5_BUTTONS) / sizeof(PS5_BUTTONS[0])) ? -1 : 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 int8_t getButtonIndex(ButtonEnum b);
|
static inline constexpr 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,16 +1094,12 @@ void WII::readWiiBalanceBoardCalibration() {
|
||||||
/* WII Commands */
|
/* WII Commands */
|
||||||
/************************************************************/
|
/************************************************************/
|
||||||
|
|
||||||
int8_t WII::getButtonIndex(ButtonEnum b) {
|
inline constexpr int8_t WII::getButtonIndex(ButtonEnum b) {
|
||||||
const int8_t index = legacyButtonValues(b);
|
return (uint8_t)legacyButtonValues(b) >= (sizeof(WII_BUTTONS) / sizeof(WII_BUTTONS[0])) ? -1 : legacyButtonValues(b);
|
||||||
if ((uint8_t) index >= (sizeof(WII_BUTTONS) / sizeof(WII_BUTTONS[0]))) return -1;
|
|
||||||
return index;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t WII::getButtonIndexPro(ButtonEnum b) {
|
inline constexpr int8_t WII::getButtonIndexPro(ButtonEnum b) {
|
||||||
const int8_t index = legacyButtonValues(b);
|
return (uint8_t)legacyButtonValues(b) >= (sizeof(WII_PROCONTROLLER_BUTTONS) / sizeof(WII_PROCONTROLLER_BUTTONS[0])) ? -1 : 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 int8_t getButtonIndex(ButtonEnum b);
|
static inline constexpr int8_t getButtonIndex(ButtonEnum b);
|
||||||
static int8_t getButtonIndexPro(ButtonEnum b);
|
static inline constexpr int8_t getButtonIndexPro(ButtonEnum b);
|
||||||
|
|
||||||
void L2CAP_task(); // L2CAP state machine
|
void L2CAP_task(); // L2CAP state machine
|
||||||
|
|
||||||
|
|
|
@ -54,10 +54,8 @@ enum DPADEnum {
|
||||||
DPAD_LEFT_UP = 0x8,
|
DPAD_LEFT_UP = 0x8,
|
||||||
};
|
};
|
||||||
|
|
||||||
int8_t XBOXONESParser::getButtonIndex(ButtonEnum b) {
|
inline constexpr int8_t XBOXONESParser::getButtonIndex(ButtonEnum b) {
|
||||||
const int8_t index = legacyButtonValues(b);
|
return (uint8_t) legacyButtonValues(b) >= (sizeof(XBOX_ONE_S_BUTTONS) / sizeof(XBOX_ONE_S_BUTTONS[0])) ? -1 : 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 int8_t getButtonIndex(ButtonEnum b);
|
static inline constexpr 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,10 +62,8 @@ const uint16_t XBOX_BUTTONS[] PROGMEM = {
|
||||||
0x0008, // SYNC
|
0x0008, // SYNC
|
||||||
};
|
};
|
||||||
|
|
||||||
inline int8_t getXboxButtonIndex(ButtonEnum b) {
|
inline constexpr int8_t getXboxButtonIndex(ButtonEnum b) {
|
||||||
const int8_t index = legacyButtonValues(b);
|
return (uint8_t) legacyButtonValues(b) >= (sizeof(XBOX_BUTTONS) / sizeof(XBOX_BUTTONS[0])) ? -1 : 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