diff options
| author | 2021-10-24 23:23:54 -0500 | |
|---|---|---|
| committer | 2021-11-24 20:30:26 -0600 | |
| commit | 064ddacf49aa7155e26add55983b81fdda997077 (patch) | |
| tree | 17f6d767233c10578d84d2029014a3dfa4b55396 /src/core | |
| parent | input_common: Add manual update options to input devices (diff) | |
| download | yuzu-064ddacf49aa7155e26add55983b81fdda997077.tar.gz yuzu-064ddacf49aa7155e26add55983b81fdda997077.tar.xz yuzu-064ddacf49aa7155e26add55983b81fdda997077.zip | |
core/hid: Rework battery mappings
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 50 | ||||
| -rw-r--r-- | src/core/hid/emulated_controller.h | 28 | ||||
| -rw-r--r-- | src/core/hid/emulated_devices.cpp | 2 | ||||
| -rw-r--r-- | src/core/hid/input_converter.cpp | 4 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/npad.cpp | 11 |
5 files changed, 63 insertions, 32 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index 48add394b..83ced5635 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -87,11 +87,23 @@ void EmulatedController::ReloadFromSettings() { | |||
| 87 | 87 | ||
| 88 | ReloadInput(); | 88 | ReloadInput(); |
| 89 | } | 89 | } |
| 90 | void EmulatedController::LoadDevices() { | ||
| 91 | const auto left_joycon = button_params[Settings::NativeButton::ZL]; | ||
| 92 | const auto right_joycon = button_params[Settings::NativeButton::ZR]; | ||
| 90 | 93 | ||
| 91 | void EmulatedController::ReloadInput() { | 94 | // Triggers for GC controllers |
| 92 | // If you load any device here add the equivalent to the UnloadInput() function | 95 | trigger_params[LeftIndex] = button_params[Settings::NativeButton::ZL]; |
| 93 | const auto left_side = button_params[Settings::NativeButton::ZL]; | 96 | trigger_params[RightIndex] = button_params[Settings::NativeButton::ZR]; |
| 94 | const auto right_side = button_params[Settings::NativeButton::ZR]; | 97 | |
| 98 | battery_params[LeftIndex] = left_joycon; | ||
| 99 | battery_params[RightIndex] = right_joycon; | ||
| 100 | battery_params[LeftIndex].Set("battery", true); | ||
| 101 | battery_params[RightIndex].Set("battery", true); | ||
| 102 | |||
| 103 | output_params[LeftIndex] = left_joycon; | ||
| 104 | output_params[RightIndex] = right_joycon; | ||
| 105 | output_params[LeftIndex].Set("output", true); | ||
| 106 | output_params[RightIndex].Set("output", true); | ||
| 95 | 107 | ||
| 96 | std::transform(button_params.begin() + Settings::NativeButton::BUTTON_HID_BEGIN, | 108 | std::transform(button_params.begin() + Settings::NativeButton::BUTTON_HID_BEGIN, |
| 97 | button_params.begin() + Settings::NativeButton::BUTTON_NS_END, | 109 | button_params.begin() + Settings::NativeButton::BUTTON_NS_END, |
| @@ -102,19 +114,17 @@ void EmulatedController::ReloadInput() { | |||
| 102 | std::transform(motion_params.begin() + Settings::NativeMotion::MOTION_HID_BEGIN, | 114 | std::transform(motion_params.begin() + Settings::NativeMotion::MOTION_HID_BEGIN, |
| 103 | motion_params.begin() + Settings::NativeMotion::MOTION_HID_END, | 115 | motion_params.begin() + Settings::NativeMotion::MOTION_HID_END, |
| 104 | motion_devices.begin(), Input::CreateDevice<Input::InputDevice>); | 116 | motion_devices.begin(), Input::CreateDevice<Input::InputDevice>); |
| 117 | std::transform(trigger_params.begin(), trigger_params.end(), trigger_devices.begin(), | ||
| 118 | Input::CreateDevice<Input::InputDevice>); | ||
| 119 | std::transform(battery_params.begin(), battery_params.begin(), battery_devices.end(), | ||
| 120 | Input::CreateDevice<Input::InputDevice>); | ||
| 121 | std::transform(output_params.begin(), output_params.end(), output_devices.begin(), | ||
| 122 | Input::CreateDevice<Input::OutputDevice>); | ||
| 123 | } | ||
| 105 | 124 | ||
| 106 | trigger_devices[0] = | 125 | void EmulatedController::ReloadInput() { |
| 107 | Input::CreateDevice<Input::InputDevice>(button_params[Settings::NativeButton::ZL]); | 126 | // If you load any device here add the equivalent to the UnloadInput() function |
| 108 | trigger_devices[1] = | 127 | LoadDevices(); |
| 109 | Input::CreateDevice<Input::InputDevice>(button_params[Settings::NativeButton::ZR]); | ||
| 110 | |||
| 111 | battery_devices[0] = Input::CreateDevice<Input::InputDevice>(left_side); | ||
| 112 | battery_devices[1] = Input::CreateDevice<Input::InputDevice>(right_side); | ||
| 113 | |||
| 114 | button_params[Settings::NativeButton::ZL].Set("output", true); | ||
| 115 | output_devices[0] = | ||
| 116 | Input::CreateDevice<Input::OutputDevice>(button_params[Settings::NativeButton::ZL]); | ||
| 117 | |||
| 118 | for (std::size_t index = 0; index < button_devices.size(); ++index) { | 128 | for (std::size_t index = 0; index < button_devices.size(); ++index) { |
| 119 | if (!button_devices[index]) { | 129 | if (!button_devices[index]) { |
| 120 | continue; | 130 | continue; |
| @@ -241,7 +251,7 @@ void EmulatedController::RestoreConfig() { | |||
| 241 | ReloadFromSettings(); | 251 | ReloadFromSettings(); |
| 242 | } | 252 | } |
| 243 | 253 | ||
| 244 | std::vector<Common::ParamPackage> EmulatedController::GetMappedDevices() const { | 254 | std::vector<Common::ParamPackage> EmulatedController::GetMappedDevices(DeviceIndex device_index) const { |
| 245 | std::vector<Common::ParamPackage> devices; | 255 | std::vector<Common::ParamPackage> devices; |
| 246 | for (const auto& param : button_params) { | 256 | for (const auto& param : button_params) { |
| 247 | if (!param.Has("engine")) { | 257 | if (!param.Has("engine")) { |
| @@ -612,21 +622,21 @@ void EmulatedController::SetBattery(Input::CallbackStatus callback, std::size_t | |||
| 612 | } | 622 | } |
| 613 | 623 | ||
| 614 | switch (index) { | 624 | switch (index) { |
| 615 | case 0: | 625 | case LeftIndex: |
| 616 | controller.battery_state.left = { | 626 | controller.battery_state.left = { |
| 617 | .is_powered = is_powered, | 627 | .is_powered = is_powered, |
| 618 | .is_charging = is_charging, | 628 | .is_charging = is_charging, |
| 619 | .battery_level = battery_level, | 629 | .battery_level = battery_level, |
| 620 | }; | 630 | }; |
| 621 | break; | 631 | break; |
| 622 | case 1: | 632 | case RightIndex: |
| 623 | controller.battery_state.right = { | 633 | controller.battery_state.right = { |
| 624 | .is_powered = is_powered, | 634 | .is_powered = is_powered, |
| 625 | .is_charging = is_charging, | 635 | .is_charging = is_charging, |
| 626 | .battery_level = battery_level, | 636 | .battery_level = battery_level, |
| 627 | }; | 637 | }; |
| 628 | break; | 638 | break; |
| 629 | case 2: | 639 | case DualIndex: |
| 630 | controller.battery_state.dual = { | 640 | controller.battery_state.dual = { |
| 631 | .is_powered = is_powered, | 641 | .is_powered = is_powered, |
| 632 | .is_charging = is_charging, | 642 | .is_charging = is_charging, |
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h index d66768549..eb705a241 100644 --- a/src/core/hid/emulated_controller.h +++ b/src/core/hid/emulated_controller.h | |||
| @@ -18,7 +18,7 @@ | |||
| 18 | #include "core/hid/motion_input.h" | 18 | #include "core/hid/motion_input.h" |
| 19 | 19 | ||
| 20 | namespace Core::HID { | 20 | namespace Core::HID { |
| 21 | 21 | const std::size_t max_emulated_controllers = 2; | |
| 22 | struct ControllerMotionInfo { | 22 | struct ControllerMotionInfo { |
| 23 | Input::MotionStatus raw_status{}; | 23 | Input::MotionStatus raw_status{}; |
| 24 | MotionInput emulated{}; | 24 | MotionInput emulated{}; |
| @@ -32,23 +32,23 @@ using ControllerMotionDevices = | |||
| 32 | std::array<std::unique_ptr<Input::InputDevice>, Settings::NativeMotion::NumMotions>; | 32 | std::array<std::unique_ptr<Input::InputDevice>, Settings::NativeMotion::NumMotions>; |
| 33 | using TriggerDevices = | 33 | using TriggerDevices = |
| 34 | std::array<std::unique_ptr<Input::InputDevice>, Settings::NativeTrigger::NumTriggers>; | 34 | std::array<std::unique_ptr<Input::InputDevice>, Settings::NativeTrigger::NumTriggers>; |
| 35 | using BatteryDevices = std::array<std::unique_ptr<Input::InputDevice>, 2>; | 35 | using BatteryDevices = std::array<std::unique_ptr<Input::InputDevice>, max_emulated_controllers>; |
| 36 | using OutputDevices = std::array<std::unique_ptr<Input::OutputDevice>, 2>; | 36 | using OutputDevices = std::array<std::unique_ptr<Input::OutputDevice>, max_emulated_controllers>; |
| 37 | 37 | ||
| 38 | using ButtonParams = std::array<Common::ParamPackage, Settings::NativeButton::NumButtons>; | 38 | using ButtonParams = std::array<Common::ParamPackage, Settings::NativeButton::NumButtons>; |
| 39 | using StickParams = std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs>; | 39 | using StickParams = std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs>; |
| 40 | using ControllerMotionParams = std::array<Common::ParamPackage, Settings::NativeMotion::NumMotions>; | 40 | using ControllerMotionParams = std::array<Common::ParamPackage, Settings::NativeMotion::NumMotions>; |
| 41 | using TriggerParams = std::array<Common::ParamPackage, Settings::NativeTrigger::NumTriggers>; | 41 | using TriggerParams = std::array<Common::ParamPackage, Settings::NativeTrigger::NumTriggers>; |
| 42 | using BatteryParams = std::array<Common::ParamPackage, 2>; | 42 | using BatteryParams = std::array<Common::ParamPackage, max_emulated_controllers>; |
| 43 | using OutputParams = std::array<Common::ParamPackage, 2>; | 43 | using OutputParams = std::array<Common::ParamPackage, max_emulated_controllers>; |
| 44 | 44 | ||
| 45 | using ButtonValues = std::array<Input::ButtonStatus, Settings::NativeButton::NumButtons>; | 45 | using ButtonValues = std::array<Input::ButtonStatus, Settings::NativeButton::NumButtons>; |
| 46 | using SticksValues = std::array<Input::StickStatus, Settings::NativeAnalog::NumAnalogs>; | 46 | using SticksValues = std::array<Input::StickStatus, Settings::NativeAnalog::NumAnalogs>; |
| 47 | using TriggerValues = std::array<Input::TriggerStatus, Settings::NativeTrigger::NumTriggers>; | 47 | using TriggerValues = std::array<Input::TriggerStatus, Settings::NativeTrigger::NumTriggers>; |
| 48 | using ControllerMotionValues = std::array<ControllerMotionInfo, Settings::NativeMotion::NumMotions>; | 48 | using ControllerMotionValues = std::array<ControllerMotionInfo, Settings::NativeMotion::NumMotions>; |
| 49 | using ColorValues = std::array<Input::BodyColorStatus, 3>; | 49 | using ColorValues = std::array<Input::BodyColorStatus, max_emulated_controllers>; |
| 50 | using BatteryValues = std::array<Input::BatteryStatus, 3>; | 50 | using BatteryValues = std::array<Input::BatteryStatus, max_emulated_controllers>; |
| 51 | using VibrationValues = std::array<Input::VibrationStatus, 2>; | 51 | using VibrationValues = std::array<Input::VibrationStatus, max_emulated_controllers>; |
| 52 | 52 | ||
| 53 | struct AnalogSticks { | 53 | struct AnalogSticks { |
| 54 | AnalogStickState left{}; | 54 | AnalogStickState left{}; |
| @@ -75,6 +75,13 @@ struct ControllerMotion { | |||
| 75 | bool is_at_rest{}; | 75 | bool is_at_rest{}; |
| 76 | }; | 76 | }; |
| 77 | 77 | ||
| 78 | enum DeviceIndex : u8 { | ||
| 79 | LeftIndex, | ||
| 80 | RightIndex, | ||
| 81 | DualIndex, | ||
| 82 | AllDevices, | ||
| 83 | }; | ||
| 84 | |||
| 78 | using MotionState = std::array<ControllerMotion, 2>; | 85 | using MotionState = std::array<ControllerMotion, 2>; |
| 79 | 86 | ||
| 80 | struct ControllerStatus { | 87 | struct ControllerStatus { |
| @@ -189,7 +196,7 @@ public: | |||
| 189 | void RestoreConfig(); | 196 | void RestoreConfig(); |
| 190 | 197 | ||
| 191 | /// Returns a vector of mapped devices from the mapped button and stick parameters | 198 | /// Returns a vector of mapped devices from the mapped button and stick parameters |
| 192 | std::vector<Common::ParamPackage> GetMappedDevices() const; | 199 | std::vector<Common::ParamPackage> GetMappedDevices(DeviceIndex device_index) const; |
| 193 | 200 | ||
| 194 | // Returns the current mapped button device | 201 | // Returns the current mapped button device |
| 195 | Common::ParamPackage GetButtonParam(std::size_t index) const; | 202 | Common::ParamPackage GetButtonParam(std::size_t index) const; |
| @@ -289,6 +296,9 @@ public: | |||
| 289 | void DeleteCallback(int key); | 296 | void DeleteCallback(int key); |
| 290 | 297 | ||
| 291 | private: | 298 | private: |
| 299 | /// creates input devices from params | ||
| 300 | void LoadDevices(); | ||
| 301 | |||
| 292 | /** | 302 | /** |
| 293 | * Updates the button status of the controller | 303 | * Updates the button status of the controller |
| 294 | * @param callback: A CallbackStatus containing the button status | 304 | * @param callback: A CallbackStatus containing the button status |
diff --git a/src/core/hid/emulated_devices.cpp b/src/core/hid/emulated_devices.cpp index 5afd83f62..eb59c310c 100644 --- a/src/core/hid/emulated_devices.cpp +++ b/src/core/hid/emulated_devices.cpp | |||
| @@ -174,7 +174,7 @@ void EmulatedDevices::UpdateKey(std::size_t key_index, bool status) { | |||
| 174 | if (status) { | 174 | if (status) { |
| 175 | entry = entry | mask; | 175 | entry = entry | mask; |
| 176 | } else { | 176 | } else { |
| 177 | entry = entry & ~mask; | 177 | entry = static_cast<u8>(entry & ~mask); |
| 178 | } | 178 | } |
| 179 | } | 179 | } |
| 180 | 180 | ||
diff --git a/src/core/hid/input_converter.cpp b/src/core/hid/input_converter.cpp index b3c8913ce..e2598f367 100644 --- a/src/core/hid/input_converter.cpp +++ b/src/core/hid/input_converter.cpp | |||
| @@ -33,6 +33,10 @@ Input::BatteryStatus TransformToBattery(const Input::CallbackStatus& callback) { | |||
| 33 | } | 33 | } |
| 34 | break; | 34 | break; |
| 35 | } | 35 | } |
| 36 | case Input::InputType::Button: | ||
| 37 | battery = callback.button_status.value ? Input::BatteryLevel::Charging | ||
| 38 | : Input::BatteryLevel::Critical; | ||
| 39 | break; | ||
| 36 | case Input::InputType::Battery: | 40 | case Input::InputType::Battery: |
| 37 | battery = callback.battery_status; | 41 | battery = callback.battery_status; |
| 38 | break; | 42 | break; |
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index 7bf31f63a..9f84e20c2 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp | |||
| @@ -101,8 +101,9 @@ Controller_NPad::Controller_NPad(Core::System& system_, | |||
| 101 | for (std::size_t i = 0; i < controller_data.size(); ++i) { | 101 | for (std::size_t i = 0; i < controller_data.size(); ++i) { |
| 102 | auto& controller = controller_data[i]; | 102 | auto& controller = controller_data[i]; |
| 103 | controller.device = system.HIDCore().GetEmulatedControllerByIndex(i); | 103 | controller.device = system.HIDCore().GetEmulatedControllerByIndex(i); |
| 104 | controller.vibration[0].latest_vibration_value = DEFAULT_VIBRATION_VALUE; | 104 | controller.vibration[Core::HID::DeviceIndex::LeftIndex].latest_vibration_value = DEFAULT_VIBRATION_VALUE; |
| 105 | controller.vibration[1].latest_vibration_value = DEFAULT_VIBRATION_VALUE; | 105 | controller.vibration[Core::HID::DeviceIndex::RightIndex].latest_vibration_value = |
| 106 | DEFAULT_VIBRATION_VALUE; | ||
| 106 | Core::HID::ControllerUpdateCallback engine_callback{ | 107 | Core::HID::ControllerUpdateCallback engine_callback{ |
| 107 | .on_change = [this, | 108 | .on_change = [this, |
| 108 | i](Core::HID::ControllerTriggerType type) { ControllerUpdate(type, i); }, | 109 | i](Core::HID::ControllerTriggerType type) { ControllerUpdate(type, i); }, |
| @@ -285,9 +286,12 @@ void Controller_NPad::OnInit() { | |||
| 285 | auto& npad = controller.shared_memory_entry; | 286 | auto& npad = controller.shared_memory_entry; |
| 286 | npad.fullkey_color = { | 287 | npad.fullkey_color = { |
| 287 | .attribute = ColorAttribute::NoController, | 288 | .attribute = ColorAttribute::NoController, |
| 289 | .fullkey = {}, | ||
| 288 | }; | 290 | }; |
| 289 | npad.joycon_color = { | 291 | npad.joycon_color = { |
| 290 | .attribute = ColorAttribute::NoController, | 292 | .attribute = ColorAttribute::NoController, |
| 293 | .left = {}, | ||
| 294 | .right = {}, | ||
| 291 | }; | 295 | }; |
| 292 | // HW seems to initialize the first 19 entries | 296 | // HW seems to initialize the first 19 entries |
| 293 | for (std::size_t i = 0; i < 19; ++i) { | 297 | for (std::size_t i = 0; i < 19; ++i) { |
| @@ -907,9 +911,12 @@ void Controller_NPad::DisconnectNpadAtIndex(std::size_t npad_index) { | |||
| 907 | shared_memory_entry.battery_level_right = 0; | 911 | shared_memory_entry.battery_level_right = 0; |
| 908 | shared_memory_entry.fullkey_color = { | 912 | shared_memory_entry.fullkey_color = { |
| 909 | .attribute = ColorAttribute::NoController, | 913 | .attribute = ColorAttribute::NoController, |
| 914 | .fullkey = {}, | ||
| 910 | }; | 915 | }; |
| 911 | shared_memory_entry.joycon_color = { | 916 | shared_memory_entry.joycon_color = { |
| 912 | .attribute = ColorAttribute::NoController, | 917 | .attribute = ColorAttribute::NoController, |
| 918 | .left = {}, | ||
| 919 | .right = {}, | ||
| 913 | }; | 920 | }; |
| 914 | shared_memory_entry.assignment_mode = NpadJoyAssignmentMode::Dual; | 921 | shared_memory_entry.assignment_mode = NpadJoyAssignmentMode::Dual; |
| 915 | shared_memory_entry.footer_type = AppletFooterUiType::None; | 922 | shared_memory_entry.footer_type = AppletFooterUiType::None; |