diff options
Diffstat (limited to 'src/core/hid')
| -rw-r--r-- | src/core/hid/emulated_devices.cpp | 45 | ||||
| -rw-r--r-- | src/core/hid/emulated_devices.h | 34 |
2 files changed, 79 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) { |
diff --git a/src/core/hid/emulated_devices.h b/src/core/hid/emulated_devices.h index 73e9f0293..fb6451e7a 100644 --- a/src/core/hid/emulated_devices.h +++ b/src/core/hid/emulated_devices.h | |||
| @@ -26,9 +26,11 @@ using MouseButtonDevices = std::array<std::unique_ptr<Common::Input::InputDevice | |||
| 26 | using MouseAnalogDevices = std::array<std::unique_ptr<Common::Input::InputDevice>, | 26 | using MouseAnalogDevices = std::array<std::unique_ptr<Common::Input::InputDevice>, |
| 27 | Settings::NativeMouseWheel::NumMouseWheels>; | 27 | Settings::NativeMouseWheel::NumMouseWheels>; |
| 28 | using MouseStickDevice = std::unique_ptr<Common::Input::InputDevice>; | 28 | using MouseStickDevice = std::unique_ptr<Common::Input::InputDevice>; |
| 29 | using RingAnalogDevice = std::unique_ptr<Common::Input::InputDevice>; | ||
| 29 | 30 | ||
| 30 | using MouseButtonParams = | 31 | using MouseButtonParams = |
| 31 | std::array<Common::ParamPackage, Settings::NativeMouseButton::NumMouseButtons>; | 32 | std::array<Common::ParamPackage, Settings::NativeMouseButton::NumMouseButtons>; |
| 33 | using RingAnalogParams = Common::ParamPackage; | ||
| 32 | 34 | ||
| 33 | using KeyboardValues = | 35 | using KeyboardValues = |
| 34 | std::array<Common::Input::ButtonStatus, Settings::NativeKeyboard::NumKeyboardKeys>; | 36 | std::array<Common::Input::ButtonStatus, Settings::NativeKeyboard::NumKeyboardKeys>; |
| @@ -39,12 +41,17 @@ using MouseButtonValues = | |||
| 39 | using MouseAnalogValues = | 41 | using MouseAnalogValues = |
| 40 | std::array<Common::Input::AnalogStatus, Settings::NativeMouseWheel::NumMouseWheels>; | 42 | std::array<Common::Input::AnalogStatus, Settings::NativeMouseWheel::NumMouseWheels>; |
| 41 | using MouseStickValue = Common::Input::TouchStatus; | 43 | using MouseStickValue = Common::Input::TouchStatus; |
| 44 | using RingAnalogValue = Common::Input::AnalogStatus; | ||
| 42 | 45 | ||
| 43 | struct MousePosition { | 46 | struct MousePosition { |
| 44 | f32 x; | 47 | f32 x; |
| 45 | f32 y; | 48 | f32 y; |
| 46 | }; | 49 | }; |
| 47 | 50 | ||
| 51 | struct RingSensorForce { | ||
| 52 | f32 force; | ||
| 53 | }; | ||
| 54 | |||
| 48 | struct DeviceStatus { | 55 | struct DeviceStatus { |
| 49 | // Data from input_common | 56 | // Data from input_common |
| 50 | KeyboardValues keyboard_values{}; | 57 | KeyboardValues keyboard_values{}; |
| @@ -52,6 +59,7 @@ struct DeviceStatus { | |||
| 52 | MouseButtonValues mouse_button_values{}; | 59 | MouseButtonValues mouse_button_values{}; |
| 53 | MouseAnalogValues mouse_analog_values{}; | 60 | MouseAnalogValues mouse_analog_values{}; |
| 54 | MouseStickValue mouse_stick_value{}; | 61 | MouseStickValue mouse_stick_value{}; |
| 62 | RingAnalogValue ring_analog_value{}; | ||
| 55 | 63 | ||
| 56 | // Data for HID serices | 64 | // Data for HID serices |
| 57 | KeyboardKey keyboard_state{}; | 65 | KeyboardKey keyboard_state{}; |
| @@ -59,12 +67,14 @@ struct DeviceStatus { | |||
| 59 | MouseButton mouse_button_state{}; | 67 | MouseButton mouse_button_state{}; |
| 60 | MousePosition mouse_position_state{}; | 68 | MousePosition mouse_position_state{}; |
| 61 | AnalogStickState mouse_wheel_state{}; | 69 | AnalogStickState mouse_wheel_state{}; |
| 70 | RingSensorForce ring_analog_state{}; | ||
| 62 | }; | 71 | }; |
| 63 | 72 | ||
| 64 | enum class DeviceTriggerType { | 73 | enum class DeviceTriggerType { |
| 65 | Keyboard, | 74 | Keyboard, |
| 66 | KeyboardModdifier, | 75 | KeyboardModdifier, |
| 67 | Mouse, | 76 | Mouse, |
| 77 | RingController, | ||
| 68 | }; | 78 | }; |
| 69 | 79 | ||
| 70 | struct InterfaceUpdateCallback { | 80 | struct InterfaceUpdateCallback { |
| @@ -110,6 +120,15 @@ public: | |||
| 110 | /// Reverts any mapped changes made that weren't saved | 120 | /// Reverts any mapped changes made that weren't saved |
| 111 | void RestoreConfig(); | 121 | void RestoreConfig(); |
| 112 | 122 | ||
| 123 | // Returns the current mapped ring device | ||
| 124 | Common::ParamPackage GetRingParam() const; | ||
| 125 | |||
| 126 | /** | ||
| 127 | * Updates the current mapped ring device | ||
| 128 | * @param param ParamPackage with ring sensor data to be mapped | ||
| 129 | */ | ||
| 130 | void SetRingParam(Common::ParamPackage param); | ||
| 131 | |||
| 113 | /// Returns the latest status of button input from the keyboard with parameters | 132 | /// Returns the latest status of button input from the keyboard with parameters |
| 114 | KeyboardValues GetKeyboardValues() const; | 133 | KeyboardValues GetKeyboardValues() const; |
| 115 | 134 | ||
| @@ -119,6 +138,9 @@ public: | |||
| 119 | /// Returns the latest status of button input from the mouse with parameters | 138 | /// Returns the latest status of button input from the mouse with parameters |
| 120 | MouseButtonValues GetMouseButtonsValues() const; | 139 | MouseButtonValues GetMouseButtonsValues() const; |
| 121 | 140 | ||
| 141 | /// Returns the latest status of analog input from the ring sensor with parameters | ||
| 142 | RingAnalogValue GetRingSensorValues() const; | ||
| 143 | |||
| 122 | /// Returns the latest status of button input from the keyboard | 144 | /// Returns the latest status of button input from the keyboard |
| 123 | KeyboardKey GetKeyboard() const; | 145 | KeyboardKey GetKeyboard() const; |
| 124 | 146 | ||
| @@ -134,6 +156,9 @@ public: | |||
| 134 | /// Returns the latest mouse wheel change | 156 | /// Returns the latest mouse wheel change |
| 135 | AnalogStickState GetMouseWheel() const; | 157 | AnalogStickState GetMouseWheel() const; |
| 136 | 158 | ||
| 159 | /// Returns the latest ringcon force sensor value | ||
| 160 | RingSensorForce GetRingSensorForce() const; | ||
| 161 | |||
| 137 | /** | 162 | /** |
| 138 | * Adds a callback to the list of events | 163 | * Adds a callback to the list of events |
| 139 | * @param update_callback InterfaceUpdateCallback that will be triggered | 164 | * @param update_callback InterfaceUpdateCallback that will be triggered |
| @@ -186,6 +211,12 @@ private: | |||
| 186 | void SetMouseStick(const Common::Input::CallbackStatus& callback); | 211 | void SetMouseStick(const Common::Input::CallbackStatus& callback); |
| 187 | 212 | ||
| 188 | /** | 213 | /** |
| 214 | * Updates the ring analog sensor status of the ring controller | ||
| 215 | * @param callback A CallbackStatus containing the force status | ||
| 216 | */ | ||
| 217 | void SetRingAnalog(const Common::Input::CallbackStatus& callback); | ||
| 218 | |||
| 219 | /** | ||
| 189 | * Triggers a callback that something has changed on the device status | 220 | * Triggers a callback that something has changed on the device status |
| 190 | * @param type Input type of the event to trigger | 221 | * @param type Input type of the event to trigger |
| 191 | */ | 222 | */ |
| @@ -193,11 +224,14 @@ private: | |||
| 193 | 224 | ||
| 194 | bool is_configuring{false}; | 225 | bool is_configuring{false}; |
| 195 | 226 | ||
| 227 | RingAnalogParams ring_params; | ||
| 228 | |||
| 196 | KeyboardDevices keyboard_devices; | 229 | KeyboardDevices keyboard_devices; |
| 197 | KeyboardModifierDevices keyboard_modifier_devices; | 230 | KeyboardModifierDevices keyboard_modifier_devices; |
| 198 | MouseButtonDevices mouse_button_devices; | 231 | MouseButtonDevices mouse_button_devices; |
| 199 | MouseAnalogDevices mouse_analog_devices; | 232 | MouseAnalogDevices mouse_analog_devices; |
| 200 | MouseStickDevice mouse_stick_device; | 233 | MouseStickDevice mouse_stick_device; |
| 234 | RingAnalogDevice ring_analog_device; | ||
| 201 | 235 | ||
| 202 | mutable std::mutex mutex; | 236 | mutable std::mutex mutex; |
| 203 | mutable std::mutex callback_mutex; | 237 | mutable std::mutex callback_mutex; |