diff --git a/btdrv-mitm/source/controllers/dualshock4.cpp b/btdrv-mitm/source/controllers/dualshock4.cpp index 6916e92..f042f12 100644 --- a/btdrv-mitm/source/controllers/dualshock4.cpp +++ b/btdrv-mitm/source/controllers/dualshock4.cpp @@ -49,11 +49,9 @@ namespace ams::controller { case 0x01: this->handleInputReport0x01(ds4Report, switchReport); break; - case 0x11: this->handleInputReport0x11(ds4Report, switchReport); break; - default: BTDRV_LOG_FMT("DS4: RECEIVED REPORT [0x%02x]", ds4Report->id); break; @@ -76,37 +74,7 @@ namespace ams::controller { static_cast(stickScaleFactor * (UINT8_MAX - src->input0x01.right_stick.y)) & 0xfff ); - dst->input0x30.buttons.dpad_down = (src->input0x01.buttons.dpad == Dualshock4DPad_S) || - (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; + this->mapButtons(&src->input0x01.buttons, dst); } void Dualshock4Controller::handleInputReport0x11(const Dualshock4ReportData *src, SwitchReportData *dst) { @@ -121,37 +89,41 @@ namespace ams::controller { static_cast(stickScaleFactor * (UINT8_MAX - src->input0x11.right_stick.y)) & 0xfff ); - dst->input0x30.buttons.dpad_down = (src->input0x11.buttons.dpad == Dualshock4DPad_S) || - (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); + this->mapButtons(&src->input0x11.buttons, dst); + } - dst->input0x30.buttons.A = src->input0x11.buttons.circle; - dst->input0x30.buttons.B = src->input0x11.buttons.cross; - dst->input0x30.buttons.X = src->input0x11.buttons.triangle; - dst->input0x30.buttons.Y = src->input0x11.buttons.square; + void Dualshock4Controller::mapButtons(const Dualshock4ButtonData *buttons, SwitchReportData *dst) { + dst->input0x30.buttons.dpad_down = (buttons->dpad == Dualshock4DPad_S) || + (buttons->dpad == Dualshock4DPad_SE) || + (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.ZR = src->input0x11.buttons.R2; - dst->input0x30.buttons.L = src->input0x11.buttons.L1; - dst->input0x30.buttons.ZL = src->input0x11.buttons.L2; + dst->input0x30.buttons.A = buttons->circle; + dst->input0x30.buttons.B = buttons->cross; + dst->input0x30.buttons.X = buttons->triangle; + dst->input0x30.buttons.Y = buttons->square; - dst->input0x30.buttons.minus = src->input0x11.buttons.share; - dst->input0x30.buttons.plus = src->input0x11.buttons.options; + dst->input0x30.buttons.R = buttons->R1; + 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.rstick_press = src->input0x11.buttons.R3; + dst->input0x30.buttons.minus = buttons->share; + dst->input0x30.buttons.plus = buttons->options; - dst->input0x30.buttons.capture = src->input0x11.buttons.tpad; - dst->input0x30.buttons.home = src->input0x11.buttons.ps; + dst->input0x30.buttons.lstick_press = buttons->L3; + dst->input0x30.buttons.rstick_press = buttons->R3; + + dst->input0x30.buttons.capture = buttons->tpad; + dst->input0x30.buttons.home = buttons->ps; } Result Dualshock4Controller::updateControllerState(void) { diff --git a/btdrv-mitm/source/controllers/dualshock4.hpp b/btdrv-mitm/source/controllers/dualshock4.hpp index ac8b51e..3e74d54 100644 --- a/btdrv-mitm/source/controllers/dualshock4.hpp +++ b/btdrv-mitm/source/controllers/dualshock4.hpp @@ -125,6 +125,7 @@ namespace ams::controller { void handleInputReport0x01(const Dualshock4ReportData *src, SwitchReportData *dst); void handleInputReport0x11(const Dualshock4ReportData *src, SwitchReportData *dst); + void mapButtons(const Dualshock4ButtonData *buttons, SwitchReportData *dst); Result updateControllerState(void); Dualshock4LedColour m_ledColour;