diff options
| author | 2022-04-16 15:51:14 +0200 | |
|---|---|---|
| committer | 2022-04-16 15:51:14 +0200 | |
| commit | fd49b186fa13c74a61cdf70844486c75cfc0c930 (patch) | |
| tree | aff4d01b4a955e7928ed97cb979d80b596d013f3 /src/core/hid/emulated_devices.cpp | |
| parent | Merge pull request #8188 from merryhime/jit-race-page-table-changed (diff) | |
| parent | yuzu: Call ignore event after ensuring it's initialized (diff) | |
| download | yuzu-fd49b186fa13c74a61cdf70844486c75cfc0c930.tar.gz yuzu-fd49b186fa13c74a61cdf70844486c75cfc0c930.tar.xz yuzu-fd49b186fa13c74a61cdf70844486c75cfc0c930.zip | |
Merge pull request #6558 from german77/ringcon2
hidbus: Implement hidbus and ringcon
Diffstat (limited to 'src/core/hid/emulated_devices.cpp')
| -rw-r--r-- | src/core/hid/emulated_devices.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/core/hid/emulated_devices.cpp b/src/core/hid/emulated_devices.cpp index cc0dcd931..2f84d2b52 100644 --- a/src/core/hid/emulated_devices.cpp +++ b/src/core/hid/emulated_devices.cpp | |||
| @@ -15,6 +15,7 @@ EmulatedDevices::EmulatedDevices() = default; | |||
| 15 | EmulatedDevices::~EmulatedDevices() = default; | 15 | EmulatedDevices::~EmulatedDevices() = default; |
| 16 | 16 | ||
| 17 | void EmulatedDevices::ReloadFromSettings() { | 17 | void EmulatedDevices::ReloadFromSettings() { |
| 18 | ring_params = Common::ParamPackage(Settings::values.ringcon_analogs); | ||
| 18 | ReloadInput(); | 19 | ReloadInput(); |
| 19 | } | 20 | } |
| 20 | 21 | ||
| @@ -66,6 +67,8 @@ void EmulatedDevices::ReloadInput() { | |||
| 66 | key_index++; | 67 | key_index++; |
| 67 | } | 68 | } |
| 68 | 69 | ||
| 70 | ring_analog_device = Common::Input::CreateDevice<Common::Input::InputDevice>(ring_params); | ||
| 71 | |||
| 69 | for (std::size_t index = 0; index < mouse_button_devices.size(); ++index) { | 72 | for (std::size_t index = 0; index < mouse_button_devices.size(); ++index) { |
| 70 | if (!mouse_button_devices[index]) { | 73 | if (!mouse_button_devices[index]) { |
| 71 | continue; | 74 | continue; |
| @@ -120,6 +123,13 @@ void EmulatedDevices::ReloadInput() { | |||
| 120 | }, | 123 | }, |
| 121 | }); | 124 | }); |
| 122 | } | 125 | } |
| 126 | |||
| 127 | if (ring_analog_device) { | ||
| 128 | ring_analog_device->SetCallback({ | ||
| 129 | .on_change = | ||
| 130 | [this](const Common::Input::CallbackStatus& callback) { SetRingAnalog(callback); }, | ||
| 131 | }); | ||
| 132 | } | ||
| 123 | } | 133 | } |
| 124 | 134 | ||
| 125 | void EmulatedDevices::UnloadInput() { | 135 | void EmulatedDevices::UnloadInput() { |
| @@ -155,6 +165,7 @@ void EmulatedDevices::SaveCurrentConfig() { | |||
| 155 | if (!is_configuring) { | 165 | if (!is_configuring) { |
| 156 | return; | 166 | return; |
| 157 | } | 167 | } |
| 168 | Settings::values.ringcon_analogs = ring_params.Serialize(); | ||
| 158 | } | 169 | } |
| 159 | 170 | ||
| 160 | void EmulatedDevices::RestoreConfig() { | 171 | void EmulatedDevices::RestoreConfig() { |
| @@ -164,6 +175,15 @@ void EmulatedDevices::RestoreConfig() { | |||
| 164 | ReloadFromSettings(); | 175 | ReloadFromSettings(); |
| 165 | } | 176 | } |
| 166 | 177 | ||
| 178 | Common::ParamPackage EmulatedDevices::GetRingParam() const { | ||
| 179 | return ring_params; | ||
| 180 | } | ||
| 181 | |||
| 182 | void EmulatedDevices::SetRingParam(Common::ParamPackage param) { | ||
| 183 | ring_params = std::move(param); | ||
| 184 | ReloadInput(); | ||
| 185 | } | ||
| 186 | |||
| 167 | void EmulatedDevices::SetKeyboardButton(const Common::Input::CallbackStatus& callback, | 187 | void EmulatedDevices::SetKeyboardButton(const Common::Input::CallbackStatus& callback, |
| 168 | std::size_t index) { | 188 | std::size_t index) { |
| 169 | if (index >= device_status.keyboard_values.size()) { | 189 | if (index >= device_status.keyboard_values.size()) { |
| @@ -410,6 +430,23 @@ void EmulatedDevices::SetMouseStick(const Common::Input::CallbackStatus& callbac | |||
| 410 | TriggerOnChange(DeviceTriggerType::Mouse); | 430 | TriggerOnChange(DeviceTriggerType::Mouse); |
| 411 | } | 431 | } |
| 412 | 432 | ||
| 433 | void EmulatedDevices::SetRingAnalog(const Common::Input::CallbackStatus& callback) { | ||
| 434 | std::lock_guard lock{mutex}; | ||
| 435 | const auto force_value = TransformToStick(callback); | ||
| 436 | |||
| 437 | device_status.ring_analog_value = force_value.x; | ||
| 438 | |||
| 439 | if (is_configuring) { | ||
| 440 | device_status.ring_analog_value = {}; | ||
| 441 | TriggerOnChange(DeviceTriggerType::RingController); | ||
| 442 | return; | ||
| 443 | } | ||
| 444 | |||
| 445 | device_status.ring_analog_state.force = force_value.x.value; | ||
| 446 | |||
| 447 | TriggerOnChange(DeviceTriggerType::RingController); | ||
| 448 | } | ||
| 449 | |||
| 413 | KeyboardValues EmulatedDevices::GetKeyboardValues() const { | 450 | KeyboardValues EmulatedDevices::GetKeyboardValues() const { |
| 414 | std::scoped_lock lock{mutex}; | 451 | std::scoped_lock lock{mutex}; |
| 415 | return device_status.keyboard_values; | 452 | return device_status.keyboard_values; |
| @@ -425,6 +462,10 @@ MouseButtonValues EmulatedDevices::GetMouseButtonsValues() const { | |||
| 425 | return device_status.mouse_button_values; | 462 | return device_status.mouse_button_values; |
| 426 | } | 463 | } |
| 427 | 464 | ||
| 465 | RingAnalogValue EmulatedDevices::GetRingSensorValues() const { | ||
| 466 | return device_status.ring_analog_value; | ||
| 467 | } | ||
| 468 | |||
| 428 | KeyboardKey EmulatedDevices::GetKeyboard() const { | 469 | KeyboardKey EmulatedDevices::GetKeyboard() const { |
| 429 | std::scoped_lock lock{mutex}; | 470 | std::scoped_lock lock{mutex}; |
| 430 | return device_status.keyboard_state; | 471 | return device_status.keyboard_state; |
| @@ -450,6 +491,10 @@ AnalogStickState EmulatedDevices::GetMouseWheel() const { | |||
| 450 | return device_status.mouse_wheel_state; | 491 | return device_status.mouse_wheel_state; |
| 451 | } | 492 | } |
| 452 | 493 | ||
| 494 | RingSensorForce EmulatedDevices::GetRingSensorForce() const { | ||
| 495 | return device_status.ring_analog_state; | ||
| 496 | } | ||
| 497 | |||
| 453 | void EmulatedDevices::TriggerOnChange(DeviceTriggerType type) { | 498 | void EmulatedDevices::TriggerOnChange(DeviceTriggerType type) { |
| 454 | std::scoped_lock lock{callback_mutex}; | 499 | std::scoped_lock lock{callback_mutex}; |
| 455 | for (const auto& poller_pair : callback_list) { | 500 | for (const auto& poller_pair : callback_list) { |