wut  1.0.0-beta8
Wii U Toolchain
kpad.h
Go to the documentation of this file.
1 #pragma once
2 #include <wut.h>
3 #include <padscore/wpad.h>
4 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 typedef enum WPADChan KPADChan;
17 
18 typedef struct KPADStatus KPADStatus;
19 typedef struct KPADVec2D KPADVec2D;
20 
21 typedef enum KPADError
22 {
24 } KPADError;
25 
26 struct KPADVec2D
27 {
28  float x;
29  float y;
30 };
31 WUT_CHECK_OFFSET(KPADVec2D, 0x00, x);
32 WUT_CHECK_OFFSET(KPADVec2D, 0x04, y);
33 WUT_CHECK_SIZE(KPADVec2D, 0x08);
34 
35 struct KPADStatus
36 {
38  uint32_t hold;
39 
41  uint32_t trigger;
42 
44  uint32_t release;
45 
46  WUT_UNKNOWN_BYTES(5 * 4);
47 
49 
50  WUT_UNKNOWN_BYTES(3 * 4);
51 
53 
54  WUT_UNKNOWN_BYTES(8 * 4);
55 
57  uint8_t extensionType;
58 
60  int8_t error;
61 
62  uint8_t posValid;
63 
65  uint8_t format;
66 
67  // Extension data, check with extensionType to see what is valid to read
68  union
69  {
70  // For WPAD_EXT_NUNCHUK
71  struct
72  {
73  KPADVec2D stick;
74  } nunchuck;
75 
76  // For WPAD_EXT_CLASSIC
77  struct
78  {
79  uint32_t hold;
80  uint32_t trigger;
81  uint32_t release;
82  KPADVec2D leftStick;
83  KPADVec2D rightStick;
84  float leftTrigger;
85  float rightTrigger;
86  } classic;
87 
88  // For WPAD_EXT_PRO_CONTROLLER
89  struct
90  {
91  uint32_t hold;
92  uint32_t trigger;
93  uint32_t release;
94  KPADVec2D leftStick;
95  KPADVec2D rightStick;
96  int32_t charging;
97  int32_t wired;
98  } pro;
99 
100  WUT_UNKNOWN_BYTES(20 * 4);
101  };
102 
103  WUT_UNKNOWN_BYTES(16 * 4);
104 };
105 WUT_CHECK_OFFSET(KPADStatus, 0x00, hold);
106 WUT_CHECK_OFFSET(KPADStatus, 0x04, trigger);
107 WUT_CHECK_OFFSET(KPADStatus, 0x08, release);
108 WUT_CHECK_OFFSET(KPADStatus, 0x20, pos);
109 WUT_CHECK_OFFSET(KPADStatus, 0x34, angle);
110 WUT_CHECK_OFFSET(KPADStatus, 0x5C, extensionType);
111 WUT_CHECK_OFFSET(KPADStatus, 0x5D, error);
112 WUT_CHECK_OFFSET(KPADStatus, 0x5E, posValid);
113 WUT_CHECK_OFFSET(KPADStatus, 0x5F, format);
114 // For WPAD_EXT_NUNCHUK
115 WUT_CHECK_OFFSET(KPADStatus, 0x60, nunchuck.stick);
116 // For WPAD_EXT_CLASSIC
117 WUT_CHECK_OFFSET(KPADStatus, 0x60, classic.hold);
118 WUT_CHECK_OFFSET(KPADStatus, 0x64, classic.trigger);
119 WUT_CHECK_OFFSET(KPADStatus, 0x68, classic.release);
120 WUT_CHECK_OFFSET(KPADStatus, 0x6C, classic.leftStick);
121 WUT_CHECK_OFFSET(KPADStatus, 0x74, classic.rightStick);
122 WUT_CHECK_OFFSET(KPADStatus, 0x7C, classic.leftTrigger);
123 WUT_CHECK_OFFSET(KPADStatus, 0x80, classic.rightTrigger);
124 // For WPAD_EXT_PRO_CONTROLLER
125 WUT_CHECK_OFFSET(KPADStatus, 0x60, pro.hold);
126 WUT_CHECK_OFFSET(KPADStatus, 0x64, pro.trigger);
127 WUT_CHECK_OFFSET(KPADStatus, 0x68, pro.release);
128 WUT_CHECK_OFFSET(KPADStatus, 0x6C, pro.leftStick);
129 WUT_CHECK_OFFSET(KPADStatus, 0x74, pro.rightStick);
130 WUT_CHECK_OFFSET(KPADStatus, 0x7C, pro.charging);
131 WUT_CHECK_OFFSET(KPADStatus, 0x80, pro.wired);
132 WUT_CHECK_SIZE(KPADStatus, 0xF0);
133 
134 void
135 KPADInit();
136 
137 int32_t
138 KPADRead(KPADChan chan,
139  KPADStatus *data,
140  uint32_t size);
141 
142 int32_t
143 KPADReadEx(KPADChan chan,
144  KPADStatus *data,
145  uint32_t size,
146  int32_t *error);
147 
148 #ifdef __cplusplus
149 }
150 #endif
151 
KPADVec2D angle
Definition: kpad.h:52
KPADError
Definition: kpad.h:21
enum WPADExtensionType KPADExtensionType
Definition: kpad.h:16
uint32_t hold
Indicates what KPADButtons are held down.
Definition: kpad.h:38
enum WPADDataFormat KPADDataFormat
Definition: kpad.h:15
uint8_t format
Value from KPADDataFormat.
Definition: kpad.h:65
KPADVec2D pos
Definition: kpad.h:48
float x
Definition: kpad.h:28
enum WPADChan KPADChan
Definition: kpad.h:14
void KPADInit()
uint32_t trigger
Indicates what KPADButtons have been pressed since last sample.
Definition: kpad.h:41
WPADExtensionType
Definition: wpad.h:29
uint8_t extensionType
Value from KPADExtensionType.
Definition: kpad.h:57
uint8_t posValid
Definition: kpad.h:62
WPADDataFormat
Definition: wpad.h:24
int8_t error
Value from KPADError.
Definition: kpad.h:60
int32_t KPADRead(KPADChan chan, KPADStatus *data, uint32_t size)
Definition: kpad.h:26
float y
Definition: kpad.h:29
uint32_t release
Indicates what KPADButtons have been released since last sample.
Definition: kpad.h:44
int32_t KPADReadEx(KPADChan chan, KPADStatus *data, uint32_t size, int32_t *error)
WPADChan
Definition: wpad.h:16