From ad46ee78e1dd3a24d932a0d1baa3f0430c84fbf0 Mon Sep 17 00:00:00 2001 From: ndeadly <24677491+ndeadly@users.noreply.github.com> Date: Sat, 26 Dec 2020 19:58:45 +0100 Subject: [PATCH] bluetooth-mitm: refactor mocute 050 handler for yet another input report variation --- .../source/controllers/mocute_controller.cpp | 87 +++++++------------ .../source/controllers/mocute_controller.hpp | 6 +- 2 files changed, 32 insertions(+), 61 deletions(-) diff --git a/bluetooth-mitm/source/controllers/mocute_controller.cpp b/bluetooth-mitm/source/controllers/mocute_controller.cpp index ffbfe33..3d32b0d 100644 --- a/bluetooth-mitm/source/controllers/mocute_controller.cpp +++ b/bluetooth-mitm/source/controllers/mocute_controller.cpp @@ -30,17 +30,16 @@ namespace ams::controller { switch(mocute_report->id) { case 0x01: - this->HandleInputReport0x01(mocute_report); - break; case 0x04: - this->HandleInputReport0x04(mocute_report); + case 0x06: + this->HandleInputReport(mocute_report); break; default: break; } } - void MocuteController::HandleInputReport0x01(const MocuteReportData *src) { + void MocuteController::HandleInputReport(const MocuteReportData *src) { m_left_stick = this->PackStickData( static_cast(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & 0xfff @@ -50,18 +49,34 @@ namespace ams::controller { static_cast(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & 0xfff ); - m_buttons.dpad_down = (src->input0x01.buttons.dpad == MocuteDPad2_S) || - (src->input0x01.buttons.dpad == MocuteDPad2_SE) || - (src->input0x01.buttons.dpad == MocuteDPad2_SW); - m_buttons.dpad_up = (src->input0x01.buttons.dpad == MocuteDPad2_N) || - (src->input0x01.buttons.dpad == MocuteDPad2_NE) || - (src->input0x01.buttons.dpad == MocuteDPad2_NW); - m_buttons.dpad_right = (src->input0x01.buttons.dpad == MocuteDPad2_E) || - (src->input0x01.buttons.dpad == MocuteDPad2_NE) || - (src->input0x01.buttons.dpad == MocuteDPad2_SE); - m_buttons.dpad_left = (src->input0x01.buttons.dpad == MocuteDPad2_W) || - (src->input0x01.buttons.dpad == MocuteDPad2_NW) || - (src->input0x01.buttons.dpad == MocuteDPad2_SW); + if (src->id == 0x01) { + m_buttons.dpad_down = (src->input0x01.buttons.dpad == MocuteDPad2_S) || + (src->input0x01.buttons.dpad == MocuteDPad2_SE) || + (src->input0x01.buttons.dpad == MocuteDPad2_SW); + m_buttons.dpad_up = (src->input0x01.buttons.dpad == MocuteDPad2_N) || + (src->input0x01.buttons.dpad == MocuteDPad2_NE) || + (src->input0x01.buttons.dpad == MocuteDPad2_NW); + m_buttons.dpad_right = (src->input0x01.buttons.dpad == MocuteDPad2_E) || + (src->input0x01.buttons.dpad == MocuteDPad2_NE) || + (src->input0x01.buttons.dpad == MocuteDPad2_SE); + m_buttons.dpad_left = (src->input0x01.buttons.dpad == MocuteDPad2_W) || + (src->input0x01.buttons.dpad == MocuteDPad2_NW) || + (src->input0x01.buttons.dpad == MocuteDPad2_SW); + } + else { + m_buttons.dpad_down = (src->input0x01.buttons.dpad == MocuteDPad_S) || + (src->input0x01.buttons.dpad == MocuteDPad_SE) || + (src->input0x01.buttons.dpad == MocuteDPad_SW); + m_buttons.dpad_up = (src->input0x01.buttons.dpad == MocuteDPad_N) || + (src->input0x01.buttons.dpad == MocuteDPad_NE) || + (src->input0x01.buttons.dpad == MocuteDPad_NW); + m_buttons.dpad_right = (src->input0x01.buttons.dpad == MocuteDPad_E) || + (src->input0x01.buttons.dpad == MocuteDPad_NE) || + (src->input0x01.buttons.dpad == MocuteDPad_SE); + m_buttons.dpad_left = (src->input0x01.buttons.dpad == MocuteDPad_W) || + (src->input0x01.buttons.dpad == MocuteDPad_NW) || + (src->input0x01.buttons.dpad == MocuteDPad_SW); + } m_buttons.A = src->input0x01.buttons.B; m_buttons.B = src->input0x01.buttons.A; @@ -80,44 +95,4 @@ namespace ams::controller { m_buttons.rstick_press = src->input0x01.buttons.R3; } - void MocuteController::HandleInputReport0x04(const MocuteReportData *src) { - m_left_stick = this->PackStickData( - static_cast(stick_scale_factor * src->input0x04.left_stick.x) & 0xfff, - static_cast(stick_scale_factor * (UINT8_MAX - src->input0x04.left_stick.y)) & 0xfff - ); - m_right_stick = this->PackStickData( - static_cast(stick_scale_factor * src->input0x04.right_stick.x) & 0xfff, - static_cast(stick_scale_factor * (UINT8_MAX - src->input0x04.right_stick.y)) & 0xfff - ); - - m_buttons.dpad_down = (src->input0x04.buttons.dpad == MocuteDPad_S) || - (src->input0x04.buttons.dpad == MocuteDPad_SE) || - (src->input0x04.buttons.dpad == MocuteDPad_SW); - m_buttons.dpad_up = (src->input0x04.buttons.dpad == MocuteDPad_N) || - (src->input0x04.buttons.dpad == MocuteDPad_NE) || - (src->input0x04.buttons.dpad == MocuteDPad_NW); - m_buttons.dpad_right = (src->input0x04.buttons.dpad == MocuteDPad_E) || - (src->input0x04.buttons.dpad == MocuteDPad_NE) || - (src->input0x04.buttons.dpad == MocuteDPad_SE); - m_buttons.dpad_left = (src->input0x04.buttons.dpad == MocuteDPad_W) || - (src->input0x04.buttons.dpad == MocuteDPad_NW) || - (src->input0x04.buttons.dpad == MocuteDPad_SW); - - m_buttons.A = src->input0x04.buttons.B; - m_buttons.B = src->input0x04.buttons.A; - m_buttons.X = src->input0x04.buttons.Y; - m_buttons.Y = src->input0x04.buttons.X; - - m_buttons.R = src->input0x04.buttons.R1; - m_buttons.ZR = src->input0x04.buttons.R2; - m_buttons.L = src->input0x04.buttons.L1; - m_buttons.ZL = src->input0x04.buttons.L2; - - m_buttons.minus = src->input0x04.buttons.select; - m_buttons.plus = src->input0x04.buttons.start; - - m_buttons.lstick_press = src->input0x04.buttons.L3; - m_buttons.rstick_press = src->input0x04.buttons.R3; - } - } diff --git a/bluetooth-mitm/source/controllers/mocute_controller.hpp b/bluetooth-mitm/source/controllers/mocute_controller.hpp index abf33a7..b19f331 100644 --- a/bluetooth-mitm/source/controllers/mocute_controller.hpp +++ b/bluetooth-mitm/source/controllers/mocute_controller.hpp @@ -73,13 +73,10 @@ namespace ams::controller { uint8_t right_trigger; } __attribute__ ((__packed__)); - typedef MocuteInputReport0x01 MocuteInputReport0x04; - struct MocuteReportData { uint8_t id; union { MocuteInputReport0x01 input0x01; - MocuteInputReport0x04 input0x04; }; } __attribute__((packed)); @@ -96,8 +93,7 @@ namespace ams::controller { void UpdateControllerState(const bluetooth::HidReport *report); private: - void HandleInputReport0x01(const MocuteReportData *src); - void HandleInputReport0x04(const MocuteReportData *src); + void HandleInputReport(const MocuteReportData *src); };