diff options
author | german77 <juangerman-13@hotmail.com> | 2021-10-25 06:23:54 +0200 |
---|---|---|
committer | Narr the Reg <juangerman-13@hotmail.com> | 2021-11-25 03:30:26 +0100 |
commit | 064ddacf49aa7155e26add55983b81fdda997077 (patch) | |
tree | 17f6d767233c10578d84d2029014a3dfa4b55396 /src/core/hid | |
parent | input_common: Add manual update options to input devices (diff) | |
download | yuzu-064ddacf49aa7155e26add55983b81fdda997077.tar yuzu-064ddacf49aa7155e26add55983b81fdda997077.tar.gz yuzu-064ddacf49aa7155e26add55983b81fdda997077.tar.bz2 yuzu-064ddacf49aa7155e26add55983b81fdda997077.tar.lz yuzu-064ddacf49aa7155e26add55983b81fdda997077.tar.xz yuzu-064ddacf49aa7155e26add55983b81fdda997077.tar.zst yuzu-064ddacf49aa7155e26add55983b81fdda997077.zip |
Diffstat (limited to '')
-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 |
4 files changed, 54 insertions, 30 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() { ReloadInput(); } +void EmulatedController::LoadDevices() { + const auto left_joycon = button_params[Settings::NativeButton::ZL]; + const auto right_joycon = button_params[Settings::NativeButton::ZR]; -void EmulatedController::ReloadInput() { - // If you load any device here add the equivalent to the UnloadInput() function - const auto left_side = button_params[Settings::NativeButton::ZL]; - const auto right_side = button_params[Settings::NativeButton::ZR]; + // Triggers for GC controllers + trigger_params[LeftIndex] = button_params[Settings::NativeButton::ZL]; + trigger_params[RightIndex] = button_params[Settings::NativeButton::ZR]; + + battery_params[LeftIndex] = left_joycon; + battery_params[RightIndex] = right_joycon; + battery_params[LeftIndex].Set("battery", true); + battery_params[RightIndex].Set("battery", true); + + output_params[LeftIndex] = left_joycon; + output_params[RightIndex] = right_joycon; + output_params[LeftIndex].Set("output", true); + output_params[RightIndex].Set("output", true); std::transform(button_params.begin() + Settings::NativeButton::BUTTON_HID_BEGIN, button_params.begin() + Settings::NativeButton::BUTTON_NS_END, @@ -102,19 +114,17 @@ void EmulatedController::ReloadInput() { std::transform(motion_params.begin() + Settings::NativeMotion::MOTION_HID_BEGIN, motion_params.begin() + Settings::NativeMotion::MOTION_HID_END, motion_devices.begin(), Input::CreateDevice<Input::InputDevice>); + std::transform(trigger_params.begin(), trigger_params.end(), trigger_devices.begin(), + Input::CreateDevice<Input::InputDevice>); + std::transform(battery_params.begin(), battery_params.begin(), battery_devices.end(), + Input::CreateDevice<Input::InputDevice>); + std::transform(output_params.begin(), output_params.end(), output_devices.begin(), + Input::CreateDevice<Input::OutputDevice>); +} - trigger_devices[0] = - Input::CreateDevice<Input::InputDevice>(button_params[Settings::NativeButton::ZL]); - trigger_devices[1] = - Input::CreateDevice<Input::InputDevice>(button_params[Settings::NativeButton::ZR]); - - battery_devices[0] = Input::CreateDevice<Input::InputDevice>(left_side); - battery_devices[1] = Input::CreateDevice<Input::InputDevice>(right_side); - - button_params[Settings::NativeButton::ZL].Set("output", true); - output_devices[0] = - Input::CreateDevice<Input::OutputDevice>(button_params[Settings::NativeButton::ZL]); - +void EmulatedController::ReloadInput() { + // If you load any device here add the equivalent to the UnloadInput() function + LoadDevices(); for (std::size_t index = 0; index < button_devices.size(); ++index) { if (!button_devices[index]) { continue; @@ -241,7 +251,7 @@ void EmulatedController::RestoreConfig() { ReloadFromSettings(); } -std::vector<Common::ParamPackage> EmulatedController::GetMappedDevices() const { +std::vector<Common::ParamPackage> EmulatedController::GetMappedDevices(DeviceIndex device_index) const { std::vector<Common::ParamPackage> devices; for (const auto& param : button_params) { if (!param.Has("engine")) { @@ -612,21 +622,21 @@ void EmulatedController::SetBattery(Input::CallbackStatus callback, std::size_t } switch (index) { - case 0: + case LeftIndex: controller.battery_state.left = { .is_powered = is_powered, .is_charging = is_charging, .battery_level = battery_level, }; break; - case 1: + case RightIndex: controller.battery_state.right = { .is_powered = is_powered, .is_charging = is_charging, .battery_level = battery_level, }; break; - case 2: + case DualIndex: controller.battery_state.dual = { .is_powered = is_powered, .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 @@ #include "core/hid/motion_input.h" namespace Core::HID { - +const std::size_t max_emulated_controllers = 2; struct ControllerMotionInfo { Input::MotionStatus raw_status{}; MotionInput emulated{}; @@ -32,23 +32,23 @@ using ControllerMotionDevices = std::array<std::unique_ptr<Input::InputDevice>, Settings::NativeMotion::NumMotions>; using TriggerDevices = std::array<std::unique_ptr<Input::InputDevice>, Settings::NativeTrigger::NumTriggers>; -using BatteryDevices = std::array<std::unique_ptr<Input::InputDevice>, 2>; -using OutputDevices = std::array<std::unique_ptr<Input::OutputDevice>, 2>; +using BatteryDevices = std::array<std::unique_ptr<Input::InputDevice>, max_emulated_controllers>; +using OutputDevices = std::array<std::unique_ptr<Input::OutputDevice>, max_emulated_controllers>; using ButtonParams = std::array<Common::ParamPackage, Settings::NativeButton::NumButtons>; using StickParams = std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs>; using ControllerMotionParams = std::array<Common::ParamPackage, Settings::NativeMotion::NumMotions>; using TriggerParams = std::array<Common::ParamPackage, Settings::NativeTrigger::NumTriggers>; -using BatteryParams = std::array<Common::ParamPackage, 2>; -using OutputParams = std::array<Common::ParamPackage, 2>; +using BatteryParams = std::array<Common::ParamPackage, max_emulated_controllers>; +using OutputParams = std::array<Common::ParamPackage, max_emulated_controllers>; using ButtonValues = std::array<Input::ButtonStatus, Settings::NativeButton::NumButtons>; using SticksValues = std::array<Input::StickStatus, Settings::NativeAnalog::NumAnalogs>; using TriggerValues = std::array<Input::TriggerStatus, Settings::NativeTrigger::NumTriggers>; using ControllerMotionValues = std::array<ControllerMotionInfo, Settings::NativeMotion::NumMotions>; -using ColorValues = std::array<Input::BodyColorStatus, 3>; -using BatteryValues = std::array<Input::BatteryStatus, 3>; -using VibrationValues = std::array<Input::VibrationStatus, 2>; +using ColorValues = std::array<Input::BodyColorStatus, max_emulated_controllers>; +using BatteryValues = std::array<Input::BatteryStatus, max_emulated_controllers>; +using VibrationValues = std::array<Input::VibrationStatus, max_emulated_controllers>; struct AnalogSticks { AnalogStickState left{}; @@ -75,6 +75,13 @@ struct ControllerMotion { bool is_at_rest{}; }; +enum DeviceIndex : u8 { + LeftIndex, + RightIndex, + DualIndex, + AllDevices, +}; + using MotionState = std::array<ControllerMotion, 2>; struct ControllerStatus { @@ -189,7 +196,7 @@ public: void RestoreConfig(); /// Returns a vector of mapped devices from the mapped button and stick parameters - std::vector<Common::ParamPackage> GetMappedDevices() const; + std::vector<Common::ParamPackage> GetMappedDevices(DeviceIndex device_index) const; // Returns the current mapped button device Common::ParamPackage GetButtonParam(std::size_t index) const; @@ -289,6 +296,9 @@ public: void DeleteCallback(int key); private: + /// creates input devices from params + void LoadDevices(); + /** * Updates the button status of the controller * @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) { if (status) { entry = entry | mask; } else { - entry = entry & ~mask; + entry = static_cast<u8>(entry & ~mask); } } 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) { } break; } + case Input::InputType::Button: + battery = callback.button_status.value ? Input::BatteryLevel::Charging + : Input::BatteryLevel::Critical; + break; case Input::InputType::Battery: battery = callback.battery_status; break; |