summaryrefslogtreecommitdiff
path: root/src/input_common
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common')
-rw-r--r--src/input_common/main.cpp4
-rw-r--r--src/input_common/sdl/sdl_impl.cpp25
-rw-r--r--src/input_common/udp/client.cpp74
3 files changed, 57 insertions, 46 deletions
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp
index 18d7d8817..f3907c65a 100644
--- a/src/input_common/main.cpp
+++ b/src/input_common/main.cpp
@@ -346,8 +346,8 @@ void InputSubsystem::ReloadInputDevices() {
346 impl->udp->ReloadSockets(); 346 impl->udp->ReloadSockets();
347} 347}
348 348
349std::vector<std::unique_ptr<Polling::DevicePoller>> InputSubsystem::GetPollers([ 349std::vector<std::unique_ptr<Polling::DevicePoller>> InputSubsystem::GetPollers(
350 [maybe_unused]] Polling::DeviceType type) const { 350 [[maybe_unused]] Polling::DeviceType type) const {
351#ifdef HAVE_SDL2 351#ifdef HAVE_SDL2
352 return impl->sdl->GetPollers(type); 352 return impl->sdl->GetPollers(type);
353#else 353#else
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp
index 03888b7cb..ecb00d428 100644
--- a/src/input_common/sdl/sdl_impl.cpp
+++ b/src/input_common/sdl/sdl_impl.cpp
@@ -170,7 +170,8 @@ public:
170 float GetAxis(int axis, float range, float offset) const { 170 float GetAxis(int axis, float range, float offset) const {
171 std::lock_guard lock{mutex}; 171 std::lock_guard lock{mutex};
172 const float value = static_cast<float>(state.axes.at(axis)) / 32767.0f; 172 const float value = static_cast<float>(state.axes.at(axis)) / 32767.0f;
173 return (value + offset) / range; 173 const float offset_scale = (value + offset) > 0.0f ? 1.0f + offset : 1.0f - offset;
174 return (value + offset) / range / offset_scale;
174 } 175 }
175 176
176 bool RumblePlay(u16 amp_low, u16 amp_high) { 177 bool RumblePlay(u16 amp_low, u16 amp_high) {
@@ -254,11 +255,25 @@ public:
254 } 255 }
255 256
256 bool IsJoyconLeft() const { 257 bool IsJoyconLeft() const {
257 return std::strstr(GetControllerName().c_str(), "Joy-Con Left") != nullptr; 258 const std::string controller_name = GetControllerName();
259 if (std::strstr(controller_name.c_str(), "Joy-Con Left") != nullptr) {
260 return true;
261 }
262 if (std::strstr(controller_name.c_str(), "Joy-Con (L)") != nullptr) {
263 return true;
264 }
265 return false;
258 } 266 }
259 267
260 bool IsJoyconRight() const { 268 bool IsJoyconRight() const {
261 return std::strstr(GetControllerName().c_str(), "Joy-Con Right") != nullptr; 269 const std::string controller_name = GetControllerName();
270 if (std::strstr(controller_name.c_str(), "Joy-Con Right") != nullptr) {
271 return true;
272 }
273 if (std::strstr(controller_name.c_str(), "Joy-Con (R)") != nullptr) {
274 return true;
275 }
276 return false;
262 } 277 }
263 278
264 std::string GetControllerName() const { 279 std::string GetControllerName() const {
@@ -775,8 +790,8 @@ public:
775 const std::string invert_y_value = params.Get("invert_y", "+"); 790 const std::string invert_y_value = params.Get("invert_y", "+");
776 const bool invert_x = invert_x_value == "-"; 791 const bool invert_x = invert_x_value == "-";
777 const bool invert_y = invert_y_value == "-"; 792 const bool invert_y = invert_y_value == "-";
778 const float offset_x = params.Get("offset_x", 0.0f); 793 const float offset_x = std::clamp(params.Get("offset_x", 0.0f), -0.99f, 0.99f);
779 const float offset_y = params.Get("offset_y", 0.0f); 794 const float offset_y = std::clamp(params.Get("offset_y", 0.0f), -0.99f, 0.99f);
780 auto joystick = state.GetSDLJoystickByGUID(guid, port); 795 auto joystick = state.GetSDLJoystickByGUID(guid, port);
781 796
782 // This is necessary so accessing GetAxis with axis_x and axis_y won't crash 797 // This is necessary so accessing GetAxis with axis_x and axis_y won't crash
diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp
index 9b0aec797..b9512aa2e 100644
--- a/src/input_common/udp/client.cpp
+++ b/src/input_common/udp/client.cpp
@@ -471,46 +471,42 @@ CalibrationConfigurationJob::CalibrationConfigurationJob(
471 std::function<void(u16, u16, u16, u16)> data_callback) { 471 std::function<void(u16, u16, u16, u16)> data_callback) {
472 472
473 std::thread([=, this] { 473 std::thread([=, this] {
474 constexpr u16 CALIBRATION_THRESHOLD = 100;
475
476 u16 min_x{UINT16_MAX};
477 u16 min_y{UINT16_MAX};
478 u16 max_x{};
479 u16 max_y{};
480
481 Status current_status{Status::Initialized}; 474 Status current_status{Status::Initialized};
482 SocketCallback callback{[](Response::Version) {}, [](Response::PortInfo) {}, 475 SocketCallback callback{
483 [&](Response::PadData data) { 476 [](Response::Version) {}, [](Response::PortInfo) {},
484 if (current_status == Status::Initialized) { 477 [&](Response::PadData data) {
485 // Receiving data means the communication is ready now 478 static constexpr u16 CALIBRATION_THRESHOLD = 100;
486 current_status = Status::Ready; 479 static constexpr u16 MAX_VALUE = UINT16_MAX;
487 status_callback(current_status); 480
488 } 481 if (current_status == Status::Initialized) {
489 if (data.touch[0].is_active == 0) { 482 // Receiving data means the communication is ready now
490 return; 483 current_status = Status::Ready;
491 } 484 status_callback(current_status);
492 LOG_DEBUG(Input, "Current touch: {} {}", data.touch[0].x, 485 }
493 data.touch[0].y); 486 const auto& touchpad_0 = data.touch[0];
494 min_x = std::min(min_x, static_cast<u16>(data.touch[0].x)); 487 if (touchpad_0.is_active == 0) {
495 min_y = std::min(min_y, static_cast<u16>(data.touch[0].y)); 488 return;
496 if (current_status == Status::Ready) { 489 }
497 // First touch - min data (min_x/min_y) 490 LOG_DEBUG(Input, "Current touch: {} {}", touchpad_0.x, touchpad_0.y);
498 current_status = Status::Stage1Completed; 491 const u16 min_x = std::min(MAX_VALUE, static_cast<u16>(touchpad_0.x));
499 status_callback(current_status); 492 const u16 min_y = std::min(MAX_VALUE, static_cast<u16>(touchpad_0.y));
500 } 493 if (current_status == Status::Ready) {
501 if (data.touch[0].x - min_x > CALIBRATION_THRESHOLD && 494 // First touch - min data (min_x/min_y)
502 data.touch[0].y - min_y > CALIBRATION_THRESHOLD) { 495 current_status = Status::Stage1Completed;
503 // Set the current position as max value and finishes 496 status_callback(current_status);
504 // configuration 497 }
505 max_x = data.touch[0].x; 498 if (touchpad_0.x - min_x > CALIBRATION_THRESHOLD &&
506 max_y = data.touch[0].y; 499 touchpad_0.y - min_y > CALIBRATION_THRESHOLD) {
507 current_status = Status::Completed; 500 // Set the current position as max value and finishes configuration
508 data_callback(min_x, min_y, max_x, max_y); 501 const u16 max_x = touchpad_0.x;
509 status_callback(current_status); 502 const u16 max_y = touchpad_0.y;
510 503 current_status = Status::Completed;
511 complete_event.Set(); 504 data_callback(min_x, min_y, max_x, max_y);
512 } 505 status_callback(current_status);
513 }}; 506
507 complete_event.Set();
508 }
509 }};
514 Socket socket{host, port, std::move(callback)}; 510 Socket socket{host, port, std::move(callback)};
515 std::thread worker_thread{SocketLoop, &socket}; 511 std::thread worker_thread{SocketLoop, &socket};
516 complete_event.Wait(); 512 complete_event.Wait();