summaryrefslogtreecommitdiff
path: root/src/input_common
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common')
-rw-r--r--src/input_common/drivers/joycon.cpp4
-rw-r--r--src/input_common/drivers/mouse.cpp27
-rw-r--r--src/input_common/drivers/virtual_amiibo.h2
-rw-r--r--src/input_common/helpers/joycon_driver.cpp2
-rw-r--r--src/input_common/helpers/joycon_driver.h2
-rw-r--r--src/input_common/helpers/joycon_protocol/joycon_types.h4
-rw-r--r--src/input_common/helpers/joycon_protocol/poller.cpp72
-rw-r--r--src/input_common/helpers/joycon_protocol/poller.h8
-rw-r--r--src/input_common/input_mapping.cpp1
9 files changed, 66 insertions, 56 deletions
diff --git a/src/input_common/drivers/joycon.cpp b/src/input_common/drivers/joycon.cpp
index b4cd39a20..8b57ebe07 100644
--- a/src/input_common/drivers/joycon.cpp
+++ b/src/input_common/drivers/joycon.cpp
@@ -307,8 +307,8 @@ Common::Input::DriverResult Joycons::SetPollingMode(const PadIdentifier& identif
307 switch (polling_mode) { 307 switch (polling_mode) {
308 case Common::Input::PollingMode::Active: 308 case Common::Input::PollingMode::Active:
309 return static_cast<Common::Input::DriverResult>(handle->SetActiveMode()); 309 return static_cast<Common::Input::DriverResult>(handle->SetActiveMode());
310 case Common::Input::PollingMode::Pasive: 310 case Common::Input::PollingMode::Passive:
311 return static_cast<Common::Input::DriverResult>(handle->SetPasiveMode()); 311 return static_cast<Common::Input::DriverResult>(handle->SetPassiveMode());
312 case Common::Input::PollingMode::IR: 312 case Common::Input::PollingMode::IR:
313 return static_cast<Common::Input::DriverResult>(handle->SetIrMode()); 313 return static_cast<Common::Input::DriverResult>(handle->SetIrMode());
314 case Common::Input::PollingMode::NFC: 314 case Common::Input::PollingMode::NFC:
diff --git a/src/input_common/drivers/mouse.cpp b/src/input_common/drivers/mouse.cpp
index 8b7f9aee9..94e92c37d 100644
--- a/src/input_common/drivers/mouse.cpp
+++ b/src/input_common/drivers/mouse.cpp
@@ -3,6 +3,7 @@
3 3
4#include <thread> 4#include <thread>
5#include <fmt/format.h> 5#include <fmt/format.h>
6#include <math.h>
6 7
7#include "common/param_package.h" 8#include "common/param_package.h"
8#include "common/settings.h" 9#include "common/settings.h"
@@ -11,8 +12,9 @@
11 12
12namespace InputCommon { 13namespace InputCommon {
13constexpr int update_time = 10; 14constexpr int update_time = 10;
14constexpr float default_stick_sensitivity = 0.022f; 15constexpr float default_stick_sensitivity = 0.0044f;
15constexpr float default_motion_sensitivity = 0.008f; 16constexpr float default_motion_sensitivity = 0.0003f;
17constexpr float maximum_rotation_speed = 2.0f;
16constexpr int mouse_axis_x = 0; 18constexpr int mouse_axis_x = 0;
17constexpr int mouse_axis_y = 1; 19constexpr int mouse_axis_y = 1;
18constexpr int wheel_axis_x = 2; 20constexpr int wheel_axis_x = 2;
@@ -99,11 +101,13 @@ void Mouse::UpdateMotionInput() {
99 const float sensitivity = 101 const float sensitivity =
100 Settings::values.mouse_panning_sensitivity.GetValue() * default_motion_sensitivity; 102 Settings::values.mouse_panning_sensitivity.GetValue() * default_motion_sensitivity;
101 103
102 // Slow movement by 7% 104 const float rotation_velocity = std::sqrt(last_motion_change.x * last_motion_change.x +
103 if (Settings::values.mouse_panning) { 105 last_motion_change.y * last_motion_change.y);
104 last_motion_change *= 0.93f; 106
105 } else { 107 if (rotation_velocity > maximum_rotation_speed / sensitivity) {
106 last_motion_change.z *= 0.93f; 108 const float multiplier = maximum_rotation_speed / rotation_velocity / sensitivity;
109 last_motion_change.x = last_motion_change.x * multiplier;
110 last_motion_change.y = last_motion_change.y * multiplier;
107 } 111 }
108 112
109 const BasicMotion motion_data{ 113 const BasicMotion motion_data{
@@ -116,6 +120,12 @@ void Mouse::UpdateMotionInput() {
116 .delta_timestamp = update_time * 1000, 120 .delta_timestamp = update_time * 1000,
117 }; 121 };
118 122
123 if (Settings::values.mouse_panning) {
124 last_motion_change.x = 0;
125 last_motion_change.y = 0;
126 }
127 last_motion_change.z = 0;
128
119 SetMotion(motion_identifier, 0, motion_data); 129 SetMotion(motion_identifier, 0, motion_data);
120} 130}
121 131
@@ -125,7 +135,7 @@ void Mouse::Move(int x, int y, int center_x, int center_y) {
125 135
126 auto mouse_change = 136 auto mouse_change =
127 (Common::MakeVec(x, y) - Common::MakeVec(center_x, center_y)).Cast<float>(); 137 (Common::MakeVec(x, y) - Common::MakeVec(center_x, center_y)).Cast<float>();
128 Common::Vec3<float> motion_change{-mouse_change.y, -mouse_change.x, last_motion_change.z}; 138 last_motion_change += {-mouse_change.y, -mouse_change.x, last_motion_change.z};
129 139
130 const auto move_distance = mouse_change.Length(); 140 const auto move_distance = mouse_change.Length();
131 if (move_distance == 0) { 141 if (move_distance == 0) {
@@ -141,7 +151,6 @@ void Mouse::Move(int x, int y, int center_x, int center_y) {
141 151
142 // Average mouse movements 152 // Average mouse movements
143 last_mouse_change = (last_mouse_change * 0.91f) + (mouse_change * 0.09f); 153 last_mouse_change = (last_mouse_change * 0.91f) + (mouse_change * 0.09f);
144 last_motion_change = (last_motion_change * 0.69f) + (motion_change * 0.31f);
145 154
146 const auto last_move_distance = last_mouse_change.Length(); 155 const auto last_move_distance = last_mouse_change.Length();
147 156
diff --git a/src/input_common/drivers/virtual_amiibo.h b/src/input_common/drivers/virtual_amiibo.h
index 13cacfc0a..488d00b31 100644
--- a/src/input_common/drivers/virtual_amiibo.h
+++ b/src/input_common/drivers/virtual_amiibo.h
@@ -60,6 +60,6 @@ private:
60 std::string file_path{}; 60 std::string file_path{};
61 State state{State::Initialized}; 61 State state{State::Initialized};
62 std::vector<u8> nfc_data; 62 std::vector<u8> nfc_data;
63 Common::Input::PollingMode polling_mode{Common::Input::PollingMode::Pasive}; 63 Common::Input::PollingMode polling_mode{Common::Input::PollingMode::Passive};
64}; 64};
65} // namespace InputCommon 65} // namespace InputCommon
diff --git a/src/input_common/helpers/joycon_driver.cpp b/src/input_common/helpers/joycon_driver.cpp
index e65b6b845..78cc5893c 100644
--- a/src/input_common/helpers/joycon_driver.cpp
+++ b/src/input_common/helpers/joycon_driver.cpp
@@ -410,7 +410,7 @@ DriverResult JoyconDriver::SetIrsConfig(IrsMode mode_, IrsResolution format_) {
410 return result; 410 return result;
411} 411}
412 412
413DriverResult JoyconDriver::SetPasiveMode() { 413DriverResult JoyconDriver::SetPassiveMode() {
414 std::scoped_lock lock{mutex}; 414 std::scoped_lock lock{mutex};
415 motion_enabled = false; 415 motion_enabled = false;
416 hidbus_enabled = false; 416 hidbus_enabled = false;
diff --git a/src/input_common/helpers/joycon_driver.h b/src/input_common/helpers/joycon_driver.h
index c1e189fa5..b52a13ecf 100644
--- a/src/input_common/helpers/joycon_driver.h
+++ b/src/input_common/helpers/joycon_driver.h
@@ -44,7 +44,7 @@ public:
44 DriverResult SetVibration(const VibrationValue& vibration); 44 DriverResult SetVibration(const VibrationValue& vibration);
45 DriverResult SetLedConfig(u8 led_pattern); 45 DriverResult SetLedConfig(u8 led_pattern);
46 DriverResult SetIrsConfig(IrsMode mode_, IrsResolution format_); 46 DriverResult SetIrsConfig(IrsMode mode_, IrsResolution format_);
47 DriverResult SetPasiveMode(); 47 DriverResult SetPassiveMode();
48 DriverResult SetActiveMode(); 48 DriverResult SetActiveMode();
49 DriverResult SetIrMode(); 49 DriverResult SetIrMode();
50 DriverResult SetNfcMode(); 50 DriverResult SetNfcMode();
diff --git a/src/input_common/helpers/joycon_protocol/joycon_types.h b/src/input_common/helpers/joycon_protocol/joycon_types.h
index 2e50a99a8..dcac0e422 100644
--- a/src/input_common/helpers/joycon_protocol/joycon_types.h
+++ b/src/input_common/helpers/joycon_protocol/joycon_types.h
@@ -78,7 +78,7 @@ enum class PadButton : u32 {
78 Capture = 0x200000, 78 Capture = 0x200000,
79}; 79};
80 80
81enum class PasivePadButton : u32 { 81enum class PassivePadButton : u32 {
82 Down_A = 0x0001, 82 Down_A = 0x0001,
83 Right_X = 0x0002, 83 Right_X = 0x0002,
84 Left_B = 0x0004, 84 Left_B = 0x0004,
@@ -95,7 +95,7 @@ enum class PasivePadButton : u32 {
95 ZL_ZR = 0x8000, 95 ZL_ZR = 0x8000,
96}; 96};
97 97
98enum class PasivePadStick : u8 { 98enum class PassivePadStick : u8 {
99 Right = 0x00, 99 Right = 0x00,
100 RightDown = 0x01, 100 RightDown = 0x01,
101 Down = 0x02, 101 Down = 0x02,
diff --git a/src/input_common/helpers/joycon_protocol/poller.cpp b/src/input_common/helpers/joycon_protocol/poller.cpp
index ab48352b8..dca797f7a 100644
--- a/src/input_common/helpers/joycon_protocol/poller.cpp
+++ b/src/input_common/helpers/joycon_protocol/poller.cpp
@@ -48,13 +48,13 @@ void JoyconPoller::ReadPassiveMode(std::span<u8> buffer) {
48 48
49 switch (device_type) { 49 switch (device_type) {
50 case ControllerType::Left: 50 case ControllerType::Left:
51 UpdatePasiveLeftPadInput(data); 51 UpdatePassiveLeftPadInput(data);
52 break; 52 break;
53 case ControllerType::Right: 53 case ControllerType::Right:
54 UpdatePasiveRightPadInput(data); 54 UpdatePassiveRightPadInput(data);
55 break; 55 break;
56 case ControllerType::Pro: 56 case ControllerType::Pro:
57 UpdatePasiveProPadInput(data); 57 UpdatePassiveProPadInput(data);
58 break; 58 break;
59 default: 59 default:
60 break; 60 break;
@@ -210,12 +210,12 @@ void JoyconPoller::UpdateActiveProPadInput(const InputReportActive& input,
210 } 210 }
211} 211}
212 212
213void JoyconPoller::UpdatePasiveLeftPadInput(const InputReportPassive& input) { 213void JoyconPoller::UpdatePassiveLeftPadInput(const InputReportPassive& input) {
214 static constexpr std::array<PasivePadButton, 11> left_buttons{ 214 static constexpr std::array<PassivePadButton, 11> left_buttons{
215 PasivePadButton::Down_A, PasivePadButton::Right_X, PasivePadButton::Left_B, 215 PassivePadButton::Down_A, PassivePadButton::Right_X, PassivePadButton::Left_B,
216 PasivePadButton::Up_Y, PasivePadButton::SL, PasivePadButton::SR, 216 PassivePadButton::Up_Y, PassivePadButton::SL, PassivePadButton::SR,
217 PasivePadButton::L_R, PasivePadButton::ZL_ZR, PasivePadButton::Minus, 217 PassivePadButton::L_R, PassivePadButton::ZL_ZR, PassivePadButton::Minus,
218 PasivePadButton::Capture, PasivePadButton::StickL, 218 PassivePadButton::Capture, PassivePadButton::StickL,
219 }; 219 };
220 220
221 for (auto left_button : left_buttons) { 221 for (auto left_button : left_buttons) {
@@ -225,17 +225,17 @@ void JoyconPoller::UpdatePasiveLeftPadInput(const InputReportPassive& input) {
225 } 225 }
226 226
227 const auto [left_axis_x, left_axis_y] = 227 const auto [left_axis_x, left_axis_y] =
228 GetPassiveAxisValue(static_cast<PasivePadStick>(input.stick_state)); 228 GetPassiveAxisValue(static_cast<PassivePadStick>(input.stick_state));
229 callbacks.on_stick_data(static_cast<int>(PadAxes::LeftStickX), left_axis_x); 229 callbacks.on_stick_data(static_cast<int>(PadAxes::LeftStickX), left_axis_x);
230 callbacks.on_stick_data(static_cast<int>(PadAxes::LeftStickY), left_axis_y); 230 callbacks.on_stick_data(static_cast<int>(PadAxes::LeftStickY), left_axis_y);
231} 231}
232 232
233void JoyconPoller::UpdatePasiveRightPadInput(const InputReportPassive& input) { 233void JoyconPoller::UpdatePassiveRightPadInput(const InputReportPassive& input) {
234 static constexpr std::array<PasivePadButton, 11> right_buttons{ 234 static constexpr std::array<PassivePadButton, 11> right_buttons{
235 PasivePadButton::Down_A, PasivePadButton::Right_X, PasivePadButton::Left_B, 235 PassivePadButton::Down_A, PassivePadButton::Right_X, PassivePadButton::Left_B,
236 PasivePadButton::Up_Y, PasivePadButton::SL, PasivePadButton::SR, 236 PassivePadButton::Up_Y, PassivePadButton::SL, PassivePadButton::SR,
237 PasivePadButton::L_R, PasivePadButton::ZL_ZR, PasivePadButton::Plus, 237 PassivePadButton::L_R, PassivePadButton::ZL_ZR, PassivePadButton::Plus,
238 PasivePadButton::Home, PasivePadButton::StickR, 238 PassivePadButton::Home, PassivePadButton::StickR,
239 }; 239 };
240 240
241 for (auto right_button : right_buttons) { 241 for (auto right_button : right_buttons) {
@@ -245,18 +245,18 @@ void JoyconPoller::UpdatePasiveRightPadInput(const InputReportPassive& input) {
245 } 245 }
246 246
247 const auto [right_axis_x, right_axis_y] = 247 const auto [right_axis_x, right_axis_y] =
248 GetPassiveAxisValue(static_cast<PasivePadStick>(input.stick_state)); 248 GetPassiveAxisValue(static_cast<PassivePadStick>(input.stick_state));
249 callbacks.on_stick_data(static_cast<int>(PadAxes::RightStickX), right_axis_x); 249 callbacks.on_stick_data(static_cast<int>(PadAxes::RightStickX), right_axis_x);
250 callbacks.on_stick_data(static_cast<int>(PadAxes::RightStickY), right_axis_y); 250 callbacks.on_stick_data(static_cast<int>(PadAxes::RightStickY), right_axis_y);
251} 251}
252 252
253void JoyconPoller::UpdatePasiveProPadInput(const InputReportPassive& input) { 253void JoyconPoller::UpdatePassiveProPadInput(const InputReportPassive& input) {
254 static constexpr std::array<PasivePadButton, 14> pro_buttons{ 254 static constexpr std::array<PassivePadButton, 14> pro_buttons{
255 PasivePadButton::Down_A, PasivePadButton::Right_X, PasivePadButton::Left_B, 255 PassivePadButton::Down_A, PassivePadButton::Right_X, PassivePadButton::Left_B,
256 PasivePadButton::Up_Y, PasivePadButton::SL, PasivePadButton::SR, 256 PassivePadButton::Up_Y, PassivePadButton::SL, PassivePadButton::SR,
257 PasivePadButton::L_R, PasivePadButton::ZL_ZR, PasivePadButton::Minus, 257 PassivePadButton::L_R, PassivePadButton::ZL_ZR, PassivePadButton::Minus,
258 PasivePadButton::Plus, PasivePadButton::Capture, PasivePadButton::Home, 258 PassivePadButton::Plus, PassivePadButton::Capture, PassivePadButton::Home,
259 PasivePadButton::StickL, PasivePadButton::StickR, 259 PassivePadButton::StickL, PassivePadButton::StickR,
260 }; 260 };
261 261
262 for (auto pro_button : pro_buttons) { 262 for (auto pro_button : pro_buttons) {
@@ -266,9 +266,9 @@ void JoyconPoller::UpdatePasiveProPadInput(const InputReportPassive& input) {
266 } 266 }
267 267
268 const auto [left_axis_x, left_axis_y] = 268 const auto [left_axis_x, left_axis_y] =
269 GetPassiveAxisValue(static_cast<PasivePadStick>(input.stick_state && 0xf)); 269 GetPassiveAxisValue(static_cast<PassivePadStick>(input.stick_state & 0xf));
270 const auto [right_axis_x, right_axis_y] = 270 const auto [right_axis_x, right_axis_y] =
271 GetPassiveAxisValue(static_cast<PasivePadStick>(input.stick_state >> 4)); 271 GetPassiveAxisValue(static_cast<PassivePadStick>(input.stick_state >> 4));
272 callbacks.on_stick_data(static_cast<int>(PadAxes::LeftStickX), left_axis_x); 272 callbacks.on_stick_data(static_cast<int>(PadAxes::LeftStickX), left_axis_x);
273 callbacks.on_stick_data(static_cast<int>(PadAxes::LeftStickY), left_axis_y); 273 callbacks.on_stick_data(static_cast<int>(PadAxes::LeftStickY), left_axis_y);
274 callbacks.on_stick_data(static_cast<int>(PadAxes::RightStickX), right_axis_x); 274 callbacks.on_stick_data(static_cast<int>(PadAxes::RightStickX), right_axis_x);
@@ -283,25 +283,25 @@ f32 JoyconPoller::GetAxisValue(u16 raw_value, Joycon::JoyStickAxisCalibration ca
283 return value / calibration.min; 283 return value / calibration.min;
284} 284}
285 285
286std::pair<f32, f32> JoyconPoller::GetPassiveAxisValue(PasivePadStick raw_value) const { 286std::pair<f32, f32> JoyconPoller::GetPassiveAxisValue(PassivePadStick raw_value) const {
287 switch (raw_value) { 287 switch (raw_value) {
288 case PasivePadStick::Right: 288 case PassivePadStick::Right:
289 return {1.0f, 0.0f}; 289 return {1.0f, 0.0f};
290 case PasivePadStick::RightDown: 290 case PassivePadStick::RightDown:
291 return {1.0f, -1.0f}; 291 return {1.0f, -1.0f};
292 case PasivePadStick::Down: 292 case PassivePadStick::Down:
293 return {0.0f, -1.0f}; 293 return {0.0f, -1.0f};
294 case PasivePadStick::DownLeft: 294 case PassivePadStick::DownLeft:
295 return {-1.0f, -1.0f}; 295 return {-1.0f, -1.0f};
296 case PasivePadStick::Left: 296 case PassivePadStick::Left:
297 return {-1.0f, 0.0f}; 297 return {-1.0f, 0.0f};
298 case PasivePadStick::LeftUp: 298 case PassivePadStick::LeftUp:
299 return {-1.0f, 1.0f}; 299 return {-1.0f, 1.0f};
300 case PasivePadStick::Up: 300 case PassivePadStick::Up:
301 return {0.0f, 1.0f}; 301 return {0.0f, 1.0f};
302 case PasivePadStick::UpRight: 302 case PassivePadStick::UpRight:
303 return {1.0f, 1.0f}; 303 return {1.0f, 1.0f};
304 case PasivePadStick::Neutral: 304 case PassivePadStick::Neutral:
305 default: 305 default:
306 return {0.0f, 0.0f}; 306 return {0.0f, 0.0f};
307 } 307 }
diff --git a/src/input_common/helpers/joycon_protocol/poller.h b/src/input_common/helpers/joycon_protocol/poller.h
index 5c897f070..0fa72c6db 100644
--- a/src/input_common/helpers/joycon_protocol/poller.h
+++ b/src/input_common/helpers/joycon_protocol/poller.h
@@ -46,15 +46,15 @@ private:
46 const MotionStatus& motion_status); 46 const MotionStatus& motion_status);
47 void UpdateActiveProPadInput(const InputReportActive& input, const MotionStatus& motion_status); 47 void UpdateActiveProPadInput(const InputReportActive& input, const MotionStatus& motion_status);
48 48
49 void UpdatePasiveLeftPadInput(const InputReportPassive& buffer); 49 void UpdatePassiveLeftPadInput(const InputReportPassive& buffer);
50 void UpdatePasiveRightPadInput(const InputReportPassive& buffer); 50 void UpdatePassiveRightPadInput(const InputReportPassive& buffer);
51 void UpdatePasiveProPadInput(const InputReportPassive& buffer); 51 void UpdatePassiveProPadInput(const InputReportPassive& buffer);
52 52
53 /// Returns a calibrated joystick axis from raw axis data 53 /// Returns a calibrated joystick axis from raw axis data
54 f32 GetAxisValue(u16 raw_value, JoyStickAxisCalibration calibration) const; 54 f32 GetAxisValue(u16 raw_value, JoyStickAxisCalibration calibration) const;
55 55
56 /// Returns a digital joystick axis from passive axis data 56 /// Returns a digital joystick axis from passive axis data
57 std::pair<f32, f32> GetPassiveAxisValue(PasivePadStick raw_value) const; 57 std::pair<f32, f32> GetPassiveAxisValue(PassivePadStick raw_value) const;
58 58
59 /// Returns a calibrated accelerometer axis from raw motion data 59 /// Returns a calibrated accelerometer axis from raw motion data
60 f32 GetAccelerometerValue(s16 raw, const MotionSensorCalibration& cal, 60 f32 GetAccelerometerValue(s16 raw, const MotionSensorCalibration& cal,
diff --git a/src/input_common/input_mapping.cpp b/src/input_common/input_mapping.cpp
index 2ff480ff9..9361b00c5 100644
--- a/src/input_common/input_mapping.cpp
+++ b/src/input_common/input_mapping.cpp
@@ -146,6 +146,7 @@ void MappingFactory::RegisterMotion(const MappingData& data) {
146 if (data.engine == "mouse") { 146 if (data.engine == "mouse") {
147 new_input.Set("motion", 0); 147 new_input.Set("motion", 0);
148 new_input.Set("pad", 1); 148 new_input.Set("pad", 1);
149 new_input.Set("threshold", 0.001f);
149 input_queue.Push(new_input); 150 input_queue.Push(new_input);
150 return; 151 return;
151 } 152 }