diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/input.h | 10 | ||||
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 9 | ||||
| -rw-r--r-- | src/input_common/helpers/stick_from_buttons.cpp | 16 | ||||
| -rw-r--r-- | src/input_common/helpers/touch_from_buttons.cpp | 1 | ||||
| -rw-r--r-- | src/input_common/input_poller.cpp | 20 |
5 files changed, 56 insertions, 0 deletions
diff --git a/src/common/input.h b/src/common/input.h index cdacd4689..cb84f1005 100644 --- a/src/common/input.h +++ b/src/common/input.h | |||
| @@ -164,6 +164,16 @@ class InputDevice { | |||
| 164 | public: | 164 | public: |
| 165 | virtual ~InputDevice() = default; | 165 | virtual ~InputDevice() = default; |
| 166 | 166 | ||
| 167 | // Request input device to update if necessary | ||
| 168 | virtual void SoftUpdate() { | ||
| 169 | return; | ||
| 170 | } | ||
| 171 | |||
| 172 | // Force input device to update data regarless of the current state | ||
| 173 | virtual void ForceUpdate() { | ||
| 174 | return; | ||
| 175 | } | ||
| 176 | |||
| 167 | void SetCallback(InputCallback callback_) { | 177 | void SetCallback(InputCallback callback_) { |
| 168 | callback = std::move(callback_); | 178 | callback = std::move(callback_); |
| 169 | } | 179 | } |
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index bd0b89c05..48add394b 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -122,6 +122,7 @@ void EmulatedController::ReloadInput() { | |||
| 122 | Input::InputCallback button_callback{ | 122 | Input::InputCallback button_callback{ |
| 123 | [this, index](Input::CallbackStatus callback) { SetButton(callback, index); }}; | 123 | [this, index](Input::CallbackStatus callback) { SetButton(callback, index); }}; |
| 124 | button_devices[index]->SetCallback(button_callback); | 124 | button_devices[index]->SetCallback(button_callback); |
| 125 | button_devices[index]->ForceUpdate(); | ||
| 125 | } | 126 | } |
| 126 | 127 | ||
| 127 | for (std::size_t index = 0; index < stick_devices.size(); ++index) { | 128 | for (std::size_t index = 0; index < stick_devices.size(); ++index) { |
| @@ -131,6 +132,7 @@ void EmulatedController::ReloadInput() { | |||
| 131 | Input::InputCallback stick_callback{ | 132 | Input::InputCallback stick_callback{ |
| 132 | [this, index](Input::CallbackStatus callback) { SetStick(callback, index); }}; | 133 | [this, index](Input::CallbackStatus callback) { SetStick(callback, index); }}; |
| 133 | stick_devices[index]->SetCallback(stick_callback); | 134 | stick_devices[index]->SetCallback(stick_callback); |
| 135 | stick_devices[index]->ForceUpdate(); | ||
| 134 | } | 136 | } |
| 135 | 137 | ||
| 136 | for (std::size_t index = 0; index < trigger_devices.size(); ++index) { | 138 | for (std::size_t index = 0; index < trigger_devices.size(); ++index) { |
| @@ -140,6 +142,7 @@ void EmulatedController::ReloadInput() { | |||
| 140 | Input::InputCallback trigger_callback{ | 142 | Input::InputCallback trigger_callback{ |
| 141 | [this, index](Input::CallbackStatus callback) { SetTrigger(callback, index); }}; | 143 | [this, index](Input::CallbackStatus callback) { SetTrigger(callback, index); }}; |
| 142 | trigger_devices[index]->SetCallback(trigger_callback); | 144 | trigger_devices[index]->SetCallback(trigger_callback); |
| 145 | trigger_devices[index]->ForceUpdate(); | ||
| 143 | } | 146 | } |
| 144 | 147 | ||
| 145 | for (std::size_t index = 0; index < battery_devices.size(); ++index) { | 148 | for (std::size_t index = 0; index < battery_devices.size(); ++index) { |
| @@ -149,6 +152,7 @@ void EmulatedController::ReloadInput() { | |||
| 149 | Input::InputCallback battery_callback{ | 152 | Input::InputCallback battery_callback{ |
| 150 | [this, index](Input::CallbackStatus callback) { SetBattery(callback, index); }}; | 153 | [this, index](Input::CallbackStatus callback) { SetBattery(callback, index); }}; |
| 151 | battery_devices[index]->SetCallback(battery_callback); | 154 | battery_devices[index]->SetCallback(battery_callback); |
| 155 | battery_devices[index]->ForceUpdate(); | ||
| 152 | } | 156 | } |
| 153 | 157 | ||
| 154 | for (std::size_t index = 0; index < motion_devices.size(); ++index) { | 158 | for (std::size_t index = 0; index < motion_devices.size(); ++index) { |
| @@ -158,6 +162,7 @@ void EmulatedController::ReloadInput() { | |||
| 158 | Input::InputCallback motion_callback{ | 162 | Input::InputCallback motion_callback{ |
| 159 | [this, index](Input::CallbackStatus callback) { SetMotion(callback, index); }}; | 163 | [this, index](Input::CallbackStatus callback) { SetMotion(callback, index); }}; |
| 160 | motion_devices[index]->SetCallback(motion_callback); | 164 | motion_devices[index]->SetCallback(motion_callback); |
| 165 | motion_devices[index]->ForceUpdate(); | ||
| 161 | } | 166 | } |
| 162 | } | 167 | } |
| 163 | 168 | ||
| @@ -843,6 +848,10 @@ AnalogSticks EmulatedController::GetSticks() const { | |||
| 843 | if (is_configuring) { | 848 | if (is_configuring) { |
| 844 | return {}; | 849 | return {}; |
| 845 | } | 850 | } |
| 851 | // Some drivers like stick from buttons need constant refreshing | ||
| 852 | for (auto& device : stick_devices) { | ||
| 853 | device->SoftUpdate(); | ||
| 854 | } | ||
| 846 | return controller.analog_stick_state; | 855 | return controller.analog_stick_state; |
| 847 | } | 856 | } |
| 848 | 857 | ||
diff --git a/src/input_common/helpers/stick_from_buttons.cpp b/src/input_common/helpers/stick_from_buttons.cpp index 38f150746..9101f11ce 100644 --- a/src/input_common/helpers/stick_from_buttons.cpp +++ b/src/input_common/helpers/stick_from_buttons.cpp | |||
| @@ -200,6 +200,22 @@ public: | |||
| 200 | TriggerOnChange(status); | 200 | TriggerOnChange(status); |
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | void ForceUpdate() override{ | ||
| 204 | up->ForceUpdate(); | ||
| 205 | down->ForceUpdate(); | ||
| 206 | left->ForceUpdate(); | ||
| 207 | right->ForceUpdate(); | ||
| 208 | modifier->ForceUpdate(); | ||
| 209 | } | ||
| 210 | |||
| 211 | void SoftUpdate() override { | ||
| 212 | Input::CallbackStatus status{ | ||
| 213 | .type = Input::InputType::Stick, | ||
| 214 | .stick_status = GetStatus(), | ||
| 215 | }; | ||
| 216 | TriggerOnChange(status); | ||
| 217 | } | ||
| 218 | |||
| 203 | Input::StickStatus GetStatus() const { | 219 | Input::StickStatus GetStatus() const { |
| 204 | Input::StickStatus status{}; | 220 | Input::StickStatus status{}; |
| 205 | status.x.properties = properties; | 221 | status.x.properties = properties; |
diff --git a/src/input_common/helpers/touch_from_buttons.cpp b/src/input_common/helpers/touch_from_buttons.cpp index 2abfaf841..bb2bad5b1 100644 --- a/src/input_common/helpers/touch_from_buttons.cpp +++ b/src/input_common/helpers/touch_from_buttons.cpp | |||
| @@ -17,6 +17,7 @@ public: | |||
| 17 | Input::InputCallback button_up_callback{ | 17 | Input::InputCallback button_up_callback{ |
| 18 | [this](Input::CallbackStatus callback_) { UpdateButtonStatus(callback_); }}; | 18 | [this](Input::CallbackStatus callback_) { UpdateButtonStatus(callback_); }}; |
| 19 | button->SetCallback(button_up_callback); | 19 | button->SetCallback(button_up_callback); |
| 20 | button->ForceUpdate(); | ||
| 20 | } | 21 | } |
| 21 | 22 | ||
| 22 | Input::TouchStatus GetStatus(bool pressed) const { | 23 | Input::TouchStatus GetStatus(bool pressed) const { |
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index 62ade951c..024bd28ef 100644 --- a/src/input_common/input_poller.cpp +++ b/src/input_common/input_poller.cpp | |||
| @@ -45,6 +45,16 @@ public: | |||
| 45 | }; | 45 | }; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | void ForceUpdate() { | ||
| 49 | const Input::CallbackStatus status{ | ||
| 50 | .type = Input::InputType::Button, | ||
| 51 | .button_status = GetStatus(), | ||
| 52 | }; | ||
| 53 | |||
| 54 | last_button_value = status.button_status.value; | ||
| 55 | TriggerOnChange(status); | ||
| 56 | } | ||
| 57 | |||
| 48 | void OnChange() { | 58 | void OnChange() { |
| 49 | const Input::CallbackStatus status{ | 59 | const Input::CallbackStatus status{ |
| 50 | .type = Input::InputType::Button, | 60 | .type = Input::InputType::Button, |
| @@ -96,6 +106,16 @@ public: | |||
| 96 | }; | 106 | }; |
| 97 | } | 107 | } |
| 98 | 108 | ||
| 109 | void ForceUpdate() { | ||
| 110 | const Input::CallbackStatus status{ | ||
| 111 | .type = Input::InputType::Button, | ||
| 112 | .button_status = GetStatus(), | ||
| 113 | }; | ||
| 114 | |||
| 115 | last_button_value = status.button_status.value; | ||
| 116 | TriggerOnChange(status); | ||
| 117 | } | ||
| 118 | |||
| 99 | void OnChange() { | 119 | void OnChange() { |
| 100 | const Input::CallbackStatus status{ | 120 | const Input::CallbackStatus status{ |
| 101 | .type = Input::InputType::Button, | 121 | .type = Input::InputType::Button, |