From 825e675e601a2f3110fccdbafd1a5e0abe471f63 Mon Sep 17 00:00:00 2001 From: ndeadly <24677491+ndeadly@users.noreply.github.com> Date: Sun, 11 Oct 2020 12:17:30 +0200 Subject: [PATCH] bluetooth-mitm: map controls for steelseries nimbus --- Atmosphere-libs | 2 +- .../controllers/steelseries_controller.cpp | 38 +++++++++++++++++-- .../controllers/steelseries_controller.hpp | 36 ++++++++++++++++-- libnx | 2 +- 4 files changed, 69 insertions(+), 9 deletions(-) diff --git a/Atmosphere-libs b/Atmosphere-libs index 2c3ccef..48dbf48 160000 --- a/Atmosphere-libs +++ b/Atmosphere-libs @@ -1 +1 @@ -Subproject commit 2c3ccef17e9b267a5d9d232f1aba689f2c591b95 +Subproject commit 48dbf4808f4f2042de8c45e9ec471a8f60d5d621 diff --git a/bluetooth-mitm/source/controllers/steelseries_controller.cpp b/bluetooth-mitm/source/controllers/steelseries_controller.cpp index 953c7d7..bc4201f 100644 --- a/bluetooth-mitm/source/controllers/steelseries_controller.cpp +++ b/bluetooth-mitm/source/controllers/steelseries_controller.cpp @@ -33,6 +33,8 @@ namespace ams::controller { this->HandleInputReport0x01(steelseries_report); break; default: + // Todo: handle this properly + this->HandleMfiInputReport(steelseries_report); break; } } @@ -65,11 +67,39 @@ namespace ams::controller { m_buttons.X = src->input0x01.buttons.Y; m_buttons.Y = src->input0x01.buttons.X; - m_buttons.R = src->input0x01.buttons.R; - m_buttons.L = src->input0x01.buttons.L; + m_buttons.R = src->input0x01.buttons.R; + m_buttons.L = src->input0x01.buttons.L; - m_buttons.minus = src->input0x01.buttons.select; - m_buttons.plus = src->input0x01.buttons.start; + m_buttons.minus = src->input0x01.buttons.select; + m_buttons.plus = src->input0x01.buttons.start; + } + + void SteelseriesController::HandleMfiInputReport(const SteelseriesReportData *src) { + m_left_stick = this->PackStickData( + static_cast(stick_scale_factor * -static_cast(~src->input_mfi.left_stick.x + 1) + 0x7ff) & 0xfff, + static_cast(stick_scale_factor * (-static_cast(~src->input_mfi.left_stick.y + 1)) + 0x7ff) & 0xfff + ); + m_right_stick = this->PackStickData( + static_cast(stick_scale_factor * -static_cast(~src->input_mfi.right_stick.x + 1) + 0x7ff) & 0xfff, + static_cast(stick_scale_factor * (-static_cast(~src->input_mfi.right_stick.y + 1)) + 0x7ff) & 0xfff + ); + + m_buttons.dpad_up = src->input_mfi.buttons.dpad_up > 0; + m_buttons.dpad_right = src->input_mfi.buttons.dpad_right > 0; + m_buttons.dpad_down = src->input_mfi.buttons.dpad_down > 0; + m_buttons.dpad_left = src->input_mfi.buttons.dpad_left > 0; + + m_buttons.A = src->input_mfi.buttons.A > 0; + m_buttons.B = src->input_mfi.buttons.B > 0; + m_buttons.X = src->input_mfi.buttons.X > 0; + m_buttons.Y = src->input_mfi.buttons.Y > 0; + + m_buttons.R = src->input_mfi.buttons.R1 > 0; + m_buttons.L = src->input_mfi.buttons.L1 > 0; + m_buttons.ZR = src->input_mfi.buttons.R2 > 0; + m_buttons.ZL = src->input_mfi.buttons.L2 > 0; + + m_buttons.home = src->input_mfi.buttons.menu; } } diff --git a/bluetooth-mitm/source/controllers/steelseries_controller.hpp b/bluetooth-mitm/source/controllers/steelseries_controller.hpp index 93a8980..e603a9b 100644 --- a/bluetooth-mitm/source/controllers/steelseries_controller.hpp +++ b/bluetooth-mitm/source/controllers/steelseries_controller.hpp @@ -51,6 +51,30 @@ namespace ams::controller { uint8_t select : 1; uint8_t : 0; } __attribute__ ((__packed__)); + + struct SteelseriesMfiButtonData { + uint8_t dpad_up; + uint8_t dpad_right; + uint8_t dpad_down; + uint8_t dpad_left; + uint8_t A; + uint8_t B; + uint8_t X; + uint8_t Y; + uint8_t L1; + uint8_t R1; + uint8_t L2; + uint8_t R2; + + uint8_t menu : 1; + uint8_t : 0; + } __attribute__ ((__packed__)); + + struct SteelseriesMfiInputReport { + SteelseriesMfiButtonData buttons; + SteelseriesStickData left_stick; + SteelseriesStickData right_stick; + } __attribute__((packed)); struct SteelseriesInputReport0x01 { uint8_t dpad; @@ -60,9 +84,15 @@ namespace ams::controller { } __attribute__((packed)); struct SteelseriesReportData { - uint8_t id; union { - SteelseriesInputReport0x01 input0x01; + struct { + uint8_t id; + union { + SteelseriesInputReport0x01 input0x01; + }; + }; + + SteelseriesMfiInputReport input_mfi; }; } __attribute__((packed)); @@ -81,7 +111,7 @@ namespace ams::controller { private: void HandleInputReport0x01(const SteelseriesReportData *src); - + void HandleMfiInputReport(const SteelseriesReportData *src); }; } diff --git a/libnx b/libnx index 9d939bc..ffde37a 160000 --- a/libnx +++ b/libnx @@ -1 +1 @@ -Subproject commit 9d939bcd7e821cef3cb8ef2529b409252b883041 +Subproject commit ffde37ae3d0be30269f5aa5d0c1986e6d7dcdb10