summaryrefslogtreecommitdiff
path: root/src/core/hid
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hid')
-rw-r--r--src/core/hid/emulated_controller.cpp43
-rw-r--r--src/core/hid/emulated_controller.h14
-rw-r--r--src/core/hid/hid_core.cpp10
-rw-r--r--src/core/hid/hid_core.h2
-rw-r--r--src/core/hid/hid_types.h2
5 files changed, 70 insertions, 1 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp
index 466ff5542..720706794 100644
--- a/src/core/hid/emulated_controller.cpp
+++ b/src/core/hid/emulated_controller.cpp
@@ -866,7 +866,50 @@ void EmulatedController::SetLedPattern() {
866 } 866 }
867} 867}
868 868
869void EmulatedController::SetSupportedNpadStyleTag(NpadStyleTag supported_styles) {
870 supported_style_tag = supported_styles;
871 if (!is_connected) {
872 return;
873 }
874 if (!IsControllerSupported()) {
875 LOG_ERROR(Service_HID, "Controller type {} is not supported. Disconnecting controller",
876 npad_type);
877 Disconnect();
878 }
879}
880
881bool EmulatedController::IsControllerSupported() const {
882 switch (npad_type) {
883 case NpadStyleIndex::ProController:
884 return supported_style_tag.fullkey;
885 case NpadStyleIndex::JoyconDual:
886 return supported_style_tag.joycon_dual;
887 case NpadStyleIndex::JoyconLeft:
888 return supported_style_tag.joycon_left;
889 case NpadStyleIndex::JoyconRight:
890 return supported_style_tag.joycon_right;
891 case NpadStyleIndex::GameCube:
892 return supported_style_tag.gamecube;
893 case NpadStyleIndex::Pokeball:
894 return supported_style_tag.palma;
895 case NpadStyleIndex::NES:
896 return supported_style_tag.lark;
897 case NpadStyleIndex::SNES:
898 return supported_style_tag.lucia;
899 case NpadStyleIndex::N64:
900 return supported_style_tag.lagoon;
901 case NpadStyleIndex::SegaGenesis:
902 return supported_style_tag.lager;
903 default:
904 return false;
905 }
906}
907
869void EmulatedController::Connect() { 908void EmulatedController::Connect() {
909 if (!IsControllerSupported()) {
910 LOG_ERROR(Service_HID, "Controller type {} is not supported", npad_type);
911 return;
912 }
870 { 913 {
871 std::lock_guard lock{mutex}; 914 std::lock_guard lock{mutex};
872 if (is_configuring) { 915 if (is_configuring) {
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h
index 5887e3e38..425b3e7c4 100644
--- a/src/core/hid/emulated_controller.h
+++ b/src/core/hid/emulated_controller.h
@@ -160,6 +160,13 @@ public:
160 */ 160 */
161 NpadStyleIndex GetNpadStyleIndex(bool get_temporary_value = false) const; 161 NpadStyleIndex GetNpadStyleIndex(bool get_temporary_value = false) const;
162 162
163 /**
164 * Sets the supported controller types. Disconnects the controller if current type is not
165 * supported
166 * @param supported_styles bitflag with supported types
167 */
168 void SetSupportedNpadStyleTag(NpadStyleTag supported_styles);
169
163 /// Sets the connected status to true 170 /// Sets the connected status to true
164 void Connect(); 171 void Connect();
165 172
@@ -311,6 +318,12 @@ private:
311 void LoadTASParams(); 318 void LoadTASParams();
312 319
313 /** 320 /**
321 * Checks the current controller type against the supported_style_tag
322 * @return true if the controller is supported
323 */
324 bool IsControllerSupported() const;
325
326 /**
314 * Updates the button status of the controller 327 * Updates the button status of the controller
315 * @param callback A CallbackStatus containing the button status 328 * @param callback A CallbackStatus containing the button status
316 * @param index Button ID of the to be updated 329 * @param index Button ID of the to be updated
@@ -354,6 +367,7 @@ private:
354 367
355 NpadIdType npad_id_type; 368 NpadIdType npad_id_type;
356 NpadStyleIndex npad_type{NpadStyleIndex::None}; 369 NpadStyleIndex npad_type{NpadStyleIndex::None};
370 NpadStyleTag supported_style_tag{NpadStyleSet::All};
357 bool is_connected{false}; 371 bool is_connected{false};
358 bool is_configuring{false}; 372 bool is_configuring{false};
359 f32 motion_sensitivity{0.01f}; 373 f32 motion_sensitivity{0.01f};
diff --git a/src/core/hid/hid_core.cpp b/src/core/hid/hid_core.cpp
index 946adde00..0c3eb5a62 100644
--- a/src/core/hid/hid_core.cpp
+++ b/src/core/hid/hid_core.cpp
@@ -108,6 +108,16 @@ const EmulatedController* HIDCore::GetEmulatedControllerByIndex(std::size_t inde
108 108
109void HIDCore::SetSupportedStyleTag(NpadStyleTag style_tag) { 109void HIDCore::SetSupportedStyleTag(NpadStyleTag style_tag) {
110 supported_style_tag.raw = style_tag.raw; 110 supported_style_tag.raw = style_tag.raw;
111 player_1->SetSupportedNpadStyleTag(supported_style_tag);
112 player_2->SetSupportedNpadStyleTag(supported_style_tag);
113 player_3->SetSupportedNpadStyleTag(supported_style_tag);
114 player_4->SetSupportedNpadStyleTag(supported_style_tag);
115 player_5->SetSupportedNpadStyleTag(supported_style_tag);
116 player_6->SetSupportedNpadStyleTag(supported_style_tag);
117 player_7->SetSupportedNpadStyleTag(supported_style_tag);
118 player_8->SetSupportedNpadStyleTag(supported_style_tag);
119 other->SetSupportedNpadStyleTag(supported_style_tag);
120 handheld->SetSupportedNpadStyleTag(supported_style_tag);
111} 121}
112 122
113NpadStyleTag HIDCore::GetSupportedStyleTag() const { 123NpadStyleTag HIDCore::GetSupportedStyleTag() const {
diff --git a/src/core/hid/hid_core.h b/src/core/hid/hid_core.h
index 140a0e962..2fb0f7e19 100644
--- a/src/core/hid/hid_core.h
+++ b/src/core/hid/hid_core.h
@@ -73,7 +73,7 @@ private:
73 std::unique_ptr<EmulatedController> handheld; 73 std::unique_ptr<EmulatedController> handheld;
74 std::unique_ptr<EmulatedConsole> console; 74 std::unique_ptr<EmulatedConsole> console;
75 std::unique_ptr<EmulatedDevices> devices; 75 std::unique_ptr<EmulatedDevices> devices;
76 NpadStyleTag supported_style_tag; 76 NpadStyleTag supported_style_tag{NpadStyleSet::All};
77}; 77};
78 78
79} // namespace Core::HID 79} // namespace Core::HID
diff --git a/src/core/hid/hid_types.h b/src/core/hid/hid_types.h
index 780659b86..7c12f01fc 100644
--- a/src/core/hid/hid_types.h
+++ b/src/core/hid/hid_types.h
@@ -256,6 +256,8 @@ enum class NpadStyleSet : u32 {
256 Lager = 1U << 11, 256 Lager = 1U << 11,
257 SystemExt = 1U << 29, 257 SystemExt = 1U << 29,
258 System = 1U << 30, 258 System = 1U << 30,
259
260 All = 0xFFFFFFFFU,
259}; 261};
260static_assert(sizeof(NpadStyleSet) == 4, "NpadStyleSet is an invalid size"); 262static_assert(sizeof(NpadStyleSet) == 4, "NpadStyleSet is an invalid size");
261 263