diff options
Diffstat (limited to '')
-rw-r--r-- | src/common/settings.h | 8 | ||||
-rw-r--r-- | src/core/constants.cpp | 27 | ||||
-rw-r--r-- | src/core/constants.h | 2 | ||||
-rw-r--r-- | src/input_common/helpers/joycon_protocol/joycon_types.h | 12 | ||||
-rw-r--r-- | src/input_common/helpers/joycon_protocol/poller.cpp | 95 | ||||
-rw-r--r-- | src/input_common/helpers/joycon_protocol/poller.h | 9 |
6 files changed, 108 insertions, 45 deletions
diff --git a/src/common/settings.h b/src/common/settings.h index 512ecff69..1ae28ce93 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -128,7 +128,7 @@ public: /** * Sets a default value, label, and setting value. * - * @param default_val Intial value of the setting, and default value of the setting + * @param default_val Initial value of the setting, and default value of the setting * @param name Label for the setting */ explicit Setting(const Type& default_val, const std::string& name) @@ -139,7 +139,7 @@ public: /** * Sets a default value, minimum value, maximum value, and label. * - * @param default_val Intial value of the setting, and default value of the setting + * @param default_val Initial value of the setting, and default value of the setting * @param min_val Sets the minimum allowed value of the setting * @param max_val Sets the maximum allowed value of the setting * @param name Label for the setting @@ -231,7 +231,7 @@ public: /** * Sets a default value, label, and setting value. * - * @param default_val Intial value of the setting, and default value of the setting + * @param default_val Initial value of the setting, and default value of the setting * @param name Label for the setting */ explicit SwitchableSetting(const Type& default_val, const std::string& name) @@ -242,7 +242,7 @@ public: /** * Sets a default value, minimum value, maximum value, and label. * - * @param default_val Intial value of the setting, and default value of the setting + * @param default_val Initial value of the setting, and default value of the setting * @param min_val Sets the minimum allowed value of the setting * @param max_val Sets the maximum allowed value of the setting * @param name Label for the setting diff --git a/src/core/constants.cpp b/src/core/constants.cpp index 4430173ef..760dc5f23 100644 --- a/src/core/constants.cpp +++ b/src/core/constants.cpp @@ -4,13 +4,24 @@ #include "core/constants.h" namespace Core::Constants { -const std::array<u8, 107> ACCOUNT_BACKUP_JPEG{{ - 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02, - 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08, 0x06, 0x06, 0x05, - 0x06, 0x09, 0x08, 0x0a, 0x0a, 0x09, 0x08, 0x09, 0x09, 0x0a, 0x0c, 0x0f, 0x0c, 0x0a, 0x0b, 0x0e, - 0x0b, 0x09, 0x09, 0x0d, 0x11, 0x0d, 0x0e, 0x0f, 0x10, 0x10, 0x11, 0x10, 0x0a, 0x0c, 0x12, 0x13, - 0x12, 0x10, 0x13, 0x0f, 0x10, 0x10, 0x10, 0xff, 0xc9, 0x00, 0x0b, 0x08, 0x00, 0x01, 0x00, 0x01, - 0x01, 0x01, 0x11, 0x00, 0xff, 0xcc, 0x00, 0x06, 0x00, 0x10, 0x10, 0x05, 0xff, 0xda, 0x00, 0x08, - 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, +const std::array<u8, 287> ACCOUNT_BACKUP_JPEG{{ + 0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01, 0x01, 0x01, 0x00, 0x48, + 0x00, 0x48, 0x00, 0x00, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x06, 0x04, 0x04, 0x04, 0x05, 0x04, 0x06, + 0x05, 0x05, 0x06, 0x09, 0x06, 0x05, 0x06, 0x09, 0x0b, 0x08, 0x06, 0x06, 0x08, 0x0b, 0x0c, 0x0a, + 0x0a, 0x0b, 0x0a, 0x0a, 0x0c, 0x10, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x10, 0x0c, 0x0e, 0x0f, + 0x10, 0x0f, 0x0e, 0x0c, 0x13, 0x13, 0x14, 0x14, 0x13, 0x13, 0x1c, 0x1b, 0x1b, 0x1b, 0x1c, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xff, 0xdb, 0x00, 0x43, 0x01, 0x07, 0x07, + 0x07, 0x0d, 0x0c, 0x0d, 0x18, 0x10, 0x10, 0x18, 0x1a, 0x15, 0x11, 0x15, 0x1a, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xff, 0xc0, + 0x00, 0x11, 0x08, 0x00, 0x20, 0x00, 0x20, 0x03, 0x01, 0x22, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, + 0x01, 0xff, 0xc4, 0x00, 0x14, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc4, 0x00, 0x14, 0x10, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc4, 0x00, + 0x14, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0xc4, 0x00, 0x14, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, + 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xd9, }}; } diff --git a/src/core/constants.h b/src/core/constants.h index f916ce0b6..f1f67d3b8 100644 --- a/src/core/constants.h +++ b/src/core/constants.h @@ -12,6 +12,6 @@ namespace Core::Constants { // ACC Service - Blank JPEG used as user icon in absentia of real one. -extern const std::array<u8, 107> ACCOUNT_BACKUP_JPEG; +extern const std::array<u8, 287> ACCOUNT_BACKUP_JPEG; } // namespace Core::Constants diff --git a/src/input_common/helpers/joycon_protocol/joycon_types.h b/src/input_common/helpers/joycon_protocol/joycon_types.h index b91934990..2e50a99a8 100644 --- a/src/input_common/helpers/joycon_protocol/joycon_types.h +++ b/src/input_common/helpers/joycon_protocol/joycon_types.h @@ -95,6 +95,18 @@ enum class PasivePadButton : u32 { ZL_ZR = 0x8000, }; +enum class PasivePadStick : u8 { + Right = 0x00, + RightDown = 0x01, + Down = 0x02, + DownLeft = 0x03, + Left = 0x04, + LeftUp = 0x05, + Up = 0x06, + UpRight = 0x07, + Neutral = 0x08, +}; + enum class OutputReport : u8 { RUMBLE_AND_SUBCMD = 0x01, FW_UPDATE_PKT = 0x03, diff --git a/src/input_common/helpers/joycon_protocol/poller.cpp b/src/input_common/helpers/joycon_protocol/poller.cpp index 9bb15e935..ab48352b8 100644 --- a/src/input_common/helpers/joycon_protocol/poller.cpp +++ b/src/input_common/helpers/joycon_protocol/poller.cpp @@ -12,7 +12,7 @@ JoyconPoller::JoyconPoller(ControllerType device_type_, JoyStickCalibration left : device_type{device_type_}, left_stick_calibration{left_stick_calibration_}, right_stick_calibration{right_stick_calibration_}, motion_calibration{motion_calibration_} {} -void JoyconPoller::SetCallbacks(const Joycon::JoyconCallbacks& callbacks_) { +void JoyconPoller::SetCallbacks(const JoyconCallbacks& callbacks_) { callbacks = std::move(callbacks_); } @@ -22,13 +22,13 @@ void JoyconPoller::ReadActiveMode(std::span<u8> buffer, const MotionStatus& moti memcpy(&data, buffer.data(), sizeof(InputReportActive)); switch (device_type) { - case Joycon::ControllerType::Left: + case ControllerType::Left: UpdateActiveLeftPadInput(data, motion_status); break; - case Joycon::ControllerType::Right: + case ControllerType::Right: UpdateActiveRightPadInput(data, motion_status); break; - case Joycon::ControllerType::Pro: + case ControllerType::Pro: UpdateActiveProPadInput(data, motion_status); break; default: @@ -47,13 +47,13 @@ void JoyconPoller::ReadPassiveMode(std::span<u8> buffer) { memcpy(&data, buffer.data(), sizeof(InputReportPassive)); switch (device_type) { - case Joycon::ControllerType::Left: + case ControllerType::Left: UpdatePasiveLeftPadInput(data); break; - case Joycon::ControllerType::Right: + case ControllerType::Right: UpdatePasiveRightPadInput(data); break; - case Joycon::ControllerType::Pro: + case ControllerType::Pro: UpdatePasiveProPadInput(data); break; default: @@ -211,13 +211,11 @@ void JoyconPoller::UpdateActiveProPadInput(const InputReportActive& input, } void JoyconPoller::UpdatePasiveLeftPadInput(const InputReportPassive& input) { - static constexpr std::array<Joycon::PasivePadButton, 11> left_buttons{ - Joycon::PasivePadButton::Down_A, Joycon::PasivePadButton::Right_X, - Joycon::PasivePadButton::Left_B, Joycon::PasivePadButton::Up_Y, - Joycon::PasivePadButton::SL, Joycon::PasivePadButton::SR, - Joycon::PasivePadButton::L_R, Joycon::PasivePadButton::ZL_ZR, - Joycon::PasivePadButton::Minus, Joycon::PasivePadButton::Capture, - Joycon::PasivePadButton::StickL, + static constexpr std::array<PasivePadButton, 11> left_buttons{ + PasivePadButton::Down_A, PasivePadButton::Right_X, PasivePadButton::Left_B, + PasivePadButton::Up_Y, PasivePadButton::SL, PasivePadButton::SR, + PasivePadButton::L_R, PasivePadButton::ZL_ZR, PasivePadButton::Minus, + PasivePadButton::Capture, PasivePadButton::StickL, }; for (auto left_button : left_buttons) { @@ -225,16 +223,19 @@ void JoyconPoller::UpdatePasiveLeftPadInput(const InputReportPassive& input) { const int button = static_cast<int>(left_button); callbacks.on_button_data(button, button_status); } + + const auto [left_axis_x, left_axis_y] = + GetPassiveAxisValue(static_cast<PasivePadStick>(input.stick_state)); + callbacks.on_stick_data(static_cast<int>(PadAxes::LeftStickX), left_axis_x); + callbacks.on_stick_data(static_cast<int>(PadAxes::LeftStickY), left_axis_y); } void JoyconPoller::UpdatePasiveRightPadInput(const InputReportPassive& input) { - static constexpr std::array<Joycon::PasivePadButton, 11> right_buttons{ - Joycon::PasivePadButton::Down_A, Joycon::PasivePadButton::Right_X, - Joycon::PasivePadButton::Left_B, Joycon::PasivePadButton::Up_Y, - Joycon::PasivePadButton::SL, Joycon::PasivePadButton::SR, - Joycon::PasivePadButton::L_R, Joycon::PasivePadButton::ZL_ZR, - Joycon::PasivePadButton::Plus, Joycon::PasivePadButton::Home, - Joycon::PasivePadButton::StickR, + static constexpr std::array<PasivePadButton, 11> right_buttons{ + PasivePadButton::Down_A, PasivePadButton::Right_X, PasivePadButton::Left_B, + PasivePadButton::Up_Y, PasivePadButton::SL, PasivePadButton::SR, + PasivePadButton::L_R, PasivePadButton::ZL_ZR, PasivePadButton::Plus, + PasivePadButton::Home, PasivePadButton::StickR, }; for (auto right_button : right_buttons) { @@ -242,17 +243,20 @@ void JoyconPoller::UpdatePasiveRightPadInput(const InputReportPassive& input) { const int button = static_cast<int>(right_button); callbacks.on_button_data(button, button_status); } + + const auto [right_axis_x, right_axis_y] = + GetPassiveAxisValue(static_cast<PasivePadStick>(input.stick_state)); + callbacks.on_stick_data(static_cast<int>(PadAxes::RightStickX), right_axis_x); + callbacks.on_stick_data(static_cast<int>(PadAxes::RightStickY), right_axis_y); } void JoyconPoller::UpdatePasiveProPadInput(const InputReportPassive& input) { - static constexpr std::array<Joycon::PasivePadButton, 14> pro_buttons{ - Joycon::PasivePadButton::Down_A, Joycon::PasivePadButton::Right_X, - Joycon::PasivePadButton::Left_B, Joycon::PasivePadButton::Up_Y, - Joycon::PasivePadButton::SL, Joycon::PasivePadButton::SR, - Joycon::PasivePadButton::L_R, Joycon::PasivePadButton::ZL_ZR, - Joycon::PasivePadButton::Minus, Joycon::PasivePadButton::Plus, - Joycon::PasivePadButton::Capture, Joycon::PasivePadButton::Home, - Joycon::PasivePadButton::StickL, Joycon::PasivePadButton::StickR, + static constexpr std::array<PasivePadButton, 14> pro_buttons{ + PasivePadButton::Down_A, PasivePadButton::Right_X, PasivePadButton::Left_B, + PasivePadButton::Up_Y, PasivePadButton::SL, PasivePadButton::SR, + PasivePadButton::L_R, PasivePadButton::ZL_ZR, PasivePadButton::Minus, + PasivePadButton::Plus, PasivePadButton::Capture, PasivePadButton::Home, + PasivePadButton::StickL, PasivePadButton::StickR, }; for (auto pro_button : pro_buttons) { @@ -260,6 +264,15 @@ void JoyconPoller::UpdatePasiveProPadInput(const InputReportPassive& input) { const int button = static_cast<int>(pro_button); callbacks.on_button_data(button, button_status); } + + const auto [left_axis_x, left_axis_y] = + GetPassiveAxisValue(static_cast<PasivePadStick>(input.stick_state && 0xf)); + const auto [right_axis_x, right_axis_y] = + GetPassiveAxisValue(static_cast<PasivePadStick>(input.stick_state >> 4)); + callbacks.on_stick_data(static_cast<int>(PadAxes::LeftStickX), left_axis_x); + callbacks.on_stick_data(static_cast<int>(PadAxes::LeftStickY), left_axis_y); + callbacks.on_stick_data(static_cast<int>(PadAxes::RightStickX), right_axis_x); + callbacks.on_stick_data(static_cast<int>(PadAxes::RightStickY), right_axis_y); } f32 JoyconPoller::GetAxisValue(u16 raw_value, Joycon::JoyStickAxisCalibration calibration) const { @@ -270,6 +283,30 @@ f32 JoyconPoller::GetAxisValue(u16 raw_value, Joycon::JoyStickAxisCalibration ca return value / calibration.min; } +std::pair<f32, f32> JoyconPoller::GetPassiveAxisValue(PasivePadStick raw_value) const { + switch (raw_value) { + case PasivePadStick::Right: + return {1.0f, 0.0f}; + case PasivePadStick::RightDown: + return {1.0f, -1.0f}; + case PasivePadStick::Down: + return {0.0f, -1.0f}; + case PasivePadStick::DownLeft: + return {-1.0f, -1.0f}; + case PasivePadStick::Left: + return {-1.0f, 0.0f}; + case PasivePadStick::LeftUp: + return {-1.0f, 1.0f}; + case PasivePadStick::Up: + return {0.0f, 1.0f}; + case PasivePadStick::UpRight: + return {1.0f, 1.0f}; + case PasivePadStick::Neutral: + default: + return {0.0f, 0.0f}; + } +} + f32 JoyconPoller::GetAccelerometerValue(s16 raw, const MotionSensorCalibration& cal, AccelerometerSensitivity sensitivity) const { const f32 value = raw * (1.0f / (cal.scale - cal.offset)) * 4; diff --git a/src/input_common/helpers/joycon_protocol/poller.h b/src/input_common/helpers/joycon_protocol/poller.h index 354d41dad..5c897f070 100644 --- a/src/input_common/helpers/joycon_protocol/poller.h +++ b/src/input_common/helpers/joycon_protocol/poller.h @@ -22,7 +22,7 @@ public: JoyStickCalibration right_stick_calibration_, MotionCalibration motion_calibration_); - void SetCallbacks(const Joycon::JoyconCallbacks& callbacks_); + void SetCallbacks(const JoyconCallbacks& callbacks_); /// Handles data from passive packages void ReadPassiveMode(std::span<u8> buffer); @@ -51,7 +51,10 @@ private: void UpdatePasiveProPadInput(const InputReportPassive& buffer); /// Returns a calibrated joystick axis from raw axis data - f32 GetAxisValue(u16 raw_value, Joycon::JoyStickAxisCalibration calibration) const; + f32 GetAxisValue(u16 raw_value, JoyStickAxisCalibration calibration) const; + + /// Returns a digital joystick axis from passive axis data + std::pair<f32, f32> GetPassiveAxisValue(PasivePadStick raw_value) const; /// Returns a calibrated accelerometer axis from raw motion data f32 GetAccelerometerValue(s16 raw, const MotionSensorCalibration& cal, @@ -75,7 +78,7 @@ private: JoyStickCalibration right_stick_calibration{}; MotionCalibration motion_calibration{}; - Joycon::JoyconCallbacks callbacks{}; + JoyconCallbacks callbacks{}; }; } // namespace InputCommon::Joycon |