Explorar o código

controllers/npad: Add DeviceHandle struct

A DeviceHandle describes a vibration device or six-axis sensor based on the npad type, npad id, and device index/position
Morph %!s(int64=5) %!d(string=hai) anos
pai
achega
0a966e2cac
Modificáronse 1 ficheiros con 50 adicións e 27 borrados
  1. 50 27
      src/core/hle/service/hid/controllers/npad.h

+ 50 - 27
src/core/hle/service/hid/controllers/npad.h

@@ -39,28 +39,30 @@ public:
     // Called when input devices should be loaded
     void OnLoadInputDevices() override;
 
-    struct NPadType {
-        union {
-            u32_le raw{};
-
-            BitField<0, 1, u32> pro_controller;
-            BitField<1, 1, u32> handheld;
-            BitField<2, 1, u32> joycon_dual;
-            BitField<3, 1, u32> joycon_left;
-            BitField<4, 1, u32> joycon_right;
+    enum class NPadControllerType {
+        None,
+        ProController,
+        Handheld,
+        JoyDual,
+        JoyLeft,
+        JoyRight,
+        Pokeball,
+    };
 
-            BitField<6, 1, u32> pokeball; // TODO(ogniK): Confirm when possible
-        };
+    enum class NpadType : u8 {
+        ProController = 3,
+        Handheld = 4,
+        JoyconDual = 5,
+        JoyconLeft = 6,
+        JoyconRight = 7,
+        Pokeball = 9,
     };
-    static_assert(sizeof(NPadType) == 4, "NPadType is an invalid size");
 
-    struct Vibration {
-        f32 amp_low;
-        f32 freq_low;
-        f32 amp_high;
-        f32 freq_high;
+    enum class DeviceIndex : u8 {
+        Left = 0,
+        Right = 1,
+        None = 2,
     };
-    static_assert(sizeof(Vibration) == 0x10, "Vibration is an invalid size");
 
     enum class GyroscopeZeroDriftMode : u32 {
         Loose = 0,
@@ -73,7 +75,7 @@ public:
         Horizontal = 1,
     };
 
-    enum class NPadAssignments : u32_le {
+    enum class NPadAssignments : u32 {
         Dual = 0,
         Single = 1,
     };
@@ -84,15 +86,36 @@ public:
         None = 2,
     };
 
-    enum class NPadControllerType {
-        None,
-        ProController,
-        Handheld,
-        JoyDual,
-        JoyLeft,
-        JoyRight,
-        Pokeball,
+    struct DeviceHandle {
+        NpadType npad_type{};
+        u8 npad_id{};
+        DeviceIndex device_index{};
+        INSERT_PADDING_BYTES(1);
     };
+    static_assert(sizeof(DeviceHandle) == 4, "DeviceHandle is an invalid size");
+
+    struct NPadType {
+        union {
+            u32_le raw{};
+
+            BitField<0, 1, u32> pro_controller;
+            BitField<1, 1, u32> handheld;
+            BitField<2, 1, u32> joycon_dual;
+            BitField<3, 1, u32> joycon_left;
+            BitField<4, 1, u32> joycon_right;
+
+            BitField<6, 1, u32> pokeball; // TODO(ogniK): Confirm when possible
+        };
+    };
+    static_assert(sizeof(NPadType) == 4, "NPadType is an invalid size");
+
+    struct Vibration {
+        f32 amp_low;
+        f32 freq_low;
+        f32 amp_high;
+        f32 freq_high;
+    };
+    static_assert(sizeof(Vibration) == 0x10, "Vibration is an invalid size");
 
     struct LedPattern {
         explicit LedPattern(u64 light1, u64 light2, u64 light3, u64 light4) {