wut  v1.5.0
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 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
18 typedef enum WPADChan KPADChan;
20 typedef enum WPADDataFormat KPADDataFormat;
23 
24 typedef struct KPADStatus KPADStatus;
25 typedef struct KPADVec2D KPADVec2D;
26 typedef struct KPADVec3D KPADVec3D;
27 
29 typedef enum KPADError
30 {
44 
46 struct KPADVec2D
47 {
49  float x;
51  float y;
52 };
53 WUT_CHECK_OFFSET(KPADVec2D, 0x00, x);
54 WUT_CHECK_OFFSET(KPADVec2D, 0x04, y);
55 WUT_CHECK_SIZE(KPADVec2D, 0x08);
56 
58 struct KPADVec3D
59 {
61  float x;
63  float y;
65  float z;
66 };
67 WUT_CHECK_OFFSET(KPADVec3D, 0x00, x);
68 WUT_CHECK_OFFSET(KPADVec3D, 0x04, y);
69 WUT_CHECK_OFFSET(KPADVec3D, 0x08, z);
70 WUT_CHECK_SIZE(KPADVec3D, 0x0C);
71 
73 struct KPADStatus
74 {
76  uint32_t hold;
77 
79  uint32_t trigger;
80 
82  uint32_t release;
83 
86 
88  float accMagnitude;
89 
91  float accVariation;
92 
95 
96  WUT_UNKNOWN_BYTES(3 * 4);
97 
100 
101  WUT_UNKNOWN_BYTES(8 * 4);
102 
104  uint8_t extensionType;
105 
107  int8_t error;
108 
110  int8_t posValid;
111 
113  uint8_t format;
114 
116  union
117  {
119  struct
120  {
122  KPADVec2D stick;
124  KPADVec3D acc;
126  float accMagnitude;
128  float accVariation;
130  uint32_t hold;
132  uint32_t trigger;
134  uint32_t release;
135  } nunchuck;
136 
138  struct
139  {
141  uint32_t hold;
143  uint32_t trigger;
145  uint32_t release;
147  KPADVec2D leftStick;
149  KPADVec2D rightStick;
151  float leftTrigger;
153  float rightTrigger;
154  } classic;
155 
157  struct
158  {
160  uint32_t hold;
162  uint32_t trigger;
164  uint32_t release;
166  KPADVec2D leftStick;
168  KPADVec2D rightStick;
170  int32_t charging;
172  int32_t wired;
173  } pro;
174 
175  WUT_UNKNOWN_BYTES(20 * 4);
176  };
177 
178  WUT_UNKNOWN_BYTES(16 * 4);
179 };
180 WUT_CHECK_OFFSET(KPADStatus, 0x00, hold);
181 WUT_CHECK_OFFSET(KPADStatus, 0x04, trigger);
182 WUT_CHECK_OFFSET(KPADStatus, 0x08, release);
183 WUT_CHECK_OFFSET(KPADStatus, 0x0C, acc);
184 WUT_CHECK_OFFSET(KPADStatus, 0x18, accMagnitude);
185 WUT_CHECK_OFFSET(KPADStatus, 0x1C, accVariation);
186 WUT_CHECK_OFFSET(KPADStatus, 0x20, pos);
187 WUT_CHECK_OFFSET(KPADStatus, 0x34, angle);
188 WUT_CHECK_OFFSET(KPADStatus, 0x5C, extensionType);
189 WUT_CHECK_OFFSET(KPADStatus, 0x5D, error);
190 WUT_CHECK_OFFSET(KPADStatus, 0x5E, posValid);
191 WUT_CHECK_OFFSET(KPADStatus, 0x5F, format);
192 // For WPAD_EXT_NUNCHUK
193 WUT_CHECK_OFFSET(KPADStatus, 0x60, nunchuck.stick);
194 WUT_CHECK_OFFSET(KPADStatus, 0x68, nunchuck.acc);
195 WUT_CHECK_OFFSET(KPADStatus, 0x74, nunchuck.accMagnitude);
196 WUT_CHECK_OFFSET(KPADStatus, 0x78, nunchuck.accVariation);
197 WUT_CHECK_OFFSET(KPADStatus, 0x7C, nunchuck.hold);
198 WUT_CHECK_OFFSET(KPADStatus, 0x80, nunchuck.trigger);
199 WUT_CHECK_OFFSET(KPADStatus, 0x84, nunchuck.release);
200 // For WPAD_EXT_CLASSIC
201 WUT_CHECK_OFFSET(KPADStatus, 0x60, classic.hold);
202 WUT_CHECK_OFFSET(KPADStatus, 0x64, classic.trigger);
203 WUT_CHECK_OFFSET(KPADStatus, 0x68, classic.release);
204 WUT_CHECK_OFFSET(KPADStatus, 0x6C, classic.leftStick);
205 WUT_CHECK_OFFSET(KPADStatus, 0x74, classic.rightStick);
206 WUT_CHECK_OFFSET(KPADStatus, 0x7C, classic.leftTrigger);
207 WUT_CHECK_OFFSET(KPADStatus, 0x80, classic.rightTrigger);
208 // For WPAD_EXT_PRO_CONTROLLER
209 WUT_CHECK_OFFSET(KPADStatus, 0x60, pro.hold);
210 WUT_CHECK_OFFSET(KPADStatus, 0x64, pro.trigger);
211 WUT_CHECK_OFFSET(KPADStatus, 0x68, pro.release);
212 WUT_CHECK_OFFSET(KPADStatus, 0x6C, pro.leftStick);
213 WUT_CHECK_OFFSET(KPADStatus, 0x74, pro.rightStick);
214 WUT_CHECK_OFFSET(KPADStatus, 0x7C, pro.charging);
215 WUT_CHECK_OFFSET(KPADStatus, 0x80, pro.wired);
216 WUT_CHECK_SIZE(KPADStatus, 0xF0);
217 
219 
223 void
225 
229 void
231 
247 int32_t
249  KPADStatus *data,
250  uint32_t size);
251 
270 int32_t
272  KPADStatus *data,
273  uint32_t size,
274  KPADError *error);
275 
285 int32_t
286 KPADSetMaxControllers(uint32_t maxControllers);
287 
294 uint32_t
296 
303 uint32_t
305 
320  KPADConnectCallback callback);
321 
322 #ifdef __cplusplus
323 }
324 #endif
325 
uint8_t extensionType
Value from KPADExtensionType.
Definition: kpad.h:101
KPADVec3D acc
Indicates the value of the acceleration sensor.
Definition: kpad.h:85
uint32_t hold
Indicates what KPADButtons are held down.
Definition: kpad.h:76
int8_t posValid
Validity of the result.
Definition: kpad.h:110
KPADVec2D angle
Angle.
Definition: kpad.h:96
uint8_t format
Value from KPADDataFormat.
Definition: kpad.h:113
float y
y.
Definition: kpad.h:51
uint32_t release
Indicates what KPADButtons have been released since last sample.
Definition: kpad.h:82
int8_t error
Value from KPADError.
Definition: kpad.h:107
uint32_t trigger
Indicates what KPADButtons have been pressed since last sample.
Definition: kpad.h:79
float x
x.
Definition: kpad.h:49
float accVariation
Indicates the variation in acceleration.
Definition: kpad.h:91
float accMagnitude
Indicates the magnitude of acceleration.
Definition: kpad.h:88
float z
z.
Definition: kpad.h:65
KPADVec2D pos
Indicates the position where the Wii Remote is pointing.
Definition: kpad.h:94
WPADConnectCallback KPADConnectCallback
Definition: kpad.h:180
void KPADShutdown()
Cleans up and frees the KPAD library.
KPADError
Error.
Definition: kpad.h:30
enum WPADExtensionType KPADExtensionType
Extension type.
Definition: kpad.h:22
enum WPADDataFormat KPADDataFormat
Data format.
Definition: kpad.h:20
KPADConnectCallback KPADSetConnectCallback(KPADChan chan, KPADConnectCallback callback)
Set a callback for when a controller connection status changes.
uint32_t KPADGetGameMaxControllers(void)
Get the maximum amount of controllers which can be connected, as reported by IOS-PAD.
void KPADInit()
Initialises the KPAD library for use.
uint32_t KPADGetMaxControllers(void)
Get the maximum amount of controllers which can be connected to the system.
enum WPADChan KPADChan
Wii Remote channel.
Definition: kpad.h:18
int32_t KPADRead(KPADChan chan, KPADStatus *data, uint32_t size)
Read data from the desired controller.
int32_t KPADReadEx(KPADChan chan, KPADStatus *data, uint32_t size, KPADError *error)
Read data from the desired controller.
int32_t KPADSetMaxControllers(uint32_t maxControllers)
Set the maximum amount of controllers which can be connected to the system.
@ KPAD_ERROR_OK
No error occurred, and data was written to the buffers.
Definition: kpad.h:32
@ KPAD_ERROR_WPAD_UNINIT
WPAD is uninitialized, shouldn't happen unless WPADShutdown() is manually called.
Definition: kpad.h:38
@ KPAD_ERROR_BUSY
KPAD channel is busy, perhaps being accessed by another thread.
Definition: kpad.h:40
@ KPAD_ERROR_NO_SAMPLES
There was no sample new data available to write.
Definition: kpad.h:34
@ KPAD_ERROR_INVALID_CONTROLLER
The requested controller or channel was invalid.
Definition: kpad.h:36
@ KPAD_ERROR_UNINITIALIZED
KPAD is uninitialized, need to call KPADInit()
Definition: kpad.h:42
A structure conataining the Wii Remote data.
Definition: kpad.h:74
2D vector.
Definition: kpad.h:47
3D vector.
Definition: kpad.h:59
WPADDataFormat
Data format.
Definition: wpad.h:40
WPADChan
Wii Remote channel.
Definition: wpad.h:21
WPADExtensionType
Extension type.
Definition: wpad.h:46
void(* WPADConnectCallback)(WPADChan chan, int32_t status)
Definition: wpad.h:256