diff options
Diffstat (limited to 'src/input_common')
| -rw-r--r-- | src/input_common/drivers/gc_adapter.cpp | 2 | ||||
| -rw-r--r-- | src/input_common/drivers/keyboard.cpp | 6 | ||||
| -rw-r--r-- | src/input_common/drivers/mouse.cpp | 2 | ||||
| -rw-r--r-- | src/input_common/drivers/sdl_driver.cpp | 28 | ||||
| -rw-r--r-- | src/input_common/drivers/touch_screen.cpp | 2 | ||||
| -rw-r--r-- | src/input_common/drivers/udp_client.cpp | 18 | ||||
| -rw-r--r-- | src/input_common/drivers/udp_client.h | 4 | ||||
| -rw-r--r-- | src/input_common/helpers/stick_from_buttons.cpp | 30 | ||||
| -rw-r--r-- | src/input_common/helpers/touch_from_buttons.cpp | 1 | ||||
| -rw-r--r-- | src/input_common/input_engine.cpp | 18 | ||||
| -rw-r--r-- | src/input_common/input_engine.h | 22 | ||||
| -rw-r--r-- | src/input_common/input_mapping.cpp | 6 | ||||
| -rw-r--r-- | src/input_common/input_poller.cpp | 4 |
13 files changed, 78 insertions, 65 deletions
diff --git a/src/input_common/drivers/gc_adapter.cpp b/src/input_common/drivers/gc_adapter.cpp index 7ab4540a8..155caae42 100644 --- a/src/input_common/drivers/gc_adapter.cpp +++ b/src/input_common/drivers/gc_adapter.cpp | |||
| @@ -248,7 +248,7 @@ bool GCAdapter::Setup() { | |||
| 248 | std::size_t port = 0; | 248 | std::size_t port = 0; |
| 249 | for (GCController& pad : pads) { | 249 | for (GCController& pad : pads) { |
| 250 | pad.identifier = { | 250 | pad.identifier = { |
| 251 | .guid = Common::UUID{Common::INVALID_UUID}, | 251 | .guid = Common::UUID{}, |
| 252 | .port = port++, | 252 | .port = port++, |
| 253 | .pad = 0, | 253 | .pad = 0, |
| 254 | }; | 254 | }; |
diff --git a/src/input_common/drivers/keyboard.cpp b/src/input_common/drivers/keyboard.cpp index 4c1e5bbec..59e3d9cc0 100644 --- a/src/input_common/drivers/keyboard.cpp +++ b/src/input_common/drivers/keyboard.cpp | |||
| @@ -9,17 +9,17 @@ | |||
| 9 | namespace InputCommon { | 9 | namespace InputCommon { |
| 10 | 10 | ||
| 11 | constexpr PadIdentifier key_identifier = { | 11 | constexpr PadIdentifier key_identifier = { |
| 12 | .guid = Common::UUID{Common::INVALID_UUID}, | 12 | .guid = Common::UUID{}, |
| 13 | .port = 0, | 13 | .port = 0, |
| 14 | .pad = 0, | 14 | .pad = 0, |
| 15 | }; | 15 | }; |
| 16 | constexpr PadIdentifier keyboard_key_identifier = { | 16 | constexpr PadIdentifier keyboard_key_identifier = { |
| 17 | .guid = Common::UUID{Common::INVALID_UUID}, | 17 | .guid = Common::UUID{}, |
| 18 | .port = 1, | 18 | .port = 1, |
| 19 | .pad = 0, | 19 | .pad = 0, |
| 20 | }; | 20 | }; |
| 21 | constexpr PadIdentifier keyboard_modifier_identifier = { | 21 | constexpr PadIdentifier keyboard_modifier_identifier = { |
| 22 | .guid = Common::UUID{Common::INVALID_UUID}, | 22 | .guid = Common::UUID{}, |
| 23 | .port = 1, | 23 | .port = 1, |
| 24 | .pad = 1, | 24 | .pad = 1, |
| 25 | }; | 25 | }; |
diff --git a/src/input_common/drivers/mouse.cpp b/src/input_common/drivers/mouse.cpp index d8ae7f0c1..3c9a4e747 100644 --- a/src/input_common/drivers/mouse.cpp +++ b/src/input_common/drivers/mouse.cpp | |||
| @@ -20,7 +20,7 @@ constexpr int motion_wheel_y = 4; | |||
| 20 | constexpr int touch_axis_x = 10; | 20 | constexpr int touch_axis_x = 10; |
| 21 | constexpr int touch_axis_y = 11; | 21 | constexpr int touch_axis_y = 11; |
| 22 | constexpr PadIdentifier identifier = { | 22 | constexpr PadIdentifier identifier = { |
| 23 | .guid = Common::UUID{Common::INVALID_UUID}, | 23 | .guid = Common::UUID{}, |
| 24 | .port = 0, | 24 | .port = 0, |
| 25 | .pad = 0, | 25 | .pad = 0, |
| 26 | }; | 26 | }; |
diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp index 577bf5c31..c17ea305e 100644 --- a/src/input_common/drivers/sdl_driver.cpp +++ b/src/input_common/drivers/sdl_driver.cpp | |||
| @@ -175,23 +175,23 @@ public: | |||
| 175 | return false; | 175 | return false; |
| 176 | } | 176 | } |
| 177 | 177 | ||
| 178 | BatteryLevel GetBatteryLevel() { | 178 | Common::Input::BatteryLevel GetBatteryLevel() { |
| 179 | const auto level = SDL_JoystickCurrentPowerLevel(sdl_joystick.get()); | 179 | const auto level = SDL_JoystickCurrentPowerLevel(sdl_joystick.get()); |
| 180 | switch (level) { | 180 | switch (level) { |
| 181 | case SDL_JOYSTICK_POWER_EMPTY: | 181 | case SDL_JOYSTICK_POWER_EMPTY: |
| 182 | return BatteryLevel::Empty; | 182 | return Common::Input::BatteryLevel::Empty; |
| 183 | case SDL_JOYSTICK_POWER_LOW: | 183 | case SDL_JOYSTICK_POWER_LOW: |
| 184 | return BatteryLevel::Critical; | 184 | return Common::Input::BatteryLevel::Low; |
| 185 | case SDL_JOYSTICK_POWER_MEDIUM: | 185 | case SDL_JOYSTICK_POWER_MEDIUM: |
| 186 | return BatteryLevel::Low; | 186 | return Common::Input::BatteryLevel::Medium; |
| 187 | case SDL_JOYSTICK_POWER_FULL: | 187 | case SDL_JOYSTICK_POWER_FULL: |
| 188 | return BatteryLevel::Medium; | ||
| 189 | case SDL_JOYSTICK_POWER_MAX: | 188 | case SDL_JOYSTICK_POWER_MAX: |
| 190 | return BatteryLevel::Full; | 189 | return Common::Input::BatteryLevel::Full; |
| 191 | case SDL_JOYSTICK_POWER_UNKNOWN: | ||
| 192 | case SDL_JOYSTICK_POWER_WIRED: | 190 | case SDL_JOYSTICK_POWER_WIRED: |
| 191 | return Common::Input::BatteryLevel::Charging; | ||
| 192 | case SDL_JOYSTICK_POWER_UNKNOWN: | ||
| 193 | default: | 193 | default: |
| 194 | return BatteryLevel::Charging; | 194 | return Common::Input::BatteryLevel::None; |
| 195 | } | 195 | } |
| 196 | } | 196 | } |
| 197 | 197 | ||
| @@ -352,6 +352,8 @@ void SDLDriver::HandleGameControllerEvent(const SDL_Event& event) { | |||
| 352 | if (const auto joystick = GetSDLJoystickBySDLID(event.jbutton.which)) { | 352 | if (const auto joystick = GetSDLJoystickBySDLID(event.jbutton.which)) { |
| 353 | const PadIdentifier identifier = joystick->GetPadIdentifier(); | 353 | const PadIdentifier identifier = joystick->GetPadIdentifier(); |
| 354 | SetButton(identifier, event.jbutton.button, true); | 354 | SetButton(identifier, event.jbutton.button, true); |
| 355 | // Battery doesn't trigger an event so just update every button press | ||
| 356 | SetBattery(identifier, joystick->GetBatteryLevel()); | ||
| 355 | } | 357 | } |
| 356 | break; | 358 | break; |
| 357 | } | 359 | } |
| @@ -503,7 +505,7 @@ std::vector<Common::ParamPackage> SDLDriver::GetInputDevices() const { | |||
| 503 | Common::Input::VibrationError SDLDriver::SetRumble( | 505 | Common::Input::VibrationError SDLDriver::SetRumble( |
| 504 | const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) { | 506 | const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) { |
| 505 | const auto joystick = | 507 | const auto joystick = |
| 506 | GetSDLJoystickByGUID(identifier.guid.Format(), static_cast<int>(identifier.port)); | 508 | GetSDLJoystickByGUID(identifier.guid.RawString(), static_cast<int>(identifier.port)); |
| 507 | const auto process_amplitude_exp = [](f32 amplitude, f32 factor) { | 509 | const auto process_amplitude_exp = [](f32 amplitude, f32 factor) { |
| 508 | return (amplitude + std::pow(amplitude, factor)) * 0.5f * 0xFFFF; | 510 | return (amplitude + std::pow(amplitude, factor)) * 0.5f * 0xFFFF; |
| 509 | }; | 511 | }; |
| @@ -600,7 +602,7 @@ Common::ParamPackage SDLDriver::BuildParamPackageForAnalog(PadIdentifier identif | |||
| 600 | Common::ParamPackage params; | 602 | Common::ParamPackage params; |
| 601 | params.Set("engine", GetEngineName()); | 603 | params.Set("engine", GetEngineName()); |
| 602 | params.Set("port", static_cast<int>(identifier.port)); | 604 | params.Set("port", static_cast<int>(identifier.port)); |
| 603 | params.Set("guid", identifier.guid.Format()); | 605 | params.Set("guid", identifier.guid.RawString()); |
| 604 | params.Set("axis_x", axis_x); | 606 | params.Set("axis_x", axis_x); |
| 605 | params.Set("axis_y", axis_y); | 607 | params.Set("axis_y", axis_y); |
| 606 | params.Set("offset_x", offset_x); | 608 | params.Set("offset_x", offset_x); |
| @@ -812,7 +814,7 @@ AnalogMapping SDLDriver::GetAnalogMappingForDevice(const Common::ParamPackage& p | |||
| 812 | PreSetAxis(identifier, binding_left_x.value.axis); | 814 | PreSetAxis(identifier, binding_left_x.value.axis); |
| 813 | PreSetAxis(identifier, binding_left_y.value.axis); | 815 | PreSetAxis(identifier, binding_left_y.value.axis); |
| 814 | const auto left_offset_x = -GetAxis(identifier, binding_left_x.value.axis); | 816 | const auto left_offset_x = -GetAxis(identifier, binding_left_x.value.axis); |
| 815 | const auto left_offset_y = -GetAxis(identifier, binding_left_y.value.axis); | 817 | const auto left_offset_y = GetAxis(identifier, binding_left_y.value.axis); |
| 816 | mapping.insert_or_assign(Settings::NativeAnalog::LStick, | 818 | mapping.insert_or_assign(Settings::NativeAnalog::LStick, |
| 817 | BuildParamPackageForAnalog(identifier, binding_left_x.value.axis, | 819 | BuildParamPackageForAnalog(identifier, binding_left_x.value.axis, |
| 818 | binding_left_y.value.axis, | 820 | binding_left_y.value.axis, |
| @@ -823,7 +825,7 @@ AnalogMapping SDLDriver::GetAnalogMappingForDevice(const Common::ParamPackage& p | |||
| 823 | PreSetAxis(identifier, binding_left_x.value.axis); | 825 | PreSetAxis(identifier, binding_left_x.value.axis); |
| 824 | PreSetAxis(identifier, binding_left_y.value.axis); | 826 | PreSetAxis(identifier, binding_left_y.value.axis); |
| 825 | const auto left_offset_x = -GetAxis(identifier, binding_left_x.value.axis); | 827 | const auto left_offset_x = -GetAxis(identifier, binding_left_x.value.axis); |
| 826 | const auto left_offset_y = -GetAxis(identifier, binding_left_y.value.axis); | 828 | const auto left_offset_y = GetAxis(identifier, binding_left_y.value.axis); |
| 827 | mapping.insert_or_assign(Settings::NativeAnalog::LStick, | 829 | mapping.insert_or_assign(Settings::NativeAnalog::LStick, |
| 828 | BuildParamPackageForAnalog(identifier, binding_left_x.value.axis, | 830 | BuildParamPackageForAnalog(identifier, binding_left_x.value.axis, |
| 829 | binding_left_y.value.axis, | 831 | binding_left_y.value.axis, |
| @@ -838,7 +840,7 @@ AnalogMapping SDLDriver::GetAnalogMappingForDevice(const Common::ParamPackage& p | |||
| 838 | PreSetAxis(identifier, binding_right_x.value.axis); | 840 | PreSetAxis(identifier, binding_right_x.value.axis); |
| 839 | PreSetAxis(identifier, binding_right_y.value.axis); | 841 | PreSetAxis(identifier, binding_right_y.value.axis); |
| 840 | const auto right_offset_x = -GetAxis(identifier, binding_right_x.value.axis); | 842 | const auto right_offset_x = -GetAxis(identifier, binding_right_x.value.axis); |
| 841 | const auto right_offset_y = -GetAxis(identifier, binding_right_y.value.axis); | 843 | const auto right_offset_y = GetAxis(identifier, binding_right_y.value.axis); |
| 842 | mapping.insert_or_assign(Settings::NativeAnalog::RStick, | 844 | mapping.insert_or_assign(Settings::NativeAnalog::RStick, |
| 843 | BuildParamPackageForAnalog(identifier, binding_right_x.value.axis, | 845 | BuildParamPackageForAnalog(identifier, binding_right_x.value.axis, |
| 844 | binding_right_y.value.axis, right_offset_x, | 846 | binding_right_y.value.axis, right_offset_x, |
diff --git a/src/input_common/drivers/touch_screen.cpp b/src/input_common/drivers/touch_screen.cpp index 880781825..30c727df4 100644 --- a/src/input_common/drivers/touch_screen.cpp +++ b/src/input_common/drivers/touch_screen.cpp | |||
| @@ -8,7 +8,7 @@ | |||
| 8 | namespace InputCommon { | 8 | namespace InputCommon { |
| 9 | 9 | ||
| 10 | constexpr PadIdentifier identifier = { | 10 | constexpr PadIdentifier identifier = { |
| 11 | .guid = Common::UUID{Common::INVALID_UUID}, | 11 | .guid = Common::UUID{}, |
| 12 | .port = 0, | 12 | .port = 0, |
| 13 | .pad = 0, | 13 | .pad = 0, |
| 14 | }; | 14 | }; |
diff --git a/src/input_common/drivers/udp_client.cpp b/src/input_common/drivers/udp_client.cpp index 333173e3d..9780ead10 100644 --- a/src/input_common/drivers/udp_client.cpp +++ b/src/input_common/drivers/udp_client.cpp | |||
| @@ -192,22 +192,22 @@ std::size_t UDPClient::GetClientNumber(std::string_view host, u16 port) const { | |||
| 192 | return MAX_UDP_CLIENTS; | 192 | return MAX_UDP_CLIENTS; |
| 193 | } | 193 | } |
| 194 | 194 | ||
| 195 | BatteryLevel UDPClient::GetBatteryLevel(Response::Battery battery) const { | 195 | Common::Input::BatteryLevel UDPClient::GetBatteryLevel(Response::Battery battery) const { |
| 196 | switch (battery) { | 196 | switch (battery) { |
| 197 | case Response::Battery::Dying: | 197 | case Response::Battery::Dying: |
| 198 | return BatteryLevel::Empty; | 198 | return Common::Input::BatteryLevel::Empty; |
| 199 | case Response::Battery::Low: | 199 | case Response::Battery::Low: |
| 200 | return BatteryLevel::Critical; | 200 | return Common::Input::BatteryLevel::Critical; |
| 201 | case Response::Battery::Medium: | 201 | case Response::Battery::Medium: |
| 202 | return BatteryLevel::Low; | 202 | return Common::Input::BatteryLevel::Low; |
| 203 | case Response::Battery::High: | 203 | case Response::Battery::High: |
| 204 | return BatteryLevel::Medium; | 204 | return Common::Input::BatteryLevel::Medium; |
| 205 | case Response::Battery::Full: | 205 | case Response::Battery::Full: |
| 206 | case Response::Battery::Charged: | 206 | case Response::Battery::Charged: |
| 207 | return BatteryLevel::Full; | 207 | return Common::Input::BatteryLevel::Full; |
| 208 | case Response::Battery::Charging: | 208 | case Response::Battery::Charging: |
| 209 | default: | 209 | default: |
| 210 | return BatteryLevel::Charging; | 210 | return Common::Input::BatteryLevel::Charging; |
| 211 | } | 211 | } |
| 212 | } | 212 | } |
| 213 | 213 | ||
| @@ -353,7 +353,7 @@ PadIdentifier UDPClient::GetPadIdentifier(std::size_t pad_index) const { | |||
| 353 | 353 | ||
| 354 | Common::UUID UDPClient::GetHostUUID(const std::string& host) const { | 354 | Common::UUID UDPClient::GetHostUUID(const std::string& host) const { |
| 355 | const auto ip = boost::asio::ip::make_address_v4(host); | 355 | const auto ip = boost::asio::ip::make_address_v4(host); |
| 356 | const auto hex_host = fmt::format("{:06x}", ip.to_uint()); | 356 | const auto hex_host = fmt::format("00000000-0000-0000-0000-0000{:06x}", ip.to_uint()); |
| 357 | return Common::UUID{hex_host}; | 357 | return Common::UUID{hex_host}; |
| 358 | } | 358 | } |
| 359 | 359 | ||
| @@ -385,7 +385,7 @@ std::vector<Common::ParamPackage> UDPClient::GetInputDevices() const { | |||
| 385 | Common::ParamPackage identifier{}; | 385 | Common::ParamPackage identifier{}; |
| 386 | identifier.Set("engine", GetEngineName()); | 386 | identifier.Set("engine", GetEngineName()); |
| 387 | identifier.Set("display", fmt::format("UDP Controller {}", pad_identifier.pad)); | 387 | identifier.Set("display", fmt::format("UDP Controller {}", pad_identifier.pad)); |
| 388 | identifier.Set("guid", pad_identifier.guid.Format()); | 388 | identifier.Set("guid", pad_identifier.guid.RawString()); |
| 389 | identifier.Set("port", static_cast<int>(pad_identifier.port)); | 389 | identifier.Set("port", static_cast<int>(pad_identifier.port)); |
| 390 | identifier.Set("pad", static_cast<int>(pad_identifier.pad)); | 390 | identifier.Set("pad", static_cast<int>(pad_identifier.pad)); |
| 391 | devices.emplace_back(identifier); | 391 | devices.emplace_back(identifier); |
diff --git a/src/input_common/drivers/udp_client.h b/src/input_common/drivers/udp_client.h index e9c178139..c7cc7d846 100644 --- a/src/input_common/drivers/udp_client.h +++ b/src/input_common/drivers/udp_client.h | |||
| @@ -126,7 +126,7 @@ private: | |||
| 126 | struct ClientConnection { | 126 | struct ClientConnection { |
| 127 | ClientConnection(); | 127 | ClientConnection(); |
| 128 | ~ClientConnection(); | 128 | ~ClientConnection(); |
| 129 | Common::UUID uuid{"7F000001"}; | 129 | Common::UUID uuid{"00000000-0000-0000-0000-00007F000001"}; |
| 130 | std::string host{"127.0.0.1"}; | 130 | std::string host{"127.0.0.1"}; |
| 131 | u16 port{26760}; | 131 | u16 port{26760}; |
| 132 | s8 active{-1}; | 132 | s8 active{-1}; |
| @@ -141,7 +141,7 @@ private: | |||
| 141 | std::size_t GetClientNumber(std::string_view host, u16 port) const; | 141 | std::size_t GetClientNumber(std::string_view host, u16 port) const; |
| 142 | 142 | ||
| 143 | // Translates UDP battery level to input engine battery level | 143 | // Translates UDP battery level to input engine battery level |
| 144 | BatteryLevel GetBatteryLevel(Response::Battery battery) const; | 144 | Common::Input::BatteryLevel GetBatteryLevel(Response::Battery battery) const; |
| 145 | 145 | ||
| 146 | void OnVersion(Response::Version); | 146 | void OnVersion(Response::Version); |
| 147 | void OnPortInfo(Response::PortInfo); | 147 | void OnPortInfo(Response::PortInfo); |
diff --git a/src/input_common/helpers/stick_from_buttons.cpp b/src/input_common/helpers/stick_from_buttons.cpp index e23394f5f..31e6f62ab 100644 --- a/src/input_common/helpers/stick_from_buttons.cpp +++ b/src/input_common/helpers/stick_from_buttons.cpp | |||
| @@ -167,12 +167,34 @@ public: | |||
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | void UpdateModButtonStatus(const Common::Input::CallbackStatus& button_callback) { | 169 | void UpdateModButtonStatus(const Common::Input::CallbackStatus& button_callback) { |
| 170 | modifier_status = button_callback.button_status.value; | 170 | const auto& new_status = button_callback.button_status; |
| 171 | const bool new_button_value = new_status.inverted ? !new_status.value : new_status.value; | ||
| 172 | modifier_status.toggle = new_status.toggle; | ||
| 173 | |||
| 174 | // Update button status with current | ||
| 175 | if (!modifier_status.toggle) { | ||
| 176 | modifier_status.locked = false; | ||
| 177 | if (modifier_status.value != new_button_value) { | ||
| 178 | modifier_status.value = new_button_value; | ||
| 179 | } | ||
| 180 | } else { | ||
| 181 | // Toggle button and lock status | ||
| 182 | if (new_button_value && !modifier_status.locked) { | ||
| 183 | modifier_status.locked = true; | ||
| 184 | modifier_status.value = !modifier_status.value; | ||
| 185 | } | ||
| 186 | |||
| 187 | // Unlock button ready for next press | ||
| 188 | if (!new_button_value && modifier_status.locked) { | ||
| 189 | modifier_status.locked = false; | ||
| 190 | } | ||
| 191 | } | ||
| 192 | |||
| 171 | UpdateStatus(); | 193 | UpdateStatus(); |
| 172 | } | 194 | } |
| 173 | 195 | ||
| 174 | void UpdateStatus() { | 196 | void UpdateStatus() { |
| 175 | const float coef = modifier_status ? modifier_scale : 1.0f; | 197 | const float coef = modifier_status.value ? modifier_scale : 1.0f; |
| 176 | 198 | ||
| 177 | bool r = right_status; | 199 | bool r = right_status; |
| 178 | bool l = left_status; | 200 | bool l = left_status; |
| @@ -266,7 +288,7 @@ public: | |||
| 266 | if (down_status) { | 288 | if (down_status) { |
| 267 | --y; | 289 | --y; |
| 268 | } | 290 | } |
| 269 | const float coef = modifier_status ? modifier_scale : 1.0f; | 291 | const float coef = modifier_status.value ? modifier_scale : 1.0f; |
| 270 | status.x.raw_value = static_cast<float>(x) * coef * (y == 0 ? 1.0f : SQRT_HALF); | 292 | status.x.raw_value = static_cast<float>(x) * coef * (y == 0 ? 1.0f : SQRT_HALF); |
| 271 | status.y.raw_value = static_cast<float>(y) * coef * (x == 0 ? 1.0f : SQRT_HALF); | 293 | status.y.raw_value = static_cast<float>(y) * coef * (x == 0 ? 1.0f : SQRT_HALF); |
| 272 | return status; | 294 | return status; |
| @@ -287,9 +309,9 @@ private: | |||
| 287 | bool down_status{}; | 309 | bool down_status{}; |
| 288 | bool left_status{}; | 310 | bool left_status{}; |
| 289 | bool right_status{}; | 311 | bool right_status{}; |
| 290 | bool modifier_status{}; | ||
| 291 | float last_x_axis_value{}; | 312 | float last_x_axis_value{}; |
| 292 | float last_y_axis_value{}; | 313 | float last_y_axis_value{}; |
| 314 | Common::Input::ButtonStatus modifier_status{}; | ||
| 293 | const Common::Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false}; | 315 | const Common::Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false}; |
| 294 | std::chrono::time_point<std::chrono::steady_clock> last_update; | 316 | std::chrono::time_point<std::chrono::steady_clock> last_update; |
| 295 | }; | 317 | }; |
diff --git a/src/input_common/helpers/touch_from_buttons.cpp b/src/input_common/helpers/touch_from_buttons.cpp index ece1e3b32..f1b57d03a 100644 --- a/src/input_common/helpers/touch_from_buttons.cpp +++ b/src/input_common/helpers/touch_from_buttons.cpp | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include "common/settings.h" | 6 | #include "common/settings.h" |
| 7 | #include "core/frontend/framebuffer_layout.h" | ||
| 8 | #include "input_common/helpers/touch_from_buttons.h" | 7 | #include "input_common/helpers/touch_from_buttons.h" |
| 9 | 8 | ||
| 10 | namespace InputCommon { | 9 | namespace InputCommon { |
diff --git a/src/input_common/input_engine.cpp b/src/input_common/input_engine.cpp index 0508b408d..7adf7e3d7 100644 --- a/src/input_common/input_engine.cpp +++ b/src/input_common/input_engine.cpp | |||
| @@ -70,7 +70,7 @@ void InputEngine::SetAxis(const PadIdentifier& identifier, int axis, f32 value) | |||
| 70 | TriggerOnAxisChange(identifier, axis, value); | 70 | TriggerOnAxisChange(identifier, axis, value); |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | void InputEngine::SetBattery(const PadIdentifier& identifier, BatteryLevel value) { | 73 | void InputEngine::SetBattery(const PadIdentifier& identifier, Common::Input::BatteryLevel value) { |
| 74 | { | 74 | { |
| 75 | std::lock_guard lock{mutex}; | 75 | std::lock_guard lock{mutex}; |
| 76 | ControllerData& controller = controller_list.at(identifier); | 76 | ControllerData& controller = controller_list.at(identifier); |
| @@ -96,7 +96,7 @@ bool InputEngine::GetButton(const PadIdentifier& identifier, int button) const { | |||
| 96 | std::lock_guard lock{mutex}; | 96 | std::lock_guard lock{mutex}; |
| 97 | const auto controller_iter = controller_list.find(identifier); | 97 | const auto controller_iter = controller_list.find(identifier); |
| 98 | if (controller_iter == controller_list.cend()) { | 98 | if (controller_iter == controller_list.cend()) { |
| 99 | LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), | 99 | LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(), |
| 100 | identifier.pad, identifier.port); | 100 | identifier.pad, identifier.port); |
| 101 | return false; | 101 | return false; |
| 102 | } | 102 | } |
| @@ -113,7 +113,7 @@ bool InputEngine::GetHatButton(const PadIdentifier& identifier, int button, u8 d | |||
| 113 | std::lock_guard lock{mutex}; | 113 | std::lock_guard lock{mutex}; |
| 114 | const auto controller_iter = controller_list.find(identifier); | 114 | const auto controller_iter = controller_list.find(identifier); |
| 115 | if (controller_iter == controller_list.cend()) { | 115 | if (controller_iter == controller_list.cend()) { |
| 116 | LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), | 116 | LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(), |
| 117 | identifier.pad, identifier.port); | 117 | identifier.pad, identifier.port); |
| 118 | return false; | 118 | return false; |
| 119 | } | 119 | } |
| @@ -130,7 +130,7 @@ f32 InputEngine::GetAxis(const PadIdentifier& identifier, int axis) const { | |||
| 130 | std::lock_guard lock{mutex}; | 130 | std::lock_guard lock{mutex}; |
| 131 | const auto controller_iter = controller_list.find(identifier); | 131 | const auto controller_iter = controller_list.find(identifier); |
| 132 | if (controller_iter == controller_list.cend()) { | 132 | if (controller_iter == controller_list.cend()) { |
| 133 | LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), | 133 | LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(), |
| 134 | identifier.pad, identifier.port); | 134 | identifier.pad, identifier.port); |
| 135 | return 0.0f; | 135 | return 0.0f; |
| 136 | } | 136 | } |
| @@ -143,13 +143,13 @@ f32 InputEngine::GetAxis(const PadIdentifier& identifier, int axis) const { | |||
| 143 | return axis_iter->second; | 143 | return axis_iter->second; |
| 144 | } | 144 | } |
| 145 | 145 | ||
| 146 | BatteryLevel InputEngine::GetBattery(const PadIdentifier& identifier) const { | 146 | Common::Input::BatteryLevel InputEngine::GetBattery(const PadIdentifier& identifier) const { |
| 147 | std::lock_guard lock{mutex}; | 147 | std::lock_guard lock{mutex}; |
| 148 | const auto controller_iter = controller_list.find(identifier); | 148 | const auto controller_iter = controller_list.find(identifier); |
| 149 | if (controller_iter == controller_list.cend()) { | 149 | if (controller_iter == controller_list.cend()) { |
| 150 | LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), | 150 | LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(), |
| 151 | identifier.pad, identifier.port); | 151 | identifier.pad, identifier.port); |
| 152 | return BatteryLevel::Charging; | 152 | return Common::Input::BatteryLevel::Charging; |
| 153 | } | 153 | } |
| 154 | const ControllerData& controller = controller_iter->second; | 154 | const ControllerData& controller = controller_iter->second; |
| 155 | return controller.battery; | 155 | return controller.battery; |
| @@ -159,7 +159,7 @@ BasicMotion InputEngine::GetMotion(const PadIdentifier& identifier, int motion) | |||
| 159 | std::lock_guard lock{mutex}; | 159 | std::lock_guard lock{mutex}; |
| 160 | const auto controller_iter = controller_list.find(identifier); | 160 | const auto controller_iter = controller_list.find(identifier); |
| 161 | if (controller_iter == controller_list.cend()) { | 161 | if (controller_iter == controller_list.cend()) { |
| 162 | LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), | 162 | LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(), |
| 163 | identifier.pad, identifier.port); | 163 | identifier.pad, identifier.port); |
| 164 | return {}; | 164 | return {}; |
| 165 | } | 165 | } |
| @@ -270,7 +270,7 @@ void InputEngine::TriggerOnAxisChange(const PadIdentifier& identifier, int axis, | |||
| 270 | } | 270 | } |
| 271 | 271 | ||
| 272 | void InputEngine::TriggerOnBatteryChange(const PadIdentifier& identifier, | 272 | void InputEngine::TriggerOnBatteryChange(const PadIdentifier& identifier, |
| 273 | [[maybe_unused]] BatteryLevel value) { | 273 | [[maybe_unused]] Common::Input::BatteryLevel value) { |
| 274 | std::lock_guard lock{mutex_callback}; | 274 | std::lock_guard lock{mutex_callback}; |
| 275 | for (const auto& poller_pair : callback_list) { | 275 | for (const auto& poller_pair : callback_list) { |
| 276 | const InputIdentifier& poller = poller_pair.second; | 276 | const InputIdentifier& poller = poller_pair.second; |
diff --git a/src/input_common/input_engine.h b/src/input_common/input_engine.h index fe2faee5a..f44e0799b 100644 --- a/src/input_common/input_engine.h +++ b/src/input_common/input_engine.h | |||
| @@ -16,7 +16,7 @@ | |||
| 16 | 16 | ||
| 17 | // Pad Identifier of data source | 17 | // Pad Identifier of data source |
| 18 | struct PadIdentifier { | 18 | struct PadIdentifier { |
| 19 | Common::UUID guid{Common::INVALID_UUID}; | 19 | Common::UUID guid{}; |
| 20 | std::size_t port{}; | 20 | std::size_t port{}; |
| 21 | std::size_t pad{}; | 21 | std::size_t pad{}; |
| 22 | 22 | ||
| @@ -34,16 +34,6 @@ struct BasicMotion { | |||
| 34 | u64 delta_timestamp{}; | 34 | u64 delta_timestamp{}; |
| 35 | }; | 35 | }; |
| 36 | 36 | ||
| 37 | // Stages of a battery charge | ||
| 38 | enum class BatteryLevel { | ||
| 39 | Empty, | ||
| 40 | Critical, | ||
| 41 | Low, | ||
| 42 | Medium, | ||
| 43 | Full, | ||
| 44 | Charging, | ||
| 45 | }; | ||
| 46 | |||
| 47 | // Types of input that are stored in the engine | 37 | // Types of input that are stored in the engine |
| 48 | enum class EngineInputType { | 38 | enum class EngineInputType { |
| 49 | None, | 39 | None, |
| @@ -59,7 +49,7 @@ namespace std { | |||
| 59 | template <> | 49 | template <> |
| 60 | struct hash<PadIdentifier> { | 50 | struct hash<PadIdentifier> { |
| 61 | size_t operator()(const PadIdentifier& pad_id) const noexcept { | 51 | size_t operator()(const PadIdentifier& pad_id) const noexcept { |
| 62 | u64 hash_value = pad_id.guid.uuid[1] ^ pad_id.guid.uuid[0]; | 52 | u64 hash_value = pad_id.guid.Hash(); |
| 63 | hash_value ^= (static_cast<u64>(pad_id.port) << 32); | 53 | hash_value ^= (static_cast<u64>(pad_id.port) << 32); |
| 64 | hash_value ^= static_cast<u64>(pad_id.pad); | 54 | hash_value ^= static_cast<u64>(pad_id.pad); |
| 65 | return static_cast<size_t>(hash_value); | 55 | return static_cast<size_t>(hash_value); |
| @@ -178,7 +168,7 @@ public: | |||
| 178 | bool GetButton(const PadIdentifier& identifier, int button) const; | 168 | bool GetButton(const PadIdentifier& identifier, int button) const; |
| 179 | bool GetHatButton(const PadIdentifier& identifier, int button, u8 direction) const; | 169 | bool GetHatButton(const PadIdentifier& identifier, int button, u8 direction) const; |
| 180 | f32 GetAxis(const PadIdentifier& identifier, int axis) const; | 170 | f32 GetAxis(const PadIdentifier& identifier, int axis) const; |
| 181 | BatteryLevel GetBattery(const PadIdentifier& identifier) const; | 171 | Common::Input::BatteryLevel GetBattery(const PadIdentifier& identifier) const; |
| 182 | BasicMotion GetMotion(const PadIdentifier& identifier, int motion) const; | 172 | BasicMotion GetMotion(const PadIdentifier& identifier, int motion) const; |
| 183 | 173 | ||
| 184 | int SetCallback(InputIdentifier input_identifier); | 174 | int SetCallback(InputIdentifier input_identifier); |
| @@ -189,7 +179,7 @@ protected: | |||
| 189 | void SetButton(const PadIdentifier& identifier, int button, bool value); | 179 | void SetButton(const PadIdentifier& identifier, int button, bool value); |
| 190 | void SetHatButton(const PadIdentifier& identifier, int button, u8 value); | 180 | void SetHatButton(const PadIdentifier& identifier, int button, u8 value); |
| 191 | void SetAxis(const PadIdentifier& identifier, int axis, f32 value); | 181 | void SetAxis(const PadIdentifier& identifier, int axis, f32 value); |
| 192 | void SetBattery(const PadIdentifier& identifier, BatteryLevel value); | 182 | void SetBattery(const PadIdentifier& identifier, Common::Input::BatteryLevel value); |
| 193 | void SetMotion(const PadIdentifier& identifier, int motion, const BasicMotion& value); | 183 | void SetMotion(const PadIdentifier& identifier, int motion, const BasicMotion& value); |
| 194 | 184 | ||
| 195 | virtual std::string GetHatButtonName([[maybe_unused]] u8 direction_value) const { | 185 | virtual std::string GetHatButtonName([[maybe_unused]] u8 direction_value) const { |
| @@ -202,13 +192,13 @@ private: | |||
| 202 | std::unordered_map<int, u8> hat_buttons; | 192 | std::unordered_map<int, u8> hat_buttons; |
| 203 | std::unordered_map<int, float> axes; | 193 | std::unordered_map<int, float> axes; |
| 204 | std::unordered_map<int, BasicMotion> motions; | 194 | std::unordered_map<int, BasicMotion> motions; |
| 205 | BatteryLevel battery{}; | 195 | Common::Input::BatteryLevel battery{}; |
| 206 | }; | 196 | }; |
| 207 | 197 | ||
| 208 | void TriggerOnButtonChange(const PadIdentifier& identifier, int button, bool value); | 198 | void TriggerOnButtonChange(const PadIdentifier& identifier, int button, bool value); |
| 209 | void TriggerOnHatButtonChange(const PadIdentifier& identifier, int button, u8 value); | 199 | void TriggerOnHatButtonChange(const PadIdentifier& identifier, int button, u8 value); |
| 210 | void TriggerOnAxisChange(const PadIdentifier& identifier, int axis, f32 value); | 200 | void TriggerOnAxisChange(const PadIdentifier& identifier, int axis, f32 value); |
| 211 | void TriggerOnBatteryChange(const PadIdentifier& identifier, BatteryLevel value); | 201 | void TriggerOnBatteryChange(const PadIdentifier& identifier, Common::Input::BatteryLevel value); |
| 212 | void TriggerOnMotionChange(const PadIdentifier& identifier, int motion, | 202 | void TriggerOnMotionChange(const PadIdentifier& identifier, int motion, |
| 213 | const BasicMotion& value); | 203 | const BasicMotion& value); |
| 214 | 204 | ||
diff --git a/src/input_common/input_mapping.cpp b/src/input_common/input_mapping.cpp index a7a6ad8c2..fb78093b8 100644 --- a/src/input_common/input_mapping.cpp +++ b/src/input_common/input_mapping.cpp | |||
| @@ -57,7 +57,7 @@ void MappingFactory::RegisterButton(const MappingData& data) { | |||
| 57 | Common::ParamPackage new_input; | 57 | Common::ParamPackage new_input; |
| 58 | new_input.Set("engine", data.engine); | 58 | new_input.Set("engine", data.engine); |
| 59 | if (data.pad.guid.IsValid()) { | 59 | if (data.pad.guid.IsValid()) { |
| 60 | new_input.Set("guid", data.pad.guid.Format()); | 60 | new_input.Set("guid", data.pad.guid.RawString()); |
| 61 | } | 61 | } |
| 62 | new_input.Set("port", static_cast<int>(data.pad.port)); | 62 | new_input.Set("port", static_cast<int>(data.pad.port)); |
| 63 | new_input.Set("pad", static_cast<int>(data.pad.pad)); | 63 | new_input.Set("pad", static_cast<int>(data.pad.pad)); |
| @@ -93,7 +93,7 @@ void MappingFactory::RegisterStick(const MappingData& data) { | |||
| 93 | Common::ParamPackage new_input; | 93 | Common::ParamPackage new_input; |
| 94 | new_input.Set("engine", data.engine); | 94 | new_input.Set("engine", data.engine); |
| 95 | if (data.pad.guid.IsValid()) { | 95 | if (data.pad.guid.IsValid()) { |
| 96 | new_input.Set("guid", data.pad.guid.Format()); | 96 | new_input.Set("guid", data.pad.guid.RawString()); |
| 97 | } | 97 | } |
| 98 | new_input.Set("port", static_cast<int>(data.pad.port)); | 98 | new_input.Set("port", static_cast<int>(data.pad.port)); |
| 99 | new_input.Set("pad", static_cast<int>(data.pad.pad)); | 99 | new_input.Set("pad", static_cast<int>(data.pad.pad)); |
| @@ -138,7 +138,7 @@ void MappingFactory::RegisterMotion(const MappingData& data) { | |||
| 138 | Common::ParamPackage new_input; | 138 | Common::ParamPackage new_input; |
| 139 | new_input.Set("engine", data.engine); | 139 | new_input.Set("engine", data.engine); |
| 140 | if (data.pad.guid.IsValid()) { | 140 | if (data.pad.guid.IsValid()) { |
| 141 | new_input.Set("guid", data.pad.guid.Format()); | 141 | new_input.Set("guid", data.pad.guid.RawString()); |
| 142 | } | 142 | } |
| 143 | new_input.Set("port", static_cast<int>(data.pad.port)); | 143 | new_input.Set("port", static_cast<int>(data.pad.port)); |
| 144 | new_input.Set("pad", static_cast<int>(data.pad.pad)); | 144 | new_input.Set("pad", static_cast<int>(data.pad.pad)); |
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index 2f3c0735a..82b585ff2 100644 --- a/src/input_common/input_poller.cpp +++ b/src/input_common/input_poller.cpp | |||
| @@ -181,7 +181,7 @@ public: | |||
| 181 | .raw_value = input_engine->GetAxis(identifier, axis_y), | 181 | .raw_value = input_engine->GetAxis(identifier, axis_y), |
| 182 | .properties = properties_y, | 182 | .properties = properties_y, |
| 183 | }; | 183 | }; |
| 184 | // This is a workaround too keep compatibility with old yuzu versions. Vertical axis is | 184 | // This is a workaround to keep compatibility with old yuzu versions. Vertical axis is |
| 185 | // inverted on SDL compared to Nintendo | 185 | // inverted on SDL compared to Nintendo |
| 186 | if (invert_axis_y) { | 186 | if (invert_axis_y) { |
| 187 | status.y.raw_value = -status.y.raw_value; | 187 | status.y.raw_value = -status.y.raw_value; |
| @@ -470,7 +470,7 @@ public: | |||
| 470 | } | 470 | } |
| 471 | 471 | ||
| 472 | Common::Input::BatteryStatus GetStatus() const { | 472 | Common::Input::BatteryStatus GetStatus() const { |
| 473 | return static_cast<Common::Input::BatteryLevel>(input_engine->GetBattery(identifier)); | 473 | return input_engine->GetBattery(identifier); |
| 474 | } | 474 | } |
| 475 | 475 | ||
| 476 | void ForceUpdate() override { | 476 | void ForceUpdate() override { |