Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
178 | Alpin | 1 | /* |
2 | * wiiuse |
||
3 | * |
||
4 | * Written By: |
||
5 | * Michael Laforest < para > |
||
6 | * Email: < thepara (--AT--) g m a i l [--DOT--] com > |
||
7 | * |
||
8 | * Copyright 2006-2007 |
||
9 | * |
||
10 | * This file is part of wiiuse. |
||
11 | * |
||
12 | * This program is free software; you can redistribute it and/or modify |
||
13 | * it under the terms of the GNU General Public License as published by |
||
14 | * the Free Software Foundation; either version 3 of the License, or |
||
15 | * (at your option) any later version. |
||
16 | * |
||
17 | * This program is distributed in the hope that it will be useful, |
||
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
20 | * GNU General Public License for more details. |
||
21 | * |
||
22 | * You should have received a copy of the GNU General Public License |
||
23 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
24 | * |
||
25 | * $Header$ |
||
26 | * |
||
27 | */ |
||
28 | |||
29 | /** |
||
30 | * @file |
||
31 | * |
||
32 | * @brief API header file. |
||
33 | * |
||
34 | * If this file is included from inside the wiiuse source |
||
35 | * and not from a third party program, then wiimote_internal.h |
||
36 | * is also included which extends this file. |
||
37 | */ |
||
38 | |||
39 | #ifndef WIIUSE_H_INCLUDED |
||
40 | #define WIIUSE_H_INCLUDED |
||
41 | |||
42 | #ifdef _WIN32 |
||
43 | /* windows */ |
||
44 | #include <windows.h> |
||
45 | #else |
||
46 | /* nix */ |
||
47 | #include <bluetooth/bluetooth.h> |
||
48 | #endif |
||
49 | |||
50 | #ifdef WIIUSE_INTERNAL_H_INCLUDED |
||
51 | #define WCONST |
||
52 | #else |
||
53 | #define WCONST const |
||
54 | #endif |
||
55 | |||
56 | /* led bit masks */ |
||
57 | #define WIIMOTE_LED_NONE 0x00 |
||
58 | #define WIIMOTE_LED_1 0x10 |
||
59 | #define WIIMOTE_LED_2 0x20 |
||
60 | #define WIIMOTE_LED_3 0x40 |
||
61 | #define WIIMOTE_LED_4 0x80 |
||
62 | |||
63 | /* button codes */ |
||
64 | #define WIIMOTE_BUTTON_TWO 0x0001 |
||
65 | #define WIIMOTE_BUTTON_ONE 0x0002 |
||
66 | #define WIIMOTE_BUTTON_B 0x0004 |
||
67 | #define WIIMOTE_BUTTON_A 0x0008 |
||
68 | #define WIIMOTE_BUTTON_MINUS 0x0010 |
||
69 | #define WIIMOTE_BUTTON_ZACCEL_BIT6 0x0020 |
||
70 | #define WIIMOTE_BUTTON_ZACCEL_BIT7 0x0040 |
||
71 | #define WIIMOTE_BUTTON_HOME 0x0080 |
||
72 | #define WIIMOTE_BUTTON_LEFT 0x0100 |
||
73 | #define WIIMOTE_BUTTON_RIGHT 0x0200 |
||
74 | #define WIIMOTE_BUTTON_DOWN 0x0400 |
||
75 | #define WIIMOTE_BUTTON_UP 0x0800 |
||
76 | #define WIIMOTE_BUTTON_PLUS 0x1000 |
||
77 | #define WIIMOTE_BUTTON_ZACCEL_BIT4 0x2000 |
||
78 | #define WIIMOTE_BUTTON_ZACCEL_BIT5 0x4000 |
||
79 | #define WIIMOTE_BUTTON_UNKNOWN 0x8000 |
||
80 | #define WIIMOTE_BUTTON_ALL 0x1F9F |
||
81 | |||
82 | /* nunchul button codes */ |
||
83 | #define NUNCHUK_BUTTON_Z 0x01 |
||
84 | #define NUNCHUK_BUTTON_C 0x02 |
||
85 | #define NUNCHUK_BUTTON_ALL 0x03 |
||
86 | |||
87 | /* classic controller button codes */ |
||
88 | #define CLASSIC_CTRL_BUTTON_UP 0x0001 |
||
89 | #define CLASSIC_CTRL_BUTTON_LEFT 0x0002 |
||
90 | #define CLASSIC_CTRL_BUTTON_ZR 0x0004 |
||
91 | #define CLASSIC_CTRL_BUTTON_X 0x0008 |
||
92 | #define CLASSIC_CTRL_BUTTON_A 0x0010 |
||
93 | #define CLASSIC_CTRL_BUTTON_Y 0x0020 |
||
94 | #define CLASSIC_CTRL_BUTTON_B 0x0040 |
||
95 | #define CLASSIC_CTRL_BUTTON_ZL 0x0080 |
||
96 | #define CLASSIC_CTRL_BUTTON_FULL_R 0x0200 |
||
97 | #define CLASSIC_CTRL_BUTTON_PLUS 0x0400 |
||
98 | #define CLASSIC_CTRL_BUTTON_HOME 0x0800 |
||
99 | #define CLASSIC_CTRL_BUTTON_MINUS 0x1000 |
||
100 | #define CLASSIC_CTRL_BUTTON_FULL_L 0x2000 |
||
101 | #define CLASSIC_CTRL_BUTTON_DOWN 0x4000 |
||
102 | #define CLASSIC_CTRL_BUTTON_RIGHT 0x8000 |
||
103 | #define CLASSIC_CTRL_BUTTON_ALL 0xFEFF |
||
104 | |||
105 | /* guitar hero 3 button codes */ |
||
106 | #define GUITAR_HERO_3_BUTTON_STRUM_UP 0x0001 |
||
107 | #define GUITAR_HERO_3_BUTTON_YELLOW 0x0008 |
||
108 | #define GUITAR_HERO_3_BUTTON_GREEN 0x0010 |
||
109 | #define GUITAR_HERO_3_BUTTON_BLUE 0x0020 |
||
110 | #define GUITAR_HERO_3_BUTTON_RED 0x0040 |
||
111 | #define GUITAR_HERO_3_BUTTON_ORANGE 0x0080 |
||
112 | #define GUITAR_HERO_3_BUTTON_PLUS 0x0400 |
||
113 | #define GUITAR_HERO_3_BUTTON_MINUS 0x1000 |
||
114 | #define GUITAR_HERO_3_BUTTON_STRUM_DOWN 0x4000 |
||
115 | #define GUITAR_HERO_3_BUTTON_ALL 0xFEFF |
||
116 | |||
117 | |||
118 | /* wiimote option flags */ |
||
119 | #define WIIUSE_SMOOTHING 0x01 |
||
120 | #define WIIUSE_CONTINUOUS 0x02 |
||
121 | #define WIIUSE_ORIENT_THRESH 0x04 |
||
122 | #define WIIUSE_INIT_FLAGS (WIIUSE_SMOOTHING | WIIUSE_ORIENT_THRESH) |
||
123 | |||
124 | #define WIIUSE_ORIENT_PRECISION 100.0f |
||
125 | |||
126 | /* expansion codes */ |
||
127 | #define EXP_NONE 0 |
||
128 | #define EXP_NUNCHUK 1 |
||
129 | #define EXP_CLASSIC 2 |
||
130 | #define EXP_GUITAR_HERO_3 3 |
||
131 | |||
132 | /* IR correction types */ |
||
133 | typedef enum ir_position_t { |
||
134 | WIIUSE_IR_ABOVE, |
||
135 | WIIUSE_IR_BELOW |
||
136 | } ir_position_t; |
||
137 | |||
138 | /** |
||
139 | * @brief Check if a button is pressed. |
||
140 | * @param dev Pointer to a wiimote_t or expansion structure. |
||
141 | * @param button The button you are interested in. |
||
142 | * @return 1 if the button is pressed, 0 if not. |
||
143 | */ |
||
144 | #define IS_PRESSED(dev, button) ((dev->btns & button) == button) |
||
145 | |||
146 | /** |
||
147 | * @brief Check if a button is being held. |
||
148 | * @param dev Pointer to a wiimote_t or expansion structure. |
||
149 | * @param button The button you are interested in. |
||
150 | * @return 1 if the button is held, 0 if not. |
||
151 | */ |
||
152 | #define IS_HELD(dev, button) ((dev->btns_held & button) == button) |
||
153 | |||
154 | /** |
||
155 | * @brief Check if a button is released on this event. \n\n |
||
156 | * This does not mean the button is not pressed, it means \n |
||
157 | * this button was just now released. |
||
158 | * @param dev Pointer to a wiimote_t or expansion structure. |
||
159 | * @param button The button you are interested in. |
||
160 | * @return 1 if the button is released, 0 if not. |
||
161 | * |
||
162 | */ |
||
163 | #define IS_RELEASED(dev, button) ((dev->btns_released & button) == button) |
||
164 | |||
165 | /** |
||
166 | * @brief Check if a button has just been pressed this event. |
||
167 | * @param dev Pointer to a wiimote_t or expansion structure. |
||
168 | * @param button The button you are interested in. |
||
169 | * @return 1 if the button is pressed, 0 if not. |
||
170 | */ |
||
171 | #define IS_JUST_PRESSED(dev, button) (IS_PRESSED(dev, button) && !IS_HELD(dev, button)) |
||
172 | |||
173 | /** |
||
174 | * @brief Return the IR sensitivity level. |
||
175 | * @param wm Pointer to a wiimote_t structure. |
||
176 | * @param lvl [out] Pointer to an int that will hold the level setting. |
||
177 | * If no level is set 'lvl' will be set to 0. |
||
178 | */ |
||
179 | #define WIIUSE_GET_IR_SENSITIVITY(dev, lvl) \ |
||
180 | do { \ |
||
181 | if ((wm->state & 0x0200) == 0x0200) *lvl = 1; \ |
||
182 | else if ((wm->state & 0x0400) == 0x0400) *lvl = 2; \ |
||
183 | else if ((wm->state & 0x0800) == 0x0800) *lvl = 3; \ |
||
184 | else if ((wm->state & 0x1000) == 0x1000) *lvl = 4; \ |
||
185 | else if ((wm->state & 0x2000) == 0x2000) *lvl = 5; \ |
||
186 | else *lvl = 0; \ |
||
187 | } while (0) |
||
188 | |||
189 | #define WIIUSE_USING_ACC(wm) ((wm->state & 0x020) == 0x020) |
||
190 | #define WIIUSE_USING_EXP(wm) ((wm->state & 0x040) == 0x040) |
||
191 | #define WIIUSE_USING_IR(wm) ((wm->state & 0x080) == 0x080) |
||
192 | #define WIIUSE_USING_SPEAKER(wm) ((wm->state & 0x100) == 0x100) |
||
193 | |||
194 | #define WIIUSE_IS_LED_SET(wm, num) ((wm->leds & WIIMOTE_LED_##num) == WIIMOTE_LED_##num) |
||
195 | |||
196 | /* |
||
197 | * Largest known payload is 21 bytes. |
||
198 | * Add 2 for the prefix and round up to a power of 2. |
||
199 | */ |
||
200 | #define MAX_PAYLOAD 32 |
||
201 | |||
202 | /* |
||
203 | * This is left over from an old hack, but it may actually |
||
204 | * be a useful feature to keep so it wasn't removed. |
||
205 | */ |
||
206 | #ifdef WIN32 |
||
207 | #define WIIMOTE_DEFAULT_TIMEOUT 10 |
||
208 | #define WIIMOTE_EXP_TIMEOUT 10 |
||
209 | #endif |
||
210 | |||
211 | typedef unsigned char byte; |
||
212 | typedef char sbyte; |
||
213 | |||
214 | struct wiimote_t; |
||
215 | struct vec3b_t; |
||
216 | struct orient_t; |
||
217 | struct gforce_t; |
||
218 | |||
219 | |||
220 | /** |
||
221 | * @brief Callback that handles a read event. |
||
222 | * |
||
223 | * @param wm Pointer to a wiimote_t structure. |
||
224 | * @param data Pointer to the filled data block. |
||
225 | * @param len Length in bytes of the data block. |
||
226 | * |
||
227 | * @see wiiuse_init() |
||
228 | * |
||
229 | * A registered function of this type is called automatically by the wiiuse |
||
230 | * library when the wiimote has returned the full data requested by a previous |
||
231 | * call to wiiuse_read_data(). |
||
232 | */ |
||
233 | typedef void (*wiiuse_read_cb)(struct wiimote_t* wm, byte* data, unsigned short len); |
||
234 | |||
235 | |||
236 | /** |
||
237 | * @struct read_req_t |
||
238 | * @brief Data read request structure. |
||
239 | */ |
||
240 | struct read_req_t { |
||
241 | wiiuse_read_cb cb; /**< read data callback */ |
||
242 | byte* buf; /**< buffer where read data is written */ |
||
243 | unsigned int addr; /**< the offset that the read started at */ |
||
244 | unsigned short size; /**< the length of the data read */ |
||
245 | unsigned short wait; /**< num bytes still needed to finish read */ |
||
246 | byte dirty; /**< set to 1 if not using callback and needs to be cleaned up */ |
||
247 | |||
248 | struct read_req_t* next; /**< next read request in the queue */ |
||
249 | }; |
||
250 | |||
251 | |||
252 | /** |
||
253 | * @struct vec2b_t |
||
254 | * @brief Unsigned x,y byte vector. |
||
255 | */ |
||
256 | typedef struct vec2b_t { |
||
257 | byte x, y; |
||
258 | } vec2b_t; |
||
259 | |||
260 | |||
261 | /** |
||
262 | * @struct vec3b_t |
||
263 | * @brief Unsigned x,y,z byte vector. |
||
264 | */ |
||
265 | typedef struct vec3b_t { |
||
266 | byte x, y, z; |
||
267 | } vec3b_t; |
||
268 | |||
269 | |||
270 | /** |
||
271 | * @struct vec3f_t |
||
272 | * @brief Signed x,y,z float struct. |
||
273 | */ |
||
274 | typedef struct vec3f_t { |
||
275 | float x, y, z; |
||
276 | } vec3f_t; |
||
277 | |||
278 | |||
279 | /** |
||
280 | * @struct orient_t |
||
281 | * @brief Orientation struct. |
||
282 | * |
||
283 | * Yaw, pitch, and roll range from -180 to 180 degrees. |
||
284 | */ |
||
285 | typedef struct orient_t { |
||
286 | float roll; /**< roll, this may be smoothed if enabled */ |
||
287 | float pitch; /**< pitch, this may be smoothed if enabled */ |
||
288 | float yaw; |
||
289 | |||
290 | float a_roll; /**< absolute roll, unsmoothed */ |
||
291 | float a_pitch; /**< absolute pitch, unsmoothed */ |
||
292 | } orient_t; |
||
293 | |||
294 | |||
295 | /** |
||
296 | * @struct gforce_t |
||
297 | * @brief Gravity force struct. |
||
298 | */ |
||
299 | typedef struct gforce_t { |
||
300 | float x, y, z; |
||
301 | } gforce_t; |
||
302 | |||
303 | |||
304 | /** |
||
305 | * @struct accel_t |
||
306 | * @brief Accelerometer struct. For any device with an accelerometer. |
||
307 | */ |
||
308 | typedef struct accel_t { |
||
309 | struct vec3b_t cal_zero; /**< zero calibration */ |
||
310 | struct vec3b_t cal_g; /**< 1g difference around 0cal */ |
||
311 | |||
312 | float st_roll; /**< last smoothed roll value */ |
||
313 | float st_pitch; /**< last smoothed roll pitch */ |
||
314 | float st_alpha; /**< alpha value for smoothing [0-1] */ |
||
315 | } accel_t; |
||
316 | |||
317 | |||
318 | /** |
||
319 | * @struct ir_dot_t |
||
320 | * @brief A single IR source. |
||
321 | */ |
||
322 | typedef struct ir_dot_t { |
||
323 | byte visible; /**< if the IR source is visible */ |
||
324 | |||
325 | unsigned int x; /**< interpolated X coordinate */ |
||
326 | unsigned int y; /**< interpolated Y coordinate */ |
||
327 | |||
328 | short rx; /**< raw X coordinate (0-1023) */ |
||
329 | short ry; /**< raw Y coordinate (0-767) */ |
||
330 | |||
331 | byte order; /**< increasing order by x-axis value */ |
||
332 | |||
333 | byte size; /**< size of the IR dot (0-15) */ |
||
334 | } ir_dot_t; |
||
335 | |||
336 | |||
337 | /** |
||
338 | * @enum aspect_t |
||
339 | * @brief Screen aspect ratio. |
||
340 | */ |
||
341 | typedef enum aspect_t { |
||
342 | WIIUSE_ASPECT_4_3, |
||
343 | WIIUSE_ASPECT_16_9 |
||
344 | } aspect_t; |
||
345 | |||
346 | |||
347 | /** |
||
348 | * @struct ir_t |
||
349 | * @brief IR struct. Hold all data related to the IR tracking. |
||
350 | */ |
||
351 | typedef struct ir_t { |
||
352 | struct ir_dot_t dot[4]; /**< IR dots */ |
||
353 | byte num_dots; /**< number of dots at this time */ |
||
354 | |||
355 | enum aspect_t aspect; /**< aspect ratio of the screen */ |
||
356 | |||
357 | enum ir_position_t pos; /**< IR sensor bar position */ |
||
358 | |||
359 | unsigned int vres[2]; /**< IR virtual screen resolution */ |
||
360 | int offset[2]; /**< IR XY correction offset */ |
||
361 | int state; /**< keeps track of the IR state */ |
||
362 | |||
363 | int ax; /**< absolute X coordinate */ |
||
364 | int ay; /**< absolute Y coordinate */ |
||
365 | |||
366 | int x; /**< calculated X coordinate */ |
||
367 | int y; /**< calculated Y coordinate */ |
||
368 | |||
369 | float distance; /**< pixel distance between first 2 dots*/ |
||
370 | float z; /**< calculated distance */ |
||
371 | } ir_t; |
||
372 | |||
373 | |||
374 | /** |
||
375 | * @struct joystick_t |
||
376 | * @brief Joystick calibration structure. |
||
377 | * |
||
378 | * The angle \a ang is relative to the positive y-axis into quadrant I |
||
379 | * and ranges from 0 to 360 degrees. So if the joystick is held straight |
||
380 | * upwards then angle is 0 degrees. If it is held to the right it is 90, |
||
381 | * down is 180, and left is 270. |
||
382 | * |
||
383 | * The magnitude \a mag is the distance from the center to where the |
||
384 | * joystick is being held. The magnitude ranges from 0 to 1. |
||
385 | * If the joystick is only slightly tilted from the center the magnitude |
||
386 | * will be low, but if it is closer to the outter edge the value will |
||
387 | * be higher. |
||
388 | */ |
||
389 | typedef struct joystick_t { |
||
390 | struct vec2b_t max; /**< maximum joystick values */ |
||
391 | struct vec2b_t min; /**< minimum joystick values */ |
||
392 | struct vec2b_t center; /**< center joystick values */ |
||
393 | |||
394 | float ang; /**< angle the joystick is being held */ |
||
395 | float mag; /**< magnitude of the joystick (range 0-1) */ |
||
396 | } joystick_t; |
||
397 | |||
398 | |||
399 | /** |
||
400 | * @struct nunchuk_t |
||
401 | * @brief Nunchuk expansion device. |
||
402 | */ |
||
403 | typedef struct nunchuk_t { |
||
404 | struct accel_t accel_calib; /**< nunchuk accelerometer calibration */ |
||
405 | struct joystick_t js; /**< joystick calibration */ |
||
406 | |||
407 | int* flags; /**< options flag (points to wiimote_t.flags) */ |
||
408 | |||
409 | byte btns; /**< what buttons have just been pressed */ |
||
410 | byte btns_held; /**< what buttons are being held down */ |
||
411 | byte btns_released; /**< what buttons were just released this */ |
||
412 | |||
413 | float orient_threshold; /**< threshold for orient to generate an event */ |
||
414 | int accel_threshold; /**< threshold for accel to generate an event */ |
||
415 | |||
416 | struct vec3b_t accel; /**< current raw acceleration data */ |
||
417 | struct orient_t orient; /**< current orientation on each axis */ |
||
418 | struct gforce_t gforce; /**< current gravity forces on each axis */ |
||
419 | } nunchuk_t; |
||
420 | |||
421 | |||
422 | /** |
||
423 | * @struct classic_ctrl_t |
||
424 | * @brief Classic controller expansion device. |
||
425 | */ |
||
426 | typedef struct classic_ctrl_t { |
||
427 | short btns; /**< what buttons have just been pressed */ |
||
428 | short btns_held; /**< what buttons are being held down */ |
||
429 | short btns_released; /**< what buttons were just released this */ |
||
430 | |||
431 | float r_shoulder; /**< right shoulder button (range 0-1) */ |
||
432 | float l_shoulder; /**< left shoulder button (range 0-1) */ |
||
433 | |||
434 | struct joystick_t ljs; /**< left joystick calibration */ |
||
435 | struct joystick_t rjs; /**< right joystick calibration */ |
||
436 | } classic_ctrl_t; |
||
437 | |||
438 | |||
439 | /** |
||
440 | * @struct guitar_hero_3_t |
||
441 | * @brief Guitar Hero 3 expansion device. |
||
442 | */ |
||
443 | typedef struct guitar_hero_3_t { |
||
444 | short btns; /**< what buttons have just been pressed */ |
||
445 | short btns_held; /**< what buttons are being held down */ |
||
446 | short btns_released; /**< what buttons were just released this */ |
||
447 | |||
448 | float whammy_bar; /**< whammy bar (range 0-1) */ |
||
449 | |||
450 | struct joystick_t js; /**< joystick calibration */ |
||
451 | } guitar_hero_3_t; |
||
452 | |||
453 | |||
454 | /** |
||
455 | * @struct expansion_t |
||
456 | * @brief Generic expansion device plugged into wiimote. |
||
457 | */ |
||
458 | typedef struct expansion_t { |
||
459 | int type; /**< type of expansion attached */ |
||
460 | |||
461 | union { |
||
462 | struct nunchuk_t nunchuk; |
||
463 | struct classic_ctrl_t classic; |
||
464 | struct guitar_hero_3_t gh3; |
||
465 | }; |
||
466 | } expansion_t; |
||
467 | |||
468 | |||
469 | /** |
||
470 | * @enum win32_bt_stack_t |
||
471 | * @brief Available bluetooth stacks for Windows. |
||
472 | */ |
||
473 | typedef enum win_bt_stack_t { |
||
474 | WIIUSE_STACK_UNKNOWN, |
||
475 | WIIUSE_STACK_MS, |
||
476 | WIIUSE_STACK_BLUESOLEIL |
||
477 | } win_bt_stack_t; |
||
478 | |||
479 | |||
480 | /** |
||
481 | * @struct wiimote_state_t |
||
482 | * @brief Significant data from the previous event. |
||
483 | */ |
||
484 | typedef struct wiimote_state_t { |
||
485 | /* expansion_t */ |
||
486 | float exp_ljs_ang; |
||
487 | float exp_rjs_ang; |
||
488 | float exp_ljs_mag; |
||
489 | float exp_rjs_mag; |
||
490 | unsigned short exp_btns; |
||
491 | struct orient_t exp_orient; |
||
492 | struct vec3b_t exp_accel; |
||
493 | float exp_r_shoulder; |
||
494 | float exp_l_shoulder; |
||
495 | |||
496 | /* ir_t */ |
||
497 | int ir_ax; |
||
498 | int ir_ay; |
||
499 | float ir_distance; |
||
500 | |||
501 | struct orient_t orient; |
||
502 | unsigned short btns; |
||
503 | |||
504 | struct vec3b_t accel; |
||
505 | } wiimote_state_t; |
||
506 | |||
507 | |||
508 | /** |
||
509 | * @enum WIIUSE_EVENT_TYPE |
||
510 | * @brief Events that wiiuse can generate from a poll. |
||
511 | */ |
||
512 | typedef enum WIIUSE_EVENT_TYPE { |
||
513 | WIIUSE_NONE = 0, |
||
514 | WIIUSE_EVENT, |
||
515 | WIIUSE_STATUS, |
||
516 | WIIUSE_CONNECT, |
||
517 | WIIUSE_DISCONNECT, |
||
518 | WIIUSE_UNEXPECTED_DISCONNECT, |
||
519 | WIIUSE_READ_DATA, |
||
520 | WIIUSE_NUNCHUK_INSERTED, |
||
521 | WIIUSE_NUNCHUK_REMOVED, |
||
522 | WIIUSE_CLASSIC_CTRL_INSERTED, |
||
523 | WIIUSE_CLASSIC_CTRL_REMOVED, |
||
524 | WIIUSE_GUITAR_HERO_3_CTRL_INSERTED, |
||
525 | WIIUSE_GUITAR_HERO_3_CTRL_REMOVED |
||
526 | } WIIUSE_EVENT_TYPE; |
||
527 | |||
528 | /** |
||
529 | * @struct wiimote_t |
||
530 | * @brief Wiimote structure. |
||
531 | */ |
||
532 | typedef struct wiimote_t { |
||
533 | WCONST int unid; /**< user specified id */ |
||
534 | |||
535 | #ifndef WIN32 |
||
536 | WCONST bdaddr_t bdaddr; /**< bt address */ |
||
537 | WCONST char bdaddr_str[18]; /**< readable bt address */ |
||
538 | WCONST int out_sock; /**< output socket */ |
||
539 | WCONST int in_sock; /**< input socket */ |
||
540 | #else |
||
541 | WCONST HANDLE dev_handle; /**< HID handle */ |
||
542 | WCONST OVERLAPPED hid_overlap; /**< overlap handle */ |
||
543 | WCONST enum win_bt_stack_t stack; /**< type of bluetooth stack to use */ |
||
544 | WCONST int timeout; /**< read timeout */ |
||
545 | WCONST byte normal_timeout; /**< normal timeout */ |
||
546 | WCONST byte exp_timeout; /**< timeout for expansion handshake */ |
||
547 | #endif |
||
548 | |||
549 | WCONST int state; /**< various state flags */ |
||
550 | WCONST byte leds; /**< currently lit leds */ |
||
551 | WCONST float battery_level; /**< battery level */ |
||
552 | |||
553 | WCONST int flags; /**< options flag */ |
||
554 | |||
555 | WCONST byte handshake_state; /**< the state of the connection handshake */ |
||
556 | |||
557 | WCONST struct read_req_t* read_req; /**< list of data read requests */ |
||
558 | WCONST struct accel_t accel_calib; /**< wiimote accelerometer calibration */ |
||
559 | WCONST struct expansion_t exp; /**< wiimote expansion device */ |
||
560 | |||
561 | WCONST struct vec3b_t accel; /**< current raw acceleration data */ |
||
562 | WCONST struct orient_t orient; /**< current orientation on each axis */ |
||
563 | WCONST struct gforce_t gforce; /**< current gravity forces on each axis */ |
||
564 | |||
565 | WCONST struct ir_t ir; /**< IR data */ |
||
566 | |||
567 | WCONST unsigned short btns; /**< what buttons have just been pressed */ |
||
568 | WCONST unsigned short btns_held; /**< what buttons are being held down */ |
||
569 | WCONST unsigned short btns_released; /**< what buttons were just released this */ |
||
570 | |||
571 | WCONST float orient_threshold; /**< threshold for orient to generate an event */ |
||
572 | WCONST int accel_threshold; /**< threshold for accel to generate an event */ |
||
573 | |||
574 | WCONST struct wiimote_state_t lstate; /**< last saved state */ |
||
575 | |||
576 | WCONST WIIUSE_EVENT_TYPE event; /**< type of event that occured */ |
||
577 | WCONST byte event_buf[MAX_PAYLOAD]; /**< event buffer */ |
||
578 | } wiimote; |
||
579 | |||
580 | |||
581 | /***************************************** |
||
582 | * |
||
583 | * Include API specific stuff |
||
584 | * |
||
585 | *****************************************/ |
||
586 | |||
587 | #ifdef _WIN32 |
||
588 | #define WIIUSE_EXPORT_DECL __declspec(dllexport) |
||
589 | #define WIIUSE_IMPORT_DECL __declspec(dllimport) |
||
590 | #else |
||
591 | #define WIIUSE_EXPORT_DECL |
||
592 | #define WIIUSE_IMPORT_DECL |
||
593 | #endif |
||
594 | |||
595 | #ifdef WIIUSE_COMPILE_LIB |
||
596 | #define WIIUSE_EXPORT WIIUSE_EXPORT_DECL |
||
597 | #else |
||
598 | #define WIIUSE_EXPORT WIIUSE_IMPORT_DECL |
||
599 | #endif |
||
600 | |||
601 | #ifdef __cplusplus |
||
602 | extern "C" { |
||
603 | #endif |
||
604 | |||
605 | /* wiiuse.c */ |
||
606 | WIIUSE_EXPORT extern const char* wiiuse_version(); |
||
607 | |||
608 | WIIUSE_EXPORT extern struct wiimote_t** wiiuse_init(int wiimotes); |
||
609 | WIIUSE_EXPORT extern void wiiuse_disconnected(struct wiimote_t* wm); |
||
610 | WIIUSE_EXPORT extern void wiiuse_cleanup(struct wiimote_t** wm, int wiimotes); |
||
611 | WIIUSE_EXPORT extern void wiiuse_rumble(struct wiimote_t* wm, int status); |
||
612 | WIIUSE_EXPORT extern void wiiuse_toggle_rumble(struct wiimote_t* wm); |
||
613 | WIIUSE_EXPORT extern void wiiuse_set_leds(struct wiimote_t* wm, int leds); |
||
614 | WIIUSE_EXPORT extern void wiiuse_motion_sensing(struct wiimote_t* wm, int status); |
||
615 | WIIUSE_EXPORT extern int wiiuse_read_data(struct wiimote_t* wm, byte* buffer, unsigned int offset, unsigned short len); |
||
616 | WIIUSE_EXPORT extern int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, byte* data, byte len); |
||
617 | WIIUSE_EXPORT extern void wiiuse_status(struct wiimote_t* wm); |
||
618 | WIIUSE_EXPORT extern struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid); |
||
619 | WIIUSE_EXPORT extern int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable); |
||
620 | WIIUSE_EXPORT extern float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha); |
||
621 | WIIUSE_EXPORT extern void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt_stack_t type); |
||
622 | WIIUSE_EXPORT extern void wiiuse_set_orient_threshold(struct wiimote_t* wm, float threshold); |
||
623 | WIIUSE_EXPORT extern void wiiuse_resync(struct wiimote_t* wm); |
||
624 | WIIUSE_EXPORT extern void wiiuse_set_timeout(struct wiimote_t** wm, int wiimotes, byte normal_timeout, byte exp_timeout); |
||
625 | WIIUSE_EXPORT extern void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold); |
||
626 | |||
627 | /* connect.c */ |
||
628 | WIIUSE_EXPORT extern int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout); |
||
629 | WIIUSE_EXPORT extern int wiiuse_connect(struct wiimote_t** wm, int wiimotes); |
||
630 | WIIUSE_EXPORT extern void wiiuse_disconnect(struct wiimote_t* wm); |
||
631 | |||
632 | /* events.c */ |
||
633 | WIIUSE_EXPORT extern int wiiuse_poll(struct wiimote_t** wm, int wiimotes); |
||
634 | |||
635 | /* ir.c */ |
||
636 | WIIUSE_EXPORT extern void wiiuse_set_ir(struct wiimote_t* wm, int status); |
||
637 | WIIUSE_EXPORT extern void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y); |
||
638 | WIIUSE_EXPORT extern void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos); |
||
639 | WIIUSE_EXPORT extern void wiiuse_set_aspect_ratio(struct wiimote_t* wm, enum aspect_t aspect); |
||
640 | WIIUSE_EXPORT extern void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int level); |
||
641 | |||
642 | /* nunchuk.c */ |
||
643 | WIIUSE_EXPORT extern void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold); |
||
644 | WIIUSE_EXPORT extern void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* wm, int threshold); |
||
645 | |||
646 | |||
647 | #ifdef __cplusplus |
||
648 | } |
||
649 | #endif |
||
650 | |||
651 | |||
652 | #endif /* WIIUSE_H_INCLUDED */ |
||
653 |