summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/settings.h8
-rw-r--r--src/core/constants.cpp27
-rw-r--r--src/core/constants.h2
-rw-r--r--src/input_common/helpers/joycon_protocol/joycon_types.h12
-rw-r--r--src/input_common/helpers/joycon_protocol/poller.cpp95
-rw-r--r--src/input_common/helpers/joycon_protocol/poller.h9
6 files changed, 108 insertions, 45 deletions
diff --git a/src/common/settings.h b/src/common/settings.h
index 512ecff69..1ae28ce93 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -128,7 +128,7 @@ public:
128 /** 128 /**
129 * Sets a default value, label, and setting value. 129 * Sets a default value, label, and setting value.
130 * 130 *
131 * @param default_val Intial value of the setting, and default value of the setting 131 * @param default_val Initial value of the setting, and default value of the setting
132 * @param name Label for the setting 132 * @param name Label for the setting
133 */ 133 */
134 explicit Setting(const Type& default_val, const std::string& name) 134 explicit Setting(const Type& default_val, const std::string& name)
@@ -139,7 +139,7 @@ public:
139 /** 139 /**
140 * Sets a default value, minimum value, maximum value, and label. 140 * Sets a default value, minimum value, maximum value, and label.
141 * 141 *
142 * @param default_val Intial value of the setting, and default value of the setting 142 * @param default_val Initial value of the setting, and default value of the setting
143 * @param min_val Sets the minimum allowed value of the setting 143 * @param min_val Sets the minimum allowed value of the setting
144 * @param max_val Sets the maximum allowed value of the setting 144 * @param max_val Sets the maximum allowed value of the setting
145 * @param name Label for the setting 145 * @param name Label for the setting
@@ -231,7 +231,7 @@ public:
231 /** 231 /**
232 * Sets a default value, label, and setting value. 232 * Sets a default value, label, and setting value.
233 * 233 *
234 * @param default_val Intial value of the setting, and default value of the setting 234 * @param default_val Initial value of the setting, and default value of the setting
235 * @param name Label for the setting 235 * @param name Label for the setting
236 */ 236 */
237 explicit SwitchableSetting(const Type& default_val, const std::string& name) 237 explicit SwitchableSetting(const Type& default_val, const std::string& name)
@@ -242,7 +242,7 @@ public:
242 /** 242 /**
243 * Sets a default value, minimum value, maximum value, and label. 243 * Sets a default value, minimum value, maximum value, and label.
244 * 244 *
245 * @param default_val Intial value of the setting, and default value of the setting 245 * @param default_val Initial value of the setting, and default value of the setting
246 * @param min_val Sets the minimum allowed value of the setting 246 * @param min_val Sets the minimum allowed value of the setting
247 * @param max_val Sets the maximum allowed value of the setting 247 * @param max_val Sets the maximum allowed value of the setting
248 * @param name Label for the setting 248 * @param name Label for the setting
diff --git a/src/core/constants.cpp b/src/core/constants.cpp
index 4430173ef..760dc5f23 100644
--- a/src/core/constants.cpp
+++ b/src/core/constants.cpp
@@ -4,13 +4,24 @@
4#include "core/constants.h" 4#include "core/constants.h"
5 5
6namespace Core::Constants { 6namespace Core::Constants {
7const std::array<u8, 107> ACCOUNT_BACKUP_JPEG{{ 7const std::array<u8, 287> ACCOUNT_BACKUP_JPEG{{
8 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02, 8 0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01, 0x01, 0x01, 0x00, 0x48,
9 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08, 0x06, 0x06, 0x05, 9 0x00, 0x48, 0x00, 0x00, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x06, 0x04, 0x04, 0x04, 0x05, 0x04, 0x06,
10 0x06, 0x09, 0x08, 0x0a, 0x0a, 0x09, 0x08, 0x09, 0x09, 0x0a, 0x0c, 0x0f, 0x0c, 0x0a, 0x0b, 0x0e, 10 0x05, 0x05, 0x06, 0x09, 0x06, 0x05, 0x06, 0x09, 0x0b, 0x08, 0x06, 0x06, 0x08, 0x0b, 0x0c, 0x0a,
11 0x0b, 0x09, 0x09, 0x0d, 0x11, 0x0d, 0x0e, 0x0f, 0x10, 0x10, 0x11, 0x10, 0x0a, 0x0c, 0x12, 0x13, 11 0x0a, 0x0b, 0x0a, 0x0a, 0x0c, 0x10, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x10, 0x0c, 0x0e, 0x0f,
12 0x12, 0x10, 0x13, 0x0f, 0x10, 0x10, 0x10, 0xff, 0xc9, 0x00, 0x0b, 0x08, 0x00, 0x01, 0x00, 0x01, 12 0x10, 0x0f, 0x0e, 0x0c, 0x13, 0x13, 0x14, 0x14, 0x13, 0x13, 0x1c, 0x1b, 0x1b, 0x1b, 0x1c, 0x20,
13 0x01, 0x01, 0x11, 0x00, 0xff, 0xcc, 0x00, 0x06, 0x00, 0x10, 0x10, 0x05, 0xff, 0xda, 0x00, 0x08, 13 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xff, 0xdb, 0x00, 0x43, 0x01, 0x07, 0x07,
14 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, 14 0x07, 0x0d, 0x0c, 0x0d, 0x18, 0x10, 0x10, 0x18, 0x1a, 0x15, 0x11, 0x15, 0x1a, 0x20, 0x20, 0x20,
15 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
16 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
17 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xff, 0xc0,
18 0x00, 0x11, 0x08, 0x00, 0x20, 0x00, 0x20, 0x03, 0x01, 0x22, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11,
19 0x01, 0xff, 0xc4, 0x00, 0x14, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc4, 0x00, 0x14, 0x10, 0x01, 0x00, 0x00, 0x00,
21 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc4, 0x00,
22 0x14, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
23 0x00, 0x00, 0x00, 0xff, 0xc4, 0x00, 0x14, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
24 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00,
25 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xd9,
15}}; 26}};
16} 27}
diff --git a/src/core/constants.h b/src/core/constants.h
index f916ce0b6..f1f67d3b8 100644
--- a/src/core/constants.h
+++ b/src/core/constants.h
@@ -12,6 +12,6 @@
12namespace Core::Constants { 12namespace Core::Constants {
13 13
14// ACC Service - Blank JPEG used as user icon in absentia of real one. 14// ACC Service - Blank JPEG used as user icon in absentia of real one.
15extern const std::array<u8, 107> ACCOUNT_BACKUP_JPEG; 15extern const std::array<u8, 287> ACCOUNT_BACKUP_JPEG;
16 16
17} // namespace Core::Constants 17} // namespace Core::Constants
diff --git a/src/input_common/helpers/joycon_protocol/joycon_types.h b/src/input_common/helpers/joycon_protocol/joycon_types.h
index b91934990..2e50a99a8 100644
--- a/src/input_common/helpers/joycon_protocol/joycon_types.h
+++ b/src/input_common/helpers/joycon_protocol/joycon_types.h
@@ -95,6 +95,18 @@ enum class PasivePadButton : u32 {
95 ZL_ZR = 0x8000, 95 ZL_ZR = 0x8000,
96}; 96};
97 97
98enum class PasivePadStick : u8 {
99 Right = 0x00,
100 RightDown = 0x01,
101 Down = 0x02,
102 DownLeft = 0x03,
103 Left = 0x04,
104 LeftUp = 0x05,
105 Up = 0x06,
106 UpRight = 0x07,
107 Neutral = 0x08,
108};
109
98enum class OutputReport : u8 { 110enum class OutputReport : u8 {
99 RUMBLE_AND_SUBCMD = 0x01, 111 RUMBLE_AND_SUBCMD = 0x01,
100 FW_UPDATE_PKT = 0x03, 112 FW_UPDATE_PKT = 0x03,
diff --git a/src/input_common/helpers/joycon_protocol/poller.cpp b/src/input_common/helpers/joycon_protocol/poller.cpp
index 9bb15e935..ab48352b8 100644
--- a/src/input_common/helpers/joycon_protocol/poller.cpp
+++ b/src/input_common/helpers/joycon_protocol/poller.cpp
@@ -12,7 +12,7 @@ JoyconPoller::JoyconPoller(ControllerType device_type_, JoyStickCalibration left
12 : device_type{device_type_}, left_stick_calibration{left_stick_calibration_}, 12 : device_type{device_type_}, left_stick_calibration{left_stick_calibration_},
13 right_stick_calibration{right_stick_calibration_}, motion_calibration{motion_calibration_} {} 13 right_stick_calibration{right_stick_calibration_}, motion_calibration{motion_calibration_} {}
14 14
15void JoyconPoller::SetCallbacks(const Joycon::JoyconCallbacks& callbacks_) { 15void JoyconPoller::SetCallbacks(const JoyconCallbacks& callbacks_) {
16 callbacks = std::move(callbacks_); 16 callbacks = std::move(callbacks_);
17} 17}
18 18
@@ -22,13 +22,13 @@ void JoyconPoller::ReadActiveMode(std::span<u8> buffer, const MotionStatus& moti
22 memcpy(&data, buffer.data(), sizeof(InputReportActive)); 22 memcpy(&data, buffer.data(), sizeof(InputReportActive));
23 23
24 switch (device_type) { 24 switch (device_type) {
25 case Joycon::ControllerType::Left: 25 case ControllerType::Left:
26 UpdateActiveLeftPadInput(data, motion_status); 26 UpdateActiveLeftPadInput(data, motion_status);
27 break; 27 break;
28 case Joycon::ControllerType::Right: 28 case ControllerType::Right:
29 UpdateActiveRightPadInput(data, motion_status); 29 UpdateActiveRightPadInput(data, motion_status);
30 break; 30 break;
31 case Joycon::ControllerType::Pro: 31 case ControllerType::Pro:
32 UpdateActiveProPadInput(data, motion_status); 32 UpdateActiveProPadInput(data, motion_status);
33 break; 33 break;
34 default: 34 default:
@@ -47,13 +47,13 @@ void JoyconPoller::ReadPassiveMode(std::span<u8> buffer) {
47 memcpy(&data, buffer.data(), sizeof(InputReportPassive)); 47 memcpy(&data, buffer.data(), sizeof(InputReportPassive));
48 48
49 switch (device_type) { 49 switch (device_type) {
50 case Joycon::ControllerType::Left: 50 case ControllerType::Left:
51 UpdatePasiveLeftPadInput(data); 51 UpdatePasiveLeftPadInput(data);
52 break; 52 break;
53 case Joycon::ControllerType::Right: 53 case ControllerType::Right:
54 UpdatePasiveRightPadInput(data); 54 UpdatePasiveRightPadInput(data);
55 break; 55 break;
56 case Joycon::ControllerType::Pro: 56 case ControllerType::Pro:
57 UpdatePasiveProPadInput(data); 57 UpdatePasiveProPadInput(data);
58 break; 58 break;
59 default: 59 default:
@@ -211,13 +211,11 @@ void JoyconPoller::UpdateActiveProPadInput(const InputReportActive& input,
211} 211}
212 212
213void JoyconPoller::UpdatePasiveLeftPadInput(const InputReportPassive& input) { 213void JoyconPoller::UpdatePasiveLeftPadInput(const InputReportPassive& input) {
214 static constexpr std::array<Joycon::PasivePadButton, 11> left_buttons{ 214 static constexpr std::array<PasivePadButton, 11> left_buttons{
215 Joycon::PasivePadButton::Down_A, Joycon::PasivePadButton::Right_X, 215 PasivePadButton::Down_A, PasivePadButton::Right_X, PasivePadButton::Left_B,
216 Joycon::PasivePadButton::Left_B, Joycon::PasivePadButton::Up_Y, 216 PasivePadButton::Up_Y, PasivePadButton::SL, PasivePadButton::SR,
217 Joycon::PasivePadButton::SL, Joycon::PasivePadButton::SR, 217 PasivePadButton::L_R, PasivePadButton::ZL_ZR, PasivePadButton::Minus,
218 Joycon::PasivePadButton::L_R, Joycon::PasivePadButton::ZL_ZR, 218 PasivePadButton::Capture, PasivePadButton::StickL,
219 Joycon::PasivePadButton::Minus, Joycon::PasivePadButton::Capture,
220 Joycon::PasivePadButton::StickL,
221 }; 219 };
222 220
223 for (auto left_button : left_buttons) { 221 for (auto left_button : left_buttons) {
@@ -225,16 +223,19 @@ void JoyconPoller::UpdatePasiveLeftPadInput(const InputReportPassive& input) {
225 const int button = static_cast<int>(left_button); 223 const int button = static_cast<int>(left_button);
226 callbacks.on_button_data(button, button_status); 224 callbacks.on_button_data(button, button_status);
227 } 225 }
226
227 const auto [left_axis_x, left_axis_y] =
228 GetPassiveAxisValue(static_cast<PasivePadStick>(input.stick_state));
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);
228} 231}
229 232
230void JoyconPoller::UpdatePasiveRightPadInput(const InputReportPassive& input) { 233void JoyconPoller::UpdatePasiveRightPadInput(const InputReportPassive& input) {
231 static constexpr std::array<Joycon::PasivePadButton, 11> right_buttons{ 234 static constexpr std::array<PasivePadButton, 11> right_buttons{
232 Joycon::PasivePadButton::Down_A, Joycon::PasivePadButton::Right_X, 235 PasivePadButton::Down_A, PasivePadButton::Right_X, PasivePadButton::Left_B,
233 Joycon::PasivePadButton::Left_B, Joycon::PasivePadButton::Up_Y, 236 PasivePadButton::Up_Y, PasivePadButton::SL, PasivePadButton::SR,
234 Joycon::PasivePadButton::SL, Joycon::PasivePadButton::SR, 237 PasivePadButton::L_R, PasivePadButton::ZL_ZR, PasivePadButton::Plus,
235 Joycon::PasivePadButton::L_R, Joycon::PasivePadButton::ZL_ZR, 238 PasivePadButton::Home, PasivePadButton::StickR,
236 Joycon::PasivePadButton::Plus, Joycon::PasivePadButton::Home,
237 Joycon::PasivePadButton::StickR,
238 }; 239 };
239 240
240 for (auto right_button : right_buttons) { 241 for (auto right_button : right_buttons) {
@@ -242,17 +243,20 @@ void JoyconPoller::UpdatePasiveRightPadInput(const InputReportPassive& input) {
242 const int button = static_cast<int>(right_button); 243 const int button = static_cast<int>(right_button);
243 callbacks.on_button_data(button, button_status); 244 callbacks.on_button_data(button, button_status);
244 } 245 }
246
247 const auto [right_axis_x, right_axis_y] =
248 GetPassiveAxisValue(static_cast<PasivePadStick>(input.stick_state));
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);
245} 251}
246 252
247void JoyconPoller::UpdatePasiveProPadInput(const InputReportPassive& input) { 253void JoyconPoller::UpdatePasiveProPadInput(const InputReportPassive& input) {
248 static constexpr std::array<Joycon::PasivePadButton, 14> pro_buttons{ 254 static constexpr std::array<PasivePadButton, 14> pro_buttons{
249 Joycon::PasivePadButton::Down_A, Joycon::PasivePadButton::Right_X, 255 PasivePadButton::Down_A, PasivePadButton::Right_X, PasivePadButton::Left_B,
250 Joycon::PasivePadButton::Left_B, Joycon::PasivePadButton::Up_Y, 256 PasivePadButton::Up_Y, PasivePadButton::SL, PasivePadButton::SR,
251 Joycon::PasivePadButton::SL, Joycon::PasivePadButton::SR, 257 PasivePadButton::L_R, PasivePadButton::ZL_ZR, PasivePadButton::Minus,
252 Joycon::PasivePadButton::L_R, Joycon::PasivePadButton::ZL_ZR, 258 PasivePadButton::Plus, PasivePadButton::Capture, PasivePadButton::Home,
253 Joycon::PasivePadButton::Minus, Joycon::PasivePadButton::Plus, 259 PasivePadButton::StickL, PasivePadButton::StickR,
254 Joycon::PasivePadButton::Capture, Joycon::PasivePadButton::Home,
255 Joycon::PasivePadButton::StickL, Joycon::PasivePadButton::StickR,
256 }; 260 };
257 261
258 for (auto pro_button : pro_buttons) { 262 for (auto pro_button : pro_buttons) {
@@ -260,6 +264,15 @@ void JoyconPoller::UpdatePasiveProPadInput(const InputReportPassive& input) {
260 const int button = static_cast<int>(pro_button); 264 const int button = static_cast<int>(pro_button);
261 callbacks.on_button_data(button, button_status); 265 callbacks.on_button_data(button, button_status);
262 } 266 }
267
268 const auto [left_axis_x, left_axis_y] =
269 GetPassiveAxisValue(static_cast<PasivePadStick>(input.stick_state && 0xf));
270 const auto [right_axis_x, right_axis_y] =
271 GetPassiveAxisValue(static_cast<PasivePadStick>(input.stick_state >> 4));
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);
274 callbacks.on_stick_data(static_cast<int>(PadAxes::RightStickX), right_axis_x);
275 callbacks.on_stick_data(static_cast<int>(PadAxes::RightStickY), right_axis_y);
263} 276}
264 277
265f32 JoyconPoller::GetAxisValue(u16 raw_value, Joycon::JoyStickAxisCalibration calibration) const { 278f32 JoyconPoller::GetAxisValue(u16 raw_value, Joycon::JoyStickAxisCalibration calibration) const {
@@ -270,6 +283,30 @@ f32 JoyconPoller::GetAxisValue(u16 raw_value, Joycon::JoyStickAxisCalibration ca
270 return value / calibration.min; 283 return value / calibration.min;
271} 284}
272 285
286std::pair<f32, f32> JoyconPoller::GetPassiveAxisValue(PasivePadStick raw_value) const {
287 switch (raw_value) {
288 case PasivePadStick::Right:
289 return {1.0f, 0.0f};
290 case PasivePadStick::RightDown:
291 return {1.0f, -1.0f};
292 case PasivePadStick::Down:
293 return {0.0f, -1.0f};
294 case PasivePadStick::DownLeft:
295 return {-1.0f, -1.0f};
296 case PasivePadStick::Left:
297 return {-1.0f, 0.0f};
298 case PasivePadStick::LeftUp:
299 return {-1.0f, 1.0f};
300 case PasivePadStick::Up:
301 return {0.0f, 1.0f};
302 case PasivePadStick::UpRight:
303 return {1.0f, 1.0f};
304 case PasivePadStick::Neutral:
305 default:
306 return {0.0f, 0.0f};
307 }
308}
309
273f32 JoyconPoller::GetAccelerometerValue(s16 raw, const MotionSensorCalibration& cal, 310f32 JoyconPoller::GetAccelerometerValue(s16 raw, const MotionSensorCalibration& cal,
274 AccelerometerSensitivity sensitivity) const { 311 AccelerometerSensitivity sensitivity) const {
275 const f32 value = raw * (1.0f / (cal.scale - cal.offset)) * 4; 312 const f32 value = raw * (1.0f / (cal.scale - cal.offset)) * 4;
diff --git a/src/input_common/helpers/joycon_protocol/poller.h b/src/input_common/helpers/joycon_protocol/poller.h
index 354d41dad..5c897f070 100644
--- a/src/input_common/helpers/joycon_protocol/poller.h
+++ b/src/input_common/helpers/joycon_protocol/poller.h
@@ -22,7 +22,7 @@ public:
22 JoyStickCalibration right_stick_calibration_, 22 JoyStickCalibration right_stick_calibration_,
23 MotionCalibration motion_calibration_); 23 MotionCalibration motion_calibration_);
24 24
25 void SetCallbacks(const Joycon::JoyconCallbacks& callbacks_); 25 void SetCallbacks(const JoyconCallbacks& callbacks_);
26 26
27 /// Handles data from passive packages 27 /// Handles data from passive packages
28 void ReadPassiveMode(std::span<u8> buffer); 28 void ReadPassiveMode(std::span<u8> buffer);
@@ -51,7 +51,10 @@ private:
51 void UpdatePasiveProPadInput(const InputReportPassive& buffer); 51 void UpdatePasiveProPadInput(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, Joycon::JoyStickAxisCalibration calibration) const; 54 f32 GetAxisValue(u16 raw_value, JoyStickAxisCalibration calibration) const;
55
56 /// Returns a digital joystick axis from passive axis data
57 std::pair<f32, f32> GetPassiveAxisValue(PasivePadStick raw_value) const;
55 58
56 /// Returns a calibrated accelerometer axis from raw motion data 59 /// Returns a calibrated accelerometer axis from raw motion data
57 f32 GetAccelerometerValue(s16 raw, const MotionSensorCalibration& cal, 60 f32 GetAccelerometerValue(s16 raw, const MotionSensorCalibration& cal,
@@ -75,7 +78,7 @@ private:
75 JoyStickCalibration right_stick_calibration{}; 78 JoyStickCalibration right_stick_calibration{};
76 MotionCalibration motion_calibration{}; 79 MotionCalibration motion_calibration{};
77 80
78 Joycon::JoyconCallbacks callbacks{}; 81 JoyconCallbacks callbacks{};
79}; 82};
80 83
81} // namespace InputCommon::Joycon 84} // namespace InputCommon::Joycon