btdrv-mitm: factor duplicate dualshock4 button mapping code into its own method

This commit is contained in:
ndeadly 2020-08-07 02:12:57 +02:00
parent 51e182883f
commit e7fddf2a2b
2 changed files with 32 additions and 59 deletions

View file

@ -49,11 +49,9 @@ namespace ams::controller {
case 0x01: case 0x01:
this->handleInputReport0x01(ds4Report, switchReport); this->handleInputReport0x01(ds4Report, switchReport);
break; break;
case 0x11: case 0x11:
this->handleInputReport0x11(ds4Report, switchReport); this->handleInputReport0x11(ds4Report, switchReport);
break; break;
default: default:
BTDRV_LOG_FMT("DS4: RECEIVED REPORT [0x%02x]", ds4Report->id); BTDRV_LOG_FMT("DS4: RECEIVED REPORT [0x%02x]", ds4Report->id);
break; break;
@ -76,37 +74,7 @@ namespace ams::controller {
static_cast<uint16_t>(stickScaleFactor * (UINT8_MAX - src->input0x01.right_stick.y)) & 0xfff static_cast<uint16_t>(stickScaleFactor * (UINT8_MAX - src->input0x01.right_stick.y)) & 0xfff
); );
dst->input0x30.buttons.dpad_down = (src->input0x01.buttons.dpad == Dualshock4DPad_S) || this->mapButtons(&src->input0x01.buttons, dst);
(src->input0x01.buttons.dpad == Dualshock4DPad_SE) ||
(src->input0x01.buttons.dpad == Dualshock4DPad_SW);
dst->input0x30.buttons.dpad_up = (src->input0x01.buttons.dpad == Dualshock4DPad_N) ||
(src->input0x01.buttons.dpad == Dualshock4DPad_NE) ||
(src->input0x01.buttons.dpad == Dualshock4DPad_NW);
dst->input0x30.buttons.dpad_right = (src->input0x01.buttons.dpad == Dualshock4DPad_E) ||
(src->input0x01.buttons.dpad == Dualshock4DPad_NE) ||
(src->input0x01.buttons.dpad == Dualshock4DPad_SE);
dst->input0x30.buttons.dpad_left = (src->input0x01.buttons.dpad == Dualshock4DPad_W) ||
(src->input0x01.buttons.dpad == Dualshock4DPad_NW) ||
(src->input0x01.buttons.dpad == Dualshock4DPad_SW);
dst->input0x30.buttons.A = src->input0x01.buttons.circle;
dst->input0x30.buttons.B = src->input0x01.buttons.cross;
dst->input0x30.buttons.X = src->input0x01.buttons.triangle;
dst->input0x30.buttons.Y = src->input0x01.buttons.square;
dst->input0x30.buttons.R = src->input0x01.buttons.R1;
dst->input0x30.buttons.ZR = src->input0x01.buttons.R2;
dst->input0x30.buttons.L = src->input0x01.buttons.L1;
dst->input0x30.buttons.ZL = src->input0x01.buttons.L2;
dst->input0x30.buttons.minus = src->input0x01.buttons.share;
dst->input0x30.buttons.plus = src->input0x01.buttons.options;
dst->input0x30.buttons.lstick_press = src->input0x01.buttons.L3;
dst->input0x30.buttons.rstick_press = src->input0x01.buttons.R3;
dst->input0x30.buttons.capture = src->input0x01.buttons.tpad;
dst->input0x30.buttons.home = src->input0x01.buttons.ps;
} }
void Dualshock4Controller::handleInputReport0x11(const Dualshock4ReportData *src, SwitchReportData *dst) { void Dualshock4Controller::handleInputReport0x11(const Dualshock4ReportData *src, SwitchReportData *dst) {
@ -121,37 +89,41 @@ namespace ams::controller {
static_cast<uint16_t>(stickScaleFactor * (UINT8_MAX - src->input0x11.right_stick.y)) & 0xfff static_cast<uint16_t>(stickScaleFactor * (UINT8_MAX - src->input0x11.right_stick.y)) & 0xfff
); );
dst->input0x30.buttons.dpad_down = (src->input0x11.buttons.dpad == Dualshock4DPad_S) || this->mapButtons(&src->input0x11.buttons, dst);
(src->input0x11.buttons.dpad == Dualshock4DPad_SE) || }
(src->input0x11.buttons.dpad == Dualshock4DPad_SW);
dst->input0x30.buttons.dpad_up = (src->input0x11.buttons.dpad == Dualshock4DPad_N) ||
(src->input0x11.buttons.dpad == Dualshock4DPad_NE) ||
(src->input0x11.buttons.dpad == Dualshock4DPad_NW);
dst->input0x30.buttons.dpad_right = (src->input0x11.buttons.dpad == Dualshock4DPad_E) ||
(src->input0x11.buttons.dpad == Dualshock4DPad_NE) ||
(src->input0x11.buttons.dpad == Dualshock4DPad_SE);
dst->input0x30.buttons.dpad_left = (src->input0x11.buttons.dpad == Dualshock4DPad_W) ||
(src->input0x11.buttons.dpad == Dualshock4DPad_NW) ||
(src->input0x11.buttons.dpad == Dualshock4DPad_SW);
dst->input0x30.buttons.A = src->input0x11.buttons.circle; void Dualshock4Controller::mapButtons(const Dualshock4ButtonData *buttons, SwitchReportData *dst) {
dst->input0x30.buttons.B = src->input0x11.buttons.cross; dst->input0x30.buttons.dpad_down = (buttons->dpad == Dualshock4DPad_S) ||
dst->input0x30.buttons.X = src->input0x11.buttons.triangle; (buttons->dpad == Dualshock4DPad_SE) ||
dst->input0x30.buttons.Y = src->input0x11.buttons.square; (buttons->dpad == Dualshock4DPad_SW);
dst->input0x30.buttons.dpad_up = (buttons->dpad == Dualshock4DPad_N) ||
(buttons->dpad == Dualshock4DPad_NE) ||
(buttons->dpad == Dualshock4DPad_NW);
dst->input0x30.buttons.dpad_right = (buttons->dpad == Dualshock4DPad_E) ||
(buttons->dpad == Dualshock4DPad_NE) ||
(buttons->dpad == Dualshock4DPad_SE);
dst->input0x30.buttons.dpad_left = (buttons->dpad == Dualshock4DPad_W) ||
(buttons->dpad == Dualshock4DPad_NW) ||
(buttons->dpad == Dualshock4DPad_SW);
dst->input0x30.buttons.R = src->input0x11.buttons.R1; dst->input0x30.buttons.A = buttons->circle;
dst->input0x30.buttons.ZR = src->input0x11.buttons.R2; dst->input0x30.buttons.B = buttons->cross;
dst->input0x30.buttons.L = src->input0x11.buttons.L1; dst->input0x30.buttons.X = buttons->triangle;
dst->input0x30.buttons.ZL = src->input0x11.buttons.L2; dst->input0x30.buttons.Y = buttons->square;
dst->input0x30.buttons.minus = src->input0x11.buttons.share; dst->input0x30.buttons.R = buttons->R1;
dst->input0x30.buttons.plus = src->input0x11.buttons.options; dst->input0x30.buttons.ZR = buttons->R2;
dst->input0x30.buttons.L = buttons->L1;
dst->input0x30.buttons.ZL = buttons->L2;
dst->input0x30.buttons.lstick_press = src->input0x11.buttons.L3; dst->input0x30.buttons.minus = buttons->share;
dst->input0x30.buttons.rstick_press = src->input0x11.buttons.R3; dst->input0x30.buttons.plus = buttons->options;
dst->input0x30.buttons.capture = src->input0x11.buttons.tpad; dst->input0x30.buttons.lstick_press = buttons->L3;
dst->input0x30.buttons.home = src->input0x11.buttons.ps; dst->input0x30.buttons.rstick_press = buttons->R3;
dst->input0x30.buttons.capture = buttons->tpad;
dst->input0x30.buttons.home = buttons->ps;
} }
Result Dualshock4Controller::updateControllerState(void) { Result Dualshock4Controller::updateControllerState(void) {

View file

@ -125,6 +125,7 @@ namespace ams::controller {
void handleInputReport0x01(const Dualshock4ReportData *src, SwitchReportData *dst); void handleInputReport0x01(const Dualshock4ReportData *src, SwitchReportData *dst);
void handleInputReport0x11(const Dualshock4ReportData *src, SwitchReportData *dst); void handleInputReport0x11(const Dualshock4ReportData *src, SwitchReportData *dst);
void mapButtons(const Dualshock4ButtonData *buttons, SwitchReportData *dst);
Result updateControllerState(void); Result updateControllerState(void);
Dualshock4LedColour m_ledColour; Dualshock4LedColour m_ledColour;