From 34698dbd534ab3f86143fc0efa7b279ce8dce8e9 Mon Sep 17 00:00:00 2001 From: ndeadly <24677491+ndeadly@users.noreply.github.com> Date: Sun, 20 Jun 2021 22:39:28 +0200 Subject: [PATCH] mc.mitm: add methods for fetching and modifying packed switch analog stick data --- mc_mitm/source/controllers/8bitdo_controller.cpp | 4 ++-- .../source/controllers/atgames_controller.cpp | 4 ++-- .../source/controllers/dualsense_controller.cpp | 8 ++++---- .../source/controllers/dualshock4_controller.cpp | 8 ++++---- .../controllers/emulated_switch_controller.cpp | 4 ++-- .../controllers/emulated_switch_controller.hpp | 16 ++++------------ .../source/controllers/gamesir_controller.cpp | 4 ++-- .../source/controllers/gamestick_controller.cpp | 4 ++-- mc_mitm/source/controllers/gembox_controller.cpp | 4 ++-- mc_mitm/source/controllers/ipega_controller.cpp | 4 ++-- .../source/controllers/lanshen_controller.cpp | 4 ++-- .../source/controllers/mad_catz_controller.cpp | 4 ++-- mc_mitm/source/controllers/mocute_controller.cpp | 4 ++-- .../controllers/nvidia_shield_controller.cpp | 4 ++-- mc_mitm/source/controllers/ouya_controller.cpp | 4 ++-- mc_mitm/source/controllers/powera_controller.cpp | 4 ++-- mc_mitm/source/controllers/razer_controller.cpp | 4 ++-- .../controllers/steelseries_controller.cpp | 12 ++++++------ mc_mitm/source/controllers/switch_controller.hpp | 15 +++++---------- mc_mitm/source/controllers/wii_controller.cpp | 10 +++++----- .../source/controllers/xbox_one_controller.cpp | 4 ++-- mc_mitm/source/controllers/xiaomi_controller.cpp | 4 ++-- 22 files changed, 60 insertions(+), 73 deletions(-) diff --git a/mc_mitm/source/controllers/8bitdo_controller.cpp b/mc_mitm/source/controllers/8bitdo_controller.cpp index b0c1bb0..cc10e21 100644 --- a/mc_mitm/source/controllers/8bitdo_controller.cpp +++ b/mc_mitm/source/controllers/8bitdo_controller.cpp @@ -55,11 +55,11 @@ namespace ams::controller { (src->input0x01_v1.dpad == EightBitDoDPadV1_SW); } else { - m_left_stick = this->PackStickData( + m_left_stick.SetData( static_cast(stick_scale_factor * src->input0x01_v2.left_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT16_MAX - src->input0x01_v2.left_stick.y)) & 0xfff ); - m_right_stick = this->PackStickData( + m_right_stick.SetData( static_cast(stick_scale_factor * src->input0x01_v2.right_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT16_MAX - src->input0x01_v2.right_stick.y)) & 0xfff ); diff --git a/mc_mitm/source/controllers/atgames_controller.cpp b/mc_mitm/source/controllers/atgames_controller.cpp index 2a57ae9..59f49d0 100644 --- a/mc_mitm/source/controllers/atgames_controller.cpp +++ b/mc_mitm/source/controllers/atgames_controller.cpp @@ -37,11 +37,11 @@ namespace ams::controller { } void AtGamesController::HandleInputReport0x01(const AtGamesReportData *src) { - m_left_stick = this->PackStickData( + m_left_stick.SetData( STICK_ZERO + 0x7ff * (src->input0x01.nudge_left - src->input0x01.nudge_right), STICK_ZERO ); - m_right_stick = this->PackStickData( + m_right_stick.SetData( STICK_ZERO, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.x)) & 0xfff ); diff --git a/mc_mitm/source/controllers/dualsense_controller.cpp b/mc_mitm/source/controllers/dualsense_controller.cpp index 80ed471..b0819fe 100644 --- a/mc_mitm/source/controllers/dualsense_controller.cpp +++ b/mc_mitm/source/controllers/dualsense_controller.cpp @@ -101,11 +101,11 @@ namespace ams::controller { } void DualsenseController::HandleInputReport0x01(const DualsenseReportData *src) { - m_left_stick = this->PackStickData( + m_left_stick.SetData( static_cast(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & 0xfff ); - m_right_stick = this->PackStickData( + m_right_stick.SetData( static_cast(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & 0xfff ); @@ -127,11 +127,11 @@ namespace ams::controller { m_battery = static_cast(8 * (battery_level + 1) / 10) & 0x0e; - m_left_stick = this->PackStickData( + m_left_stick.SetData( static_cast(stick_scale_factor * src->input0x31.left_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x31.left_stick.y)) & 0xfff ); - m_right_stick = this->PackStickData( + m_right_stick.SetData( static_cast(stick_scale_factor * src->input0x31.right_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x31.right_stick.y)) & 0xfff ); diff --git a/mc_mitm/source/controllers/dualshock4_controller.cpp b/mc_mitm/source/controllers/dualshock4_controller.cpp index 1576e93..a16e71c 100644 --- a/mc_mitm/source/controllers/dualshock4_controller.cpp +++ b/mc_mitm/source/controllers/dualshock4_controller.cpp @@ -90,11 +90,11 @@ namespace ams::controller { } void Dualshock4Controller::HandleInputReport0x01(const Dualshock4ReportData *src) { - m_left_stick = this->PackStickData( + m_left_stick.SetData( static_cast(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & 0xfff ); - m_right_stick = this->PackStickData( + m_right_stick.SetData( static_cast(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & 0xfff ); @@ -116,11 +116,11 @@ namespace ams::controller { m_battery = static_cast(8 * (battery_level + 1) / 10) & 0x0e; - m_left_stick = this->PackStickData( + m_left_stick.SetData( static_cast(stick_scale_factor * src->input0x11.left_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x11.left_stick.y)) & 0xfff ); - m_right_stick = this->PackStickData( + m_right_stick.SetData( static_cast(stick_scale_factor * src->input0x11.right_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x11.right_stick.y)) & 0xfff ); diff --git a/mc_mitm/source/controllers/emulated_switch_controller.cpp b/mc_mitm/source/controllers/emulated_switch_controller.cpp index 7c309fb..9c5283d 100644 --- a/mc_mitm/source/controllers/emulated_switch_controller.cpp +++ b/mc_mitm/source/controllers/emulated_switch_controller.cpp @@ -98,8 +98,8 @@ namespace ams::controller { void EmulatedSwitchController::ClearControllerState(void) { std::memset(&m_buttons, 0, sizeof(m_buttons)); - m_left_stick = this->PackStickData(STICK_ZERO, STICK_ZERO); - m_right_stick = this->PackStickData(STICK_ZERO, STICK_ZERO); + m_left_stick.SetData(STICK_ZERO, STICK_ZERO); + m_right_stick.SetData(STICK_ZERO, STICK_ZERO); std::memset(&m_motion_data, 0, sizeof(m_motion_data)); } diff --git a/mc_mitm/source/controllers/emulated_switch_controller.hpp b/mc_mitm/source/controllers/emulated_switch_controller.hpp index f99c32e..0f7f901 100644 --- a/mc_mitm/source/controllers/emulated_switch_controller.hpp +++ b/mc_mitm/source/controllers/emulated_switch_controller.hpp @@ -39,14 +39,6 @@ namespace ams::controller { virtual Result CancelVibration(void) { return ams::ResultSuccess(); }; virtual Result SetPlayerLed(uint8_t led_mask) { return ams::ResultSuccess(); }; - constexpr SwitchStickData PackStickData(uint16_t x, uint16_t y) { - return { - static_cast(x & 0xff), - static_cast((x >> 8) | ((y & 0xff) << 4)), - static_cast((y >> 4) & 0xff) - }; - } - Result HandleSubCmdReport(const bluetooth::HidReport *report); Result HandleRumbleReport(const bluetooth::HidReport *report); @@ -66,12 +58,12 @@ namespace ams::controller { Result FakeSubCmdResponse(const SwitchSubcommandResponse *response); - bool m_charging; + bool m_charging; uint8_t m_battery; SwitchButtonData m_buttons; - SwitchStickData m_left_stick; - SwitchStickData m_right_stick; - Switch6AxisData m_motion_data[3]; + SwitchAnalogStick m_left_stick; + SwitchAnalogStick m_right_stick; + Switch6AxisData m_motion_data[3]; ProControllerColours m_colours; bool m_enable_rumble; diff --git a/mc_mitm/source/controllers/gamesir_controller.cpp b/mc_mitm/source/controllers/gamesir_controller.cpp index 7b4e9a5..a3edcd1 100644 --- a/mc_mitm/source/controllers/gamesir_controller.cpp +++ b/mc_mitm/source/controllers/gamesir_controller.cpp @@ -44,11 +44,11 @@ namespace ams::controller { } void GamesirController::HandleInputReport0xc4(const GamesirReportData *src) { - m_left_stick = this->PackStickData( + m_left_stick.SetData( static_cast(stick_scale_factor * src->input0xc4.left_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0xc4.left_stick.y)) & 0xfff ); - m_right_stick = this->PackStickData( + m_right_stick.SetData( static_cast(stick_scale_factor * src->input0xc4.right_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0xc4.right_stick.y)) & 0xfff ); diff --git a/mc_mitm/source/controllers/gamestick_controller.cpp b/mc_mitm/source/controllers/gamestick_controller.cpp index ab335cd..1063bda 100644 --- a/mc_mitm/source/controllers/gamestick_controller.cpp +++ b/mc_mitm/source/controllers/gamestick_controller.cpp @@ -46,11 +46,11 @@ namespace ams::controller { } void GamestickController::HandleInputReport0x03(const GamestickReportData *src) { - m_left_stick = this->PackStickData( + m_left_stick.SetData( static_cast(stick_scale_factor * src->input0x03.left_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x03.left_stick.y)) & 0xfff ); - m_right_stick = this->PackStickData( + m_right_stick.SetData( static_cast(stick_scale_factor * src->input0x03.right_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x03.right_stick.y)) & 0xfff ); diff --git a/mc_mitm/source/controllers/gembox_controller.cpp b/mc_mitm/source/controllers/gembox_controller.cpp index 000da46..93705ea 100644 --- a/mc_mitm/source/controllers/gembox_controller.cpp +++ b/mc_mitm/source/controllers/gembox_controller.cpp @@ -45,11 +45,11 @@ namespace ams::controller { } void GemboxController::HandleInputReport0x07(const GemboxReportData *src) { - m_left_stick = this->PackStickData( + m_left_stick.SetData( static_cast(stick_scale_factor * -static_cast(~src->input0x07.left_stick.x + 1) + 0x7ff) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX + static_cast(~src->input0x07.left_stick.y + 1)) + 0x7ff) & 0xfff ); - m_right_stick = this->PackStickData( + m_right_stick.SetData( static_cast(stick_scale_factor * -static_cast(~src->input0x07.right_stick.x + 1) + 0x7ff) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX + static_cast(~src->input0x07.right_stick.y + 1)) + 0x7ff) & 0xfff ); diff --git a/mc_mitm/source/controllers/ipega_controller.cpp b/mc_mitm/source/controllers/ipega_controller.cpp index 09bf5ae..bdd9388 100644 --- a/mc_mitm/source/controllers/ipega_controller.cpp +++ b/mc_mitm/source/controllers/ipega_controller.cpp @@ -44,11 +44,11 @@ namespace ams::controller { } void IpegaController::HandleInputReport0x07(const IpegaReportData *src) { - m_left_stick = this->PackStickData( + m_left_stick.SetData( static_cast(stick_scale_factor * src->input0x07.left_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x07.left_stick.y)) & 0xfff ); - m_right_stick = this->PackStickData( + m_right_stick.SetData( static_cast(stick_scale_factor * src->input0x07.right_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x07.right_stick.y)) & 0xfff ); diff --git a/mc_mitm/source/controllers/lanshen_controller.cpp b/mc_mitm/source/controllers/lanshen_controller.cpp index 9988456..3a1a144 100644 --- a/mc_mitm/source/controllers/lanshen_controller.cpp +++ b/mc_mitm/source/controllers/lanshen_controller.cpp @@ -37,11 +37,11 @@ namespace ams::controller { } void LanShenController::HandleInputReport0x01(const LanShenReportData *src) { - m_left_stick = this->PackStickData( + m_left_stick.SetData( static_cast(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & 0xfff ); - m_right_stick = this->PackStickData( + m_right_stick.SetData( static_cast(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & 0xfff ); diff --git a/mc_mitm/source/controllers/mad_catz_controller.cpp b/mc_mitm/source/controllers/mad_catz_controller.cpp index cfb4bc7..fc64ca7 100644 --- a/mc_mitm/source/controllers/mad_catz_controller.cpp +++ b/mc_mitm/source/controllers/mad_catz_controller.cpp @@ -40,11 +40,11 @@ namespace ams::controller { } void MadCatzController::HandleInputReport0x01(const MadCatzReportData *src) { - m_left_stick = this->PackStickData( + m_left_stick.SetData( static_cast(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & 0xfff ); - m_right_stick = this->PackStickData( + m_right_stick.SetData( static_cast(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & 0xfff ); diff --git a/mc_mitm/source/controllers/mocute_controller.cpp b/mc_mitm/source/controllers/mocute_controller.cpp index a92df17..61bc46a 100644 --- a/mc_mitm/source/controllers/mocute_controller.cpp +++ b/mc_mitm/source/controllers/mocute_controller.cpp @@ -39,11 +39,11 @@ namespace ams::controller { } void MocuteController::HandleInputReport(const MocuteReportData *src) { - m_left_stick = this->PackStickData( + m_left_stick.SetData( static_cast(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & 0xfff ); - m_right_stick = this->PackStickData( + m_right_stick.SetData( static_cast(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & 0xfff ); diff --git a/mc_mitm/source/controllers/nvidia_shield_controller.cpp b/mc_mitm/source/controllers/nvidia_shield_controller.cpp index 72e0b49..7138803 100644 --- a/mc_mitm/source/controllers/nvidia_shield_controller.cpp +++ b/mc_mitm/source/controllers/nvidia_shield_controller.cpp @@ -40,11 +40,11 @@ namespace ams::controller { } void NvidiaShieldController::HandleInputReport0x01(const NvidiaShieldReportData *src) { - m_left_stick = this->PackStickData( + m_left_stick.SetData( static_cast(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT16_MAX - src->input0x01.left_stick.y)) & 0xfff ); - m_right_stick = this->PackStickData( + m_right_stick.SetData( static_cast(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT16_MAX - src->input0x01.right_stick.y)) & 0xfff ); diff --git a/mc_mitm/source/controllers/ouya_controller.cpp b/mc_mitm/source/controllers/ouya_controller.cpp index 79b3edf..79104c2 100644 --- a/mc_mitm/source/controllers/ouya_controller.cpp +++ b/mc_mitm/source/controllers/ouya_controller.cpp @@ -45,11 +45,11 @@ namespace ams::controller { } void OuyaController::HandleInputReport0x07(const OuyaReportData *src) { - m_left_stick = this->PackStickData( + m_left_stick.SetData( static_cast(stick_scale_factor * src->input0x07.left_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT16_MAX - src->input0x07.left_stick.y)) & 0xfff ); - m_right_stick = this->PackStickData( + m_right_stick.SetData( static_cast(stick_scale_factor * src->input0x07.right_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT16_MAX - src->input0x07.right_stick.y)) & 0xfff ); diff --git a/mc_mitm/source/controllers/powera_controller.cpp b/mc_mitm/source/controllers/powera_controller.cpp index 7bdde5b..788ba81 100644 --- a/mc_mitm/source/controllers/powera_controller.cpp +++ b/mc_mitm/source/controllers/powera_controller.cpp @@ -40,11 +40,11 @@ namespace ams::controller { void PowerAController::HandleInputReport0x03(const PowerAReportData *src) { m_battery = convert_battery_255(src->input0x03.battery); - m_left_stick = this->PackStickData( + m_left_stick.SetData( static_cast(stick_scale_factor * src->input0x03.left_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x03.left_stick.y)) & 0xfff ); - m_right_stick = this->PackStickData( + m_right_stick.SetData( static_cast(stick_scale_factor * src->input0x03.right_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x03.right_stick.y)) & 0xfff ); diff --git a/mc_mitm/source/controllers/razer_controller.cpp b/mc_mitm/source/controllers/razer_controller.cpp index ccf0238..b9fb64f 100644 --- a/mc_mitm/source/controllers/razer_controller.cpp +++ b/mc_mitm/source/controllers/razer_controller.cpp @@ -37,11 +37,11 @@ namespace ams::controller { } void RazerController::HandleInputReport0x01(const RazerReportData *src) { - m_left_stick = this->PackStickData( + m_left_stick.SetData( static_cast(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & 0xfff ); - m_right_stick = this->PackStickData( + m_right_stick.SetData( static_cast(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & 0xfff ); diff --git a/mc_mitm/source/controllers/steelseries_controller.cpp b/mc_mitm/source/controllers/steelseries_controller.cpp index 6190d2d..8ef5bd9 100644 --- a/mc_mitm/source/controllers/steelseries_controller.cpp +++ b/mc_mitm/source/controllers/steelseries_controller.cpp @@ -45,11 +45,11 @@ namespace ams::controller { } void SteelseriesController::HandleInputReport0x01(const SteelseriesReportData *src) { - m_left_stick = this->PackStickData( + m_left_stick.SetData( static_cast(stick_scale_factor * -static_cast(~src->input0x01.left_stick.x + 1) + 0x7ff) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX + static_cast(~src->input0x01.left_stick.y + 1)) + 0x7ff) & 0xfff ); - m_right_stick = this->PackStickData( + m_right_stick.SetData( static_cast(stick_scale_factor * -static_cast(~src->input0x01.right_stick.x + 1) + 0x7ff) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX + static_cast(~src->input0x01.right_stick.y + 1)) + 0x7ff) & 0xfff ); @@ -84,11 +84,11 @@ namespace ams::controller { } void SteelseriesController::HandleInputReport0xc4(const SteelseriesReportData *src) { - m_left_stick = this->PackStickData( + m_left_stick.SetData( static_cast(stick_scale_factor * src->input0xc4.left_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0xc4.left_stick.y)) & 0xfff ); - m_right_stick = this->PackStickData( + m_right_stick.SetData( static_cast(stick_scale_factor * src->input0xc4.right_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0xc4.right_stick.y)) & 0xfff ); @@ -124,11 +124,11 @@ namespace ams::controller { } void SteelseriesController::HandleMfiInputReport(const SteelseriesReportData *src) { - m_left_stick = this->PackStickData( + m_left_stick.SetData( 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( + m_right_stick.SetData( 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 ); diff --git a/mc_mitm/source/controllers/switch_controller.hpp b/mc_mitm/source/controllers/switch_controller.hpp index 70f004e..cc64dc4 100644 --- a/mc_mitm/source/controllers/switch_controller.hpp +++ b/mc_mitm/source/controllers/switch_controller.hpp @@ -14,13 +14,12 @@ * along with this program. If not, see . */ #pragma once +#include "switch_analog_stick.hpp" #include "../bluetooth_mitm/bluetooth/bluetooth_types.hpp" #include "../bluetooth_mitm/bluetooth/bluetooth_hid_report.hpp" namespace ams::controller { - constexpr auto UINT12_MAX = 0xfff; - constexpr auto STICK_ZERO = 0x800; constexpr auto BATTERY_MAX = 8; enum SwitchPlayerNumber : uint8_t { @@ -53,10 +52,6 @@ namespace ams::controller { RGBColour right_grip; } __attribute__ ((__packed__)); - struct SwitchStickData { - uint8_t xy[3]; - } __attribute__ ((__packed__)); - struct SwitchButtonData { uint8_t Y : 1; uint8_t X : 1; @@ -200,8 +195,8 @@ namespace ams::controller { uint8_t conn_info : 4; uint8_t battery : 4; SwitchButtonData buttons; - SwitchStickData left_stick; - SwitchStickData right_stick; + SwitchAnalogStick left_stick; + SwitchAnalogStick right_stick; uint8_t vibrator; SwitchSubcommandResponse response; } __attribute__ ((__packed__)); @@ -213,8 +208,8 @@ namespace ams::controller { uint8_t conn_info : 4; uint8_t battery : 4; SwitchButtonData buttons; - SwitchStickData left_stick; - SwitchStickData right_stick; + SwitchAnalogStick left_stick; + SwitchAnalogStick right_stick; uint8_t vibrator; // IMU samples at 0, 5 and 10ms diff --git a/mc_mitm/source/controllers/wii_controller.cpp b/mc_mitm/source/controllers/wii_controller.cpp index 360133d..415f658 100644 --- a/mc_mitm/source/controllers/wii_controller.cpp +++ b/mc_mitm/source/controllers/wii_controller.cpp @@ -220,7 +220,7 @@ namespace ams::controller { void WiiController::MapNunchuckExtension(const uint8_t ext[]) { auto extension = reinterpret_cast(ext); - m_left_stick = this->PackStickData( + m_left_stick.SetData( std::clamp(static_cast(nunchuck_stick_scale_factor * (extension->stick_x - 0x80) + STICK_ZERO), 0, 0xfff), std::clamp(static_cast(nunchuck_stick_scale_factor * (extension->stick_y - 0x80) + STICK_ZERO), 0, 0xfff) ); @@ -230,11 +230,11 @@ namespace ams::controller { } void WiiController::MapClassicControllerExtension(const uint8_t ext[]) { - m_left_stick = this->PackStickData( + m_left_stick.SetData( static_cast(left_stick_scale_factor * ((ext[0] & 0x3f) - 0x20) + STICK_ZERO) & 0xfff, static_cast(left_stick_scale_factor * ((ext[1] & 0x3f) - 0x20) + STICK_ZERO) & 0xfff ); - m_right_stick = this->PackStickData( + m_right_stick.SetData( static_cast(right_stick_scale_factor * ((((ext[0] >> 3) & 0x18) | ((ext[1] >> 5) & 0x06) | ((ext[2] >> 7) & 0x01)) - 0x10) + STICK_ZERO) & 0xfff, static_cast(right_stick_scale_factor * ((ext[2] & 0x1f) - 0x10) + STICK_ZERO) & 0xfff ); @@ -265,11 +265,11 @@ namespace ams::controller { void WiiController::MapWiiUProControllerExtension(const uint8_t ext[]) { auto extension = reinterpret_cast(ext); - m_left_stick = this->PackStickData( + m_left_stick.SetData( std::clamp(((wiiu_scale_factor * (extension->left_stick_x - STICK_ZERO))) + STICK_ZERO, 0, 0xfff), std::clamp(((wiiu_scale_factor * (extension->left_stick_y - STICK_ZERO))) + STICK_ZERO, 0, 0xfff) ); - m_right_stick = this->PackStickData( + m_right_stick.SetData( std::clamp(((wiiu_scale_factor * (extension->right_stick_x - STICK_ZERO))) + STICK_ZERO, 0, 0xfff), std::clamp(((wiiu_scale_factor * (extension->right_stick_y - STICK_ZERO))) + STICK_ZERO, 0, 0xfff) ); diff --git a/mc_mitm/source/controllers/xbox_one_controller.cpp b/mc_mitm/source/controllers/xbox_one_controller.cpp index 3837f88..8f50573 100644 --- a/mc_mitm/source/controllers/xbox_one_controller.cpp +++ b/mc_mitm/source/controllers/xbox_one_controller.cpp @@ -58,11 +58,11 @@ namespace ams::controller { } void XboxOneController::HandleInputReport0x01(const XboxOneReportData *src, bool new_format) { - m_left_stick = this->PackStickData( + m_left_stick.SetData( static_cast(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT16_MAX - src->input0x01.left_stick.y)) & 0xfff ); - m_right_stick = this->PackStickData( + m_right_stick.SetData( static_cast(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT16_MAX - src->input0x01.right_stick.y)) & 0xfff ); diff --git a/mc_mitm/source/controllers/xiaomi_controller.cpp b/mc_mitm/source/controllers/xiaomi_controller.cpp index 9e032a8..0c29a7b 100644 --- a/mc_mitm/source/controllers/xiaomi_controller.cpp +++ b/mc_mitm/source/controllers/xiaomi_controller.cpp @@ -50,11 +50,11 @@ namespace ams::controller { void XiaomiController::HandleInputReport0x04(const XiaomiReportData *src) { m_battery = convert_battery_100(src->input0x04.battery); - m_left_stick = this->PackStickData( + m_left_stick.SetData( 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( + m_right_stick.SetData( static_cast(stick_scale_factor * src->input0x04.right_stick.x) & 0xfff, static_cast(stick_scale_factor * (UINT8_MAX - src->input0x04.right_stick.y)) & 0xfff );