wiiuse
wiiuse.h
Go to the documentation of this file.
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  * Mac fields based on wiic_structs.h from WiiC, written By:
11  * Gabriele Randelli
12  * Email: < randelli (--AT--) dis [--DOT--] uniroma1 [--DOT--] it >
13  *
14  * Copyright 2010
15  *
16  * This file is part of wiiuse.
17  *
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program. If not, see <http://www.gnu.org/licenses/>.
30  *
31  * $Header$
32  *
33  */
34 
71 #ifndef WIIUSE_H_INCLUDED
72 #define WIIUSE_H_INCLUDED
73 
74 #define WIIUSE_MAJOR 0
75 #define WIIUSE_MINOR 15
76 #define WIIUSE_MICRO 7
77 
78 #define WIIUSE_VERSION_TRANSFORM(MAJ, MIN, MICRO) (MAJ * 1000000 + MIN * 1000 + MICRO)
79 #define WIIUSE_HAS_VERSION(MAJ, MIN, MICRO) \
80  (WIIUSE_VERSION_TRANSFORM(MAJ, MIN, MICRO) \
81  <= WIIUSE_VERSION_TRANSFORM(WIIUSE_MAJOR, WIIUSE_MINOR, WIIUSE_MICRO))
82 
83 #ifndef WIIUSE_PLATFORM
84 #if defined(_WIN32)
85 #define WIIUSE_PLATFORM
86 #define WIIUSE_WIN32
87 #elif defined(__linux)
88 #define WIIUSE_PLATFORM
89 #define WIIUSE_BLUEZ
90 #elif defined(__APPLE__)
91 #define WIIUSE_PLATFORM
92 #define WIIUSE_MAC
93 #else
94 #error "Platform not yet supported!"
95 #endif
96 #endif
97 
98 #ifdef WIIUSE_WIN32
99 /* windows */
100 #ifndef WIN32_LEAN_AND_MEAN
101 #define WIN32_LEAN_AND_MEAN 1
102 #endif
103 #include <windows.h>
104 #endif
105 #ifdef WIIUSE_BLUEZ
106 /* nix */
107 #include <bluetooth/bluetooth.h>
108 #endif
109 
110 #if defined(_MSC_VER) && _MSC_VER < 1700
111 /* MS compilers of pre-VC2010 versions don't have stdint.h
112  * and I can't get VC2010's stdint.h to compile nicely in
113  * WiiUse
114  */
115 #include "wiiuse_msvcstdint.h"
116 #else
117 #include <stdint.h>
118 #endif
119 
120 #include <stdio.h> /* for FILE */
121 
127 #define WIIMOTE_STATE_DEV_FOUND 0x0001
128 #define WIIMOTE_STATE_HANDSHAKE 0x0002 /* actual connection exists but no handshake yet */
129 #define WIIMOTE_STATE_HANDSHAKE_COMPLETE 0x0004 /* actual connection exists but no handshake yet */
130 #define WIIMOTE_STATE_CONNECTED 0x0008
131 #define WIIMOTE_STATE_RUMBLE 0x0010
132 #define WIIMOTE_STATE_ACC 0x0020
133 #define WIIMOTE_STATE_EXP 0x0040
134 #define WIIMOTE_STATE_IR 0x0080
135 #define WIIMOTE_STATE_SPEAKER 0x0100
136 #define WIIMOTE_STATE_IR_SENS_LVL1 0x0200
137 #define WIIMOTE_STATE_IR_SENS_LVL2 0x0400
138 #define WIIMOTE_STATE_IR_SENS_LVL3 0x0800
139 #define WIIMOTE_STATE_IR_SENS_LVL4 0x1000
140 #define WIIMOTE_STATE_IR_SENS_LVL5 0x2000
141 #define WIIMOTE_STATE_EXP_HANDSHAKE 0x10000 /* actual M+ connection exists but no handshake yet */
142 #define WIIMOTE_STATE_EXP_EXTERN 0x20000 /* actual M+ connection exists but handshake failed */
143 #define WIIMOTE_STATE_EXP_FAILED 0x40000 /* actual M+ connection exists but handshake failed */
144 #define WIIMOTE_STATE_MPLUS_PRESENT 0x80000 /* Motion+ is connected */
145 
146 #define WIIMOTE_ID(wm) (wm->unid)
147 
148 #define WIIMOTE_IS_SET(wm, s) ((wm->state & (s)) == (s))
149 #define WIIMOTE_IS_CONNECTED(wm) (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED))
150 
154 #define WIIMOTE_LED_NONE 0x00
155 #define WIIMOTE_LED_1 0x10
156 #define WIIMOTE_LED_2 0x20
157 #define WIIMOTE_LED_3 0x40
158 #define WIIMOTE_LED_4 0x80
159 
163 #define WIIMOTE_BUTTON_TWO 0x0001
164 #define WIIMOTE_BUTTON_ONE 0x0002
165 #define WIIMOTE_BUTTON_B 0x0004
166 #define WIIMOTE_BUTTON_A 0x0008
167 #define WIIMOTE_BUTTON_MINUS 0x0010
168 #define WIIMOTE_BUTTON_ZACCEL_BIT6 0x0020
169 #define WIIMOTE_BUTTON_ZACCEL_BIT7 0x0040
170 #define WIIMOTE_BUTTON_HOME 0x0080
171 #define WIIMOTE_BUTTON_LEFT 0x0100
172 #define WIIMOTE_BUTTON_RIGHT 0x0200
173 #define WIIMOTE_BUTTON_DOWN 0x0400
174 #define WIIMOTE_BUTTON_UP 0x0800
175 #define WIIMOTE_BUTTON_PLUS 0x1000
176 #define WIIMOTE_BUTTON_ZACCEL_BIT4 0x2000
177 #define WIIMOTE_BUTTON_ZACCEL_BIT5 0x4000
178 #define WIIMOTE_BUTTON_UNKNOWN 0x8000
179 #define WIIMOTE_BUTTON_ALL 0x1F9F
180 
184 #define NUNCHUK_BUTTON_Z 0x01
185 #define NUNCHUK_BUTTON_C 0x02
186 #define NUNCHUK_BUTTON_ALL 0x03
187 
191 #define CLASSIC_CTRL_BUTTON_UP 0x0001
192 #define CLASSIC_CTRL_BUTTON_LEFT 0x0002
193 #define CLASSIC_CTRL_BUTTON_ZR 0x0004
194 #define CLASSIC_CTRL_BUTTON_X 0x0008
195 #define CLASSIC_CTRL_BUTTON_A 0x0010
196 #define CLASSIC_CTRL_BUTTON_Y 0x0020
197 #define CLASSIC_CTRL_BUTTON_B 0x0040
198 #define CLASSIC_CTRL_BUTTON_ZL 0x0080
199 #define CLASSIC_CTRL_BUTTON_FULL_R 0x0200
200 #define CLASSIC_CTRL_BUTTON_PLUS 0x0400
201 #define CLASSIC_CTRL_BUTTON_HOME 0x0800
202 #define CLASSIC_CTRL_BUTTON_MINUS 0x1000
203 #define CLASSIC_CTRL_BUTTON_FULL_L 0x2000
204 #define CLASSIC_CTRL_BUTTON_DOWN 0x4000
205 #define CLASSIC_CTRL_BUTTON_RIGHT 0x8000
206 #define CLASSIC_CTRL_BUTTON_ALL 0xFEFF
207 
211 #define GUITAR_HERO_3_BUTTON_STRUM_UP 0x0001
212 #define GUITAR_HERO_3_BUTTON_YELLOW 0x0008
213 #define GUITAR_HERO_3_BUTTON_GREEN 0x0010
214 #define GUITAR_HERO_3_BUTTON_BLUE 0x0020
215 #define GUITAR_HERO_3_BUTTON_RED 0x0040
216 #define GUITAR_HERO_3_BUTTON_ORANGE 0x0080
217 #define GUITAR_HERO_3_BUTTON_PLUS 0x0400
218 #define GUITAR_HERO_3_BUTTON_MINUS 0x1000
219 #define GUITAR_HERO_3_BUTTON_STRUM_DOWN 0x4000
220 #define GUITAR_HERO_3_BUTTON_ALL 0xFEFF
221 
225 #define TATACON_BUTTON_CENTER_LEFT 0x40
226 #define TATACON_BUTTON_CENTER_RIGHT 0x10
227 #define TATACON_BUTTON_RIM_LEFT 0x20
228 #define TATACON_BUTTON_RIM_RIGHT 0x08
229 #define TATACON_BUTTON_ALL 0x78
230 
234 #define WIIUSE_SMOOTHING 0x01
235 #define WIIUSE_CONTINUOUS 0x02
236 #define WIIUSE_ORIENT_THRESH 0x04
237 #define WIIUSE_INIT_FLAGS (WIIUSE_SMOOTHING | WIIUSE_ORIENT_THRESH)
238 
239 #define WIIUSE_ORIENT_PRECISION 100.0f
240 
244 #define EXP_NONE 0
245 #define EXP_NUNCHUK 1
246 #define EXP_CLASSIC 2
247 #define EXP_GUITAR_HERO_3 3
248 #define EXP_WII_BOARD 4
249 #define EXP_MOTION_PLUS 5
250 #define EXP_MOTION_PLUS_NUNCHUK 6 /* Motion+ in nunchuk pass-through mode */
251 #define EXP_MOTION_PLUS_CLASSIC 7 /* Motion+ in classic ctr. pass-through mode */
252 #define EXP_TATACON 8
253 
256 typedef enum ir_position_t { WIIUSE_IR_ABOVE, WIIUSE_IR_BELOW } ir_position_t;
257 
266 #define IS_PRESSED(dev, button) ((dev->btns & button) == button)
267 
274 #define IS_HELD(dev, button) ((dev->btns_held & button) == button)
275 
285 #define IS_RELEASED(dev, button) ((dev->btns_released & button) == button)
286 
293 #define IS_JUST_PRESSED(dev, button) (IS_PRESSED(dev, button) && !IS_HELD(dev, button))
294 
301 #define WIIUSE_GET_IR_SENSITIVITY(wm, lvl) \
302  do \
303  { \
304  if ((wm->state & 0x0200) == 0x0200) \
305  *lvl = 1; \
306  else if ((wm->state & 0x0400) == 0x0400) \
307  *lvl = 2; \
308  else if ((wm->state & 0x0800) == 0x0800) \
309  *lvl = 3; \
310  else if ((wm->state & 0x1000) == 0x1000) \
311  *lvl = 4; \
312  else if ((wm->state & 0x2000) == 0x2000) \
313  *lvl = 5; \
314  else \
315  *lvl = 0; \
316  } while (0)
317 
318 #define WIIUSE_USING_ACC(wm) ((wm->state & 0x020) == 0x020)
319 #define WIIUSE_USING_EXP(wm) ((wm->state & 0x040) == 0x040)
320 #define WIIUSE_USING_IR(wm) ((wm->state & 0x080) == 0x080)
321 #define WIIUSE_USING_SPEAKER(wm) ((wm->state & 0x100) == 0x100)
322 
323 #define WIIUSE_IS_LED_SET(wm, num) ((wm->leds & WIIMOTE_LED_##num) == WIIMOTE_LED_##num)
324 
326 /*
327  * This is left over from an old hack, but it may actually
328  * be a useful feature to keep so it wasn't removed.
329  */
330 #ifdef WIIUSE_WIN32
331 #define WIIMOTE_DEFAULT_TIMEOUT 10
332 #define WIIMOTE_EXP_TIMEOUT 10
333 #endif
334 
335 #define WIIUSE_SYNC_HANDSHAKE
336 
337 typedef unsigned char byte;
338 typedef char sbyte;
339 
340 struct wiimote_t;
341 struct vec3b_t;
342 struct orient_t;
343 struct gforce_t;
344 
358 typedef void (*wiiuse_read_cb)(struct wiimote_t *wm, byte *data, uint16_t len);
359 
364 {
367  byte *buf;
368  uint32_t addr;
369  uint16_t size;
370  uint16_t wait;
371  byte dirty;
373  struct read_req_t
374  *next;
375 };
376 
381 typedef struct ang3s_t
382 {
383  int16_t roll, pitch, yaw;
384 } ang3s_t;
385 
390 typedef struct ang3f_t
391 {
392  float roll, pitch, yaw;
393 } ang3f_t;
394 
398 typedef struct vec2b_t
399 {
400  byte x, y;
401 } vec2b_t;
402 
406 typedef struct vec3b_t
407 {
408  byte x, y, z;
409 } vec3b_t;
410 
414 typedef struct vec3f_t
415 {
416  float x, y, z;
417 } vec3f_t;
418 
424 typedef struct orient_t
425 {
426  float roll;
427  float pitch;
428  float yaw;
429 
430  float a_roll;
431  float a_pitch;
432 } orient_t;
433 
437 typedef struct gforce_t
438 {
439  float x, y, z;
440 } gforce_t;
441 
445 typedef struct accel_t
446 {
447  struct vec3b_t cal_zero;
448  struct vec3b_t cal_g;
450  float st_roll;
451  float st_pitch;
452  float st_alpha;
453 } accel_t;
454 
458 typedef struct ir_dot_t
459 {
460  byte visible;
462  unsigned int x;
463  unsigned int y;
465  int16_t rx;
466  int16_t ry;
468  byte order;
470  byte size;
471 } ir_dot_t;
472 
476 typedef enum aspect_t { WIIUSE_ASPECT_4_3, WIIUSE_ASPECT_16_9 } aspect_t;
477 
481 typedef struct ir_t
482 {
483  struct ir_dot_t dot[4];
484  byte num_dots;
486  enum aspect_t aspect;
488  enum ir_position_t pos;
490  unsigned int vres[2];
491  int offset[2];
492  int state;
494  int ax;
495  int ay;
497  int x;
498  int y;
500  float distance;
501  float z;
502 } ir_t;
503 
518 typedef struct joystick_t
519 {
520  struct vec2b_t max;
521  struct vec2b_t min;
522  struct vec2b_t center;
524  float ang;
525  float mag;
526  float x;
527  float y;
528 } joystick_t;
529 
533 typedef struct nunchuk_t
534 {
535  struct accel_t accel_calib;
536  struct joystick_t js;
538  int *flags;
540  byte btns;
541  byte btns_held;
547  struct vec3b_t accel;
548  struct orient_t orient;
549  struct gforce_t gforce;
550 } nunchuk_t;
551 
555 typedef struct classic_ctrl_t
556 {
557  int16_t btns;
558  int16_t btns_held;
559  int16_t btns_released;
561  float r_shoulder;
562  float l_shoulder;
564  struct joystick_t ljs;
565  struct joystick_t rjs;
567 
571 typedef struct guitar_hero_3_t
572 {
573  int16_t btns;
574  int16_t btns_held;
575  int16_t btns_released;
577  float whammy_bar;
579  struct joystick_t js;
581 
585 typedef struct motion_plus_t
586 {
587  byte ext;
589  struct ang3s_t raw_gyro;
590  struct ang3s_t cal_gyro;
591  struct ang3f_t angle_rate_gyro;
592  struct orient_t orient;
593  byte acc_mode;
597  struct nunchuk_t *nc;
598  struct classic_ctrl_t *classic;
599 } motion_plus_t;
600 
604 typedef struct tatacon_t
605 {
606  int8_t btns;
607 } tatacon_t;
608 
615 typedef struct wii_board_t
616 {
625  float tl;
626  float tr;
627  float bl;
628  float br;
633  uint16_t rtl;
634  uint16_t rtr;
635  uint16_t rbl;
636  uint16_t rbr;
641  uint16_t ctl[3]; /* Calibration */
642  uint16_t ctr[3];
643  uint16_t cbl[3];
644  uint16_t cbr[3]; /* /Calibration */
646  uint8_t update_calib;
647  uint8_t use_alternate_report;
648 } wii_board_t;
649 
653 typedef struct expansion_t
654 {
655  int type;
657  struct motion_plus_t mp;
658 
659  union
660  {
661  struct nunchuk_t nunchuk;
662  struct classic_ctrl_t classic;
663  struct guitar_hero_3_t gh3;
664  struct wii_board_t wb;
665  struct tatacon_t tatacon;
666  };
667 } expansion_t;
668 
672 typedef enum win_bt_stack_t { WIIUSE_STACK_UNKNOWN, WIIUSE_STACK_MS, WIIUSE_STACK_BLUESOLEIL } win_bt_stack_t;
673 
677 typedef struct wiimote_state_t
678 {
679  /* expansion_t */
680  float exp_ljs_ang;
681  float exp_rjs_ang;
682  float exp_ljs_mag;
683  float exp_rjs_mag;
684  uint16_t exp_btns;
685  struct orient_t exp_orient;
686  struct vec3b_t exp_accel;
687  float exp_r_shoulder;
688  float exp_l_shoulder;
689 
690  /* motion plus */
691  short drx;
692  short dry;
693  short drz;
694 
695  /* wiiboard */
696  uint16_t exp_wb_rtr;
697  uint16_t exp_wb_rtl;
698  uint16_t exp_wb_rbr;
699  uint16_t exp_wb_rbl;
700 
701  /* ir_t */
702  int ir_ax;
703  int ir_ay;
704  float ir_distance;
705 
706  struct orient_t orient;
707  uint16_t btns;
708 
709  struct vec3b_t accel;
711 
715 typedef enum WIIUSE_EVENT_TYPE {
716  WIIUSE_NONE = 0,
717  WIIUSE_EVENT,
718  WIIUSE_STATUS,
719  WIIUSE_CONNECT,
720  WIIUSE_DISCONNECT,
721  WIIUSE_UNEXPECTED_DISCONNECT,
722  WIIUSE_READ_DATA,
723  WIIUSE_WRITE_DATA,
724  WIIUSE_NUNCHUK_INSERTED,
725  WIIUSE_NUNCHUK_REMOVED,
726  WIIUSE_CLASSIC_CTRL_INSERTED,
727  WIIUSE_CLASSIC_CTRL_REMOVED,
728  WIIUSE_GUITAR_HERO_3_CTRL_INSERTED,
729  WIIUSE_GUITAR_HERO_3_CTRL_REMOVED,
730  WIIUSE_WII_BOARD_CTRL_INSERTED,
731  WIIUSE_WII_BOARD_CTRL_REMOVED,
732  WIIUSE_MOTION_PLUS_ACTIVATED,
733  WIIUSE_MOTION_PLUS_REMOVED,
734  WIIUSE_TATACON_CTRL_INSERTED,
735  WIIUSE_TATACON_CTRL_REMOVED
737 
741 typedef enum WIIUSE_WIIMOTE_TYPE {
742  WIIUSE_WIIMOTE_REGULAR = 0,
743  WIIUSE_WIIMOTE_MOTION_PLUS_INSIDE,
745 
751 typedef struct wiimote_t
752 {
753  int unid;
755 #ifdef WIIUSE_BLUEZ
756 
758  char bdaddr_str[18];
759  bdaddr_t bdaddr;
760  int out_sock;
761  int in_sock;
763 #endif
764 
765 #ifdef WIIUSE_WIN32
766 
768  HANDLE dev_handle;
769  OVERLAPPED hid_overlap;
770  enum win_bt_stack_t stack;
771  int timeout;
772  byte normal_timeout;
773  byte exp_timeout;
775 #endif
776 
777 #ifdef WIIUSE_MAC
778 
780  void *objc_wm;
782 #endif
783 
784  int state;
785  byte leds;
788  int flags;
790 #ifndef WIIUSE_SYNC_HANDSHAKE
791  byte handshake_state;
792 #endif
797  struct accel_t accel_calib;
798  struct expansion_t exp;
800  struct vec3b_t accel;
801  struct orient_t orient;
802  struct gforce_t gforce;
804  struct ir_t ir;
806  uint16_t btns;
807  uint16_t btns_held;
808  uint16_t btns_released;
811  int32_t accel_threshold;
813  struct wiimote_state_t lstate;
816  byte motion_plus_id[6];
817  WIIUSE_WIIMOTE_TYPE type;
818 } wiimote;
819 
822 {
823  int uid;
824  byte leds;
825  float battery_level;
826  struct vec3b_t accel;
827  struct orient_t orient;
828  struct gforce_t gforce;
829  struct ir_t ir;
830  uint16_t buttons;
831  uint16_t buttons_held;
832  uint16_t buttons_released;
833  WIIUSE_EVENT_TYPE event;
834  int state;
835  struct expansion_t expansion;
837 
839 typedef void (*wiiuse_update_cb)(struct wiimote_callback_data_t *wm);
840 
854 typedef void (*wiiuse_write_cb)(struct wiimote_t *wm, unsigned char *data, unsigned short len);
855 
856 typedef enum data_req_s { REQ_READY = 0, REQ_SENT, REQ_DONE } data_req_s;
857 
863 {
864 
865  byte data[21];
866  byte len;
867  unsigned int addr;
868  data_req_s state;
871  struct data_req_t *next;
872 };
873 
877 typedef enum wiiuse_loglevel {
878  LOGLEVEL_ERROR = 0,
879  LOGLEVEL_WARNING = 1,
880  LOGLEVEL_INFO = 2,
881  LOGLEVEL_DEBUG = 3
883 
884 /*****************************************
885  *
886  * Include API specific stuff
887  *
888  *****************************************/
889 
890 #ifdef WIIUSE_WIN32
891 #ifdef WIIUSE_STATIC
892 #define WIIUSE_EXPORT_DECL
893 #define WIIUSE_IMPORT_DECL
894 #else
895 #define WIIUSE_EXPORT_DECL __declspec(dllexport)
896 #define WIIUSE_IMPORT_DECL __declspec(dllimport)
897 #endif
898 #else
899 #define WIIUSE_EXPORT_DECL
900 #define WIIUSE_IMPORT_DECL
901 #endif
902 
903 #ifdef WIIUSE_COMPILE_LIB
904 #define WIIUSE_EXPORT WIIUSE_EXPORT_DECL
905 #else
906 #define WIIUSE_EXPORT WIIUSE_IMPORT_DECL
907 #endif
908 
909 #ifdef __cplusplus
910 extern "C" {
911 #endif
912 
913 /* wiiuse.c */
914 WIIUSE_EXPORT extern const char *wiiuse_version();
915 
919 #define WIIUSE_HAS_OUTPUT_REDIRECTION
920 WIIUSE_EXPORT extern void wiiuse_set_output(enum wiiuse_loglevel loglevel, FILE *logtarget);
921 
922 WIIUSE_EXPORT extern struct wiimote_t **wiiuse_init(int wiimotes);
923 WIIUSE_EXPORT extern void wiiuse_disconnected(struct wiimote_t *wm);
924 WIIUSE_EXPORT extern void wiiuse_cleanup(struct wiimote_t **wm, int wiimotes);
925 WIIUSE_EXPORT extern void wiiuse_rumble(struct wiimote_t *wm, int status);
926 WIIUSE_EXPORT extern void wiiuse_toggle_rumble(struct wiimote_t *wm);
927 WIIUSE_EXPORT extern void wiiuse_set_leds(struct wiimote_t *wm, int leds);
928 WIIUSE_EXPORT extern void wiiuse_motion_sensing(struct wiimote_t *wm, int status);
929 WIIUSE_EXPORT extern int wiiuse_read_data(struct wiimote_t *wm, byte *buffer, unsigned int offset,
930  uint16_t len);
931 WIIUSE_EXPORT extern int wiiuse_write_data(struct wiimote_t *wm, unsigned int addr, const byte *data,
932  byte len);
933 WIIUSE_EXPORT extern void wiiuse_status(struct wiimote_t *wm);
934 WIIUSE_EXPORT extern struct wiimote_t *wiiuse_get_by_id(struct wiimote_t **wm, int wiimotes, int unid);
935 WIIUSE_EXPORT extern int wiiuse_set_flags(struct wiimote_t *wm, int enable, int disable);
936 WIIUSE_EXPORT extern float wiiuse_set_smooth_alpha(struct wiimote_t *wm, float alpha);
937 WIIUSE_EXPORT extern void wiiuse_set_bluetooth_stack(struct wiimote_t **wm, int wiimotes,
938  enum win_bt_stack_t type);
939 WIIUSE_EXPORT extern void wiiuse_set_orient_threshold(struct wiimote_t *wm, float threshold);
940 WIIUSE_EXPORT extern void wiiuse_resync(struct wiimote_t *wm);
941 WIIUSE_EXPORT extern void wiiuse_set_timeout(struct wiimote_t **wm, int wiimotes, byte normal_timeout,
942  byte exp_timeout);
943 WIIUSE_EXPORT extern void wiiuse_set_accel_threshold(struct wiimote_t *wm, int threshold);
944 WIIUSE_EXPORT extern void wiiuse_wiiboard_use_alternate_report(struct wiimote_t *wm, int enabled);
945 
946 /* io.c */
947 WIIUSE_EXPORT extern int wiiuse_find(struct wiimote_t **wm, int max_wiimotes, int timeout);
948 WIIUSE_EXPORT extern int wiiuse_connect(struct wiimote_t **wm, int wiimotes);
949 WIIUSE_EXPORT extern void wiiuse_disconnect(struct wiimote_t *wm);
950 
951 /* events.c */
952 WIIUSE_EXPORT extern int wiiuse_poll(struct wiimote_t **wm, int wiimotes);
953 
963 WIIUSE_EXPORT extern int wiiuse_update(struct wiimote_t **wm, int wiimotes, wiiuse_update_cb callback);
964 
965 /* ir.c */
966 WIIUSE_EXPORT extern void wiiuse_set_ir(struct wiimote_t *wm, int status);
967 WIIUSE_EXPORT extern void wiiuse_set_ir_vres(struct wiimote_t *wm, unsigned int x, unsigned int y);
968 WIIUSE_EXPORT extern void wiiuse_set_ir_position(struct wiimote_t *wm, enum ir_position_t pos);
969 WIIUSE_EXPORT extern void wiiuse_set_aspect_ratio(struct wiimote_t *wm, enum aspect_t aspect);
970 WIIUSE_EXPORT extern void wiiuse_set_ir_sensitivity(struct wiimote_t *wm, int level);
971 
972 /* nunchuk.c */
973 WIIUSE_EXPORT extern void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t *wm, float threshold);
974 WIIUSE_EXPORT extern void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t *wm, int threshold);
975 
976 /* wiiboard.c */
977 WIIUSE_EXPORT extern void wiiuse_set_wii_board_calib(struct wiimote_t *wm);
978 
979 WIIUSE_EXPORT extern void wiiuse_set_motion_plus(struct wiimote_t *wm, int status);
980 
981 #ifdef __cplusplus
982 }
983 #endif
984 
987 #endif /* WIIUSE_H_INCLUDED */
int x
calculated X coordinate
Definition: wiiuse.h:497
WIIUSE_EXPORT void wiiuse_status(struct wiimote_t *wm)
Request the wiimote controller status.
Definition: wiiuse.c:536
Nunchuk expansion device.
Definition: wiiuse.h:533
WIIUSE_EXPORT int wiiuse_update(struct wiimote_t **wm, int wiimotes, wiiuse_update_cb callback)
Poll Wiimotes, and call the provided callback with information on each Wiimote that had an event...
Definition: events.c:78
uint16_t btns_held
what buttons are being held down
Definition: wiiuse.h:807
Significant data from the previous event.
Definition: wiiuse.h:677
struct wii_board_t wii_board_t
Wii Balance Board "expansion" device.
float x
horizontal position of the joystick (range [-1, 1]
Definition: wiiuse.h:526
float orient_threshold
threshold for orient to generate an event
Definition: wiiuse.h:544
float pitch
pitch, this may be smoothed if enabled
Definition: wiiuse.h:427
uint32_t addr
the offset that the read started at
Definition: wiiuse.h:368
WIIUSE_EXPORT void wiiuse_set_aspect_ratio(struct wiimote_t *wm, enum aspect_t aspect)
Set the aspect ratio of the TV/monitor.
Definition: ir.c:298
struct ir_t ir_t
IR struct.
WIIUSE_EXPORT void wiiuse_set_ir_vres(struct wiimote_t *wm, unsigned int x, unsigned int y)
Set the virtual screen resolution for IR tracking.
Definition: ir.c:233
byte visible
if the IR source is visible
Definition: wiiuse.h:460
Main Wiimote device structure.
Definition: wiiuse.h:751
struct motion_plus_t motion_plus_t
Motion Plus expansion device.
struct data_req_t * data_req
list of data read requests
Definition: wiiuse.h:794
int32_t accel_threshold
threshold for accel to generate an event
Definition: wiiuse.h:811
Accelerometer struct.
Definition: wiiuse.h:445
WIIUSE_EVENT_TYPE
Events that wiiuse can generate from a poll.
Definition: wiiuse.h:715
A single IR source.
Definition: wiiuse.h:458
int type
type of expansion attached
Definition: wiiuse.h:655
WIIUSE_EXPORT void wiiuse_set_leds(struct wiimote_t *wm, int leds)
Set the enabled LEDs.
Definition: wiiuse.c:267
float st_roll
last smoothed roll value
Definition: wiiuse.h:450
wiiuse_read_cb cb
read data callback
Definition: wiiuse.h:365
int16_t btns_held
what buttons are being held down
Definition: wiiuse.h:558
float st_alpha
alpha value for smoothing [0-1]
Definition: wiiuse.h:452
wiiuse_write_cb cb
read data callback
Definition: wiiuse.h:869
Roll/Pitch/Yaw short angles.
Definition: wiiuse.h:381
struct nunchuk_t * nc
pointers to nunchuk & classic in pass-through-mode
Definition: wiiuse.h:597
float roll
roll, this may be smoothed if enabled
Definition: wiiuse.h:426
byte order
increasing order by x-axis value
Definition: wiiuse.h:468
struct expansion_t expansion_t
Generic expansion device plugged into wiimote.
WIIUSE_EXPORT void wiiuse_motion_sensing(struct wiimote_t *wm, int status)
Set if the wiimote should report motion sensing.
Definition: wiiuse.c:300
struct read_req_t * next
next read request in the queue
Definition: wiiuse.h:373
struct nunchuk_t nunchuk_t
Nunchuk expansion device.
byte num_dots
number of dots at this time
Definition: wiiuse.h:484
uint16_t size
the length of the data read
Definition: wiiuse.h:369
int16_t btns
what buttons have just been pressed
Definition: wiiuse.h:573
float distance
pixel distance between first 2 dots
Definition: wiiuse.h:500
WIIUSE_EXPORT void wiiuse_cleanup(struct wiimote_t **wm, int wiimotes)
Clean up wiimote_t array created by wiiuse_init()
Definition: wiiuse.c:73
int accel_threshold
threshold for accel to generate an event
Definition: wiiuse.h:545
struct gforce_t gforce_t
Gravity force struct.
WIIUSE_EXPORT void wiiuse_wiiboard_use_alternate_report(struct wiimote_t *wm, int enabled)
Switch the Balance Board to use report 0x34 instead of 0x32.
Definition: wiiuse.c:908
struct wiimote_callback_data_t wiimote_callback_data_t
Data passed to a callback during wiiuse_update()
Motion Plus expansion device.
Definition: wiiuse.h:585
void(* wiiuse_update_cb)(struct wiimote_callback_data_t *wm)
Callback type.
Definition: wiiuse.h:839
int y
calculated Y coordinate
Definition: wiiuse.h:498
uint16_t btns
what buttons have just been pressed
Definition: wiiuse.h:806
float whammy_bar
whammy bar (range 0-1)
Definition: wiiuse.h:577
uint16_t btns_released
what buttons were just released this
Definition: wiiuse.h:808
float st_pitch
last smoothed roll pitch
Definition: wiiuse.h:451
int16_t ry
raw Y coordinate (0-767)
Definition: wiiuse.h:466
data_req_s state
set to 1 if not using callback and needs to be cleaned up
Definition: wiiuse.h:868
int * flags
options flag (points to wiimote_t.flags)
Definition: wiiuse.h:538
ir_position_t
IR correction types.
Definition: wiiuse.h:256
struct read_req_t * read_req
list of data read requests
Definition: wiiuse.h:796
struct guitar_hero_3_t guitar_hero_3_t
Guitar Hero 3 expansion device.
int state
keeps track of the IR state
Definition: wiiuse.h:492
Unsigned x,y byte vector.
Definition: wiiuse.h:398
int16_t btns_released
what buttons were just released this
Definition: wiiuse.h:559
WIIUSE_EXPORT struct wiimote_t * wiiuse_get_by_id(struct wiimote_t **wm, int wiimotes, int unid)
Find a wiimote_t structure by its unique identifier.
Definition: wiiuse.c:559
struct classic_ctrl_t classic_ctrl_t
Classic controller expansion device.
Classic controller expansion device.
Definition: wiiuse.h:555
Tatacon expansion device.
Definition: wiiuse.h:604
Gravity force struct.
Definition: wiiuse.h:437
WIIUSE_EXPORT void wiiuse_set_timeout(struct wiimote_t **wm, int wiimotes, byte normal_timeout, byte exp_timeout)
Set the normal and expansion handshake timeouts.
Definition: wiiuse.c:944
WIIUSE_EXPORT struct wiimote_t ** wiiuse_init(int wiimotes)
Initialize an array of wiimote structures.
Definition: wiiuse.c:108
wiiuse_loglevel
Loglevels supported by wiiuse.
Definition: wiiuse.h:877
WIIUSE_EXPORT float wiiuse_set_smooth_alpha(struct wiimote_t *wm, float alpha)
Set the wiimote smoothing alpha value.
Definition: wiiuse.c:820
byte * buf
buffer where read data is written
Definition: wiiuse.h:367
byte dirty
set to 1 if not using callback and needs to be cleaned up
Definition: wiiuse.h:371
void(* wiiuse_read_cb)(struct wiimote_t *wm, byte *data, uint16_t len)
Callback that handles a read event.
Definition: wiiuse.h:358
WIIUSE_EXPORT void wiiuse_disconnected(struct wiimote_t *wm)
The wiimote disconnected.
Definition: wiiuse.c:179
struct vec3f_t vec3f_t
Signed x,y,z float struct.
struct orient_t orient_t
Orientation struct.
WIIUSE_WIIMOTE_TYPE
Type of wiimote peripheral.
Definition: wiiuse.h:741
int16_t rx
raw X coordinate (0-1023)
Definition: wiiuse.h:465
struct vec2b_t vec2b_t
Unsigned x,y byte vector.
WIIUSE_EXPORT void wiiuse_set_ir_sensitivity(struct wiimote_t *wm, int level)
Set the IR sensitivity.
Definition: ir.c:330
WIIUSE_EXPORT void wiiuse_rumble(struct wiimote_t *wm, int status)
Enable or disable the rumble.
Definition: wiiuse.c:211
float a_roll
absolute roll, unsmoothed
Definition: wiiuse.h:430
Guitar Hero 3 expansion device.
Definition: wiiuse.h:571
byte acc_mode
Fast/slow rotation mode for roll, pitch and yaw (0 if rotating fast, 1 if slow or still) ...
Definition: wiiuse.h:593
int8_t btns
what buttons have just been pressed
Definition: wiiuse.h:606
Data passed to a callback during wiiuse_update()
Definition: wiiuse.h:821
IR struct.
Definition: wiiuse.h:481
struct ir_dot_t ir_dot_t
A single IR source.
Orientation struct.
Definition: wiiuse.h:424
byte btns_released
what buttons were just released this
Definition: wiiuse.h:542
WIIUSE_EXPORT int wiiuse_find(struct wiimote_t **wm, int max_wiimotes, int timeout)
Find a wiimote or wiimotes.
Definition: io.c:65
struct wiimote_state_t wiimote_state_t
Significant data from the previous event.
int16_t btns_released
what buttons were just released this
Definition: wiiuse.h:575
WIIUSE_EXPORT int wiiuse_read_data(struct wiimote_t *wm, byte *buffer, unsigned int offset, uint16_t len)
Read data from the wiimote (event version).
Definition: wiiuse.c:480
byte ext
is there a device on the pass-through port?
Definition: wiiuse.h:587
WIIUSE_EXPORT void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t *wm, float threshold)
Set the orientation event threshold for the nunchuk.
Definition: nunchuk.c:189
WIIUSE_EXPORT void wiiuse_set_orient_threshold(struct wiimote_t *wm, float threshold)
Set the orientation event threshold.
Definition: wiiuse.c:876
WIIUSE_EXPORT void wiiuse_set_ir_position(struct wiimote_t *wm, enum ir_position_t pos)
Set the XY position for the IR cursor.
Definition: ir.c:249
int unid
user specified id
Definition: wiiuse.h:753
void(* wiiuse_write_cb)(struct wiimote_t *wm, unsigned char *data, unsigned short len)
Callback that handles a write event.
Definition: wiiuse.h:854
unsigned int x
interpolated X coordinate
Definition: wiiuse.h:462
Data read request structure.
Definition: wiiuse.h:363
byte btns_held
what buttons are being held down
Definition: wiiuse.h:541
float battery_level
battery level
Definition: wiiuse.h:786
int ax
absolute X coordinate
Definition: wiiuse.h:494
float mag
magnitude of the joystick (range 0-1)
Definition: wiiuse.h:525
struct tatacon_t tatacon_t
Tatacon expansion device.
Generic expansion device plugged into wiimote.
Definition: wiiuse.h:653
byte leds
currently lit leds
Definition: wiiuse.h:785
int raw_gyro_threshold
threshold for gyroscopes to generate an event
Definition: wiiuse.h:595
WIIUSE_EXPORT void wiiuse_set_motion_plus(struct wiimote_t *wm, int status)
Enable/disable Motion+ expansion.
Definition: motion_plus.c:177
struct vec3b_t vec3b_t
Unsigned x,y,z byte vector.
WIIUSE_EXPORT void wiiuse_disconnect(struct wiimote_t *wm)
Disconnect a wiimote.
Definition: io.c:108
Roll/Pitch/Yaw float angles.
Definition: wiiuse.h:390
WIIUSE_EXPORT void wiiuse_set_wii_board_calib(struct wiimote_t *wm)
Calib wii board.
Definition: wiiboard.c:168
WIIUSE_EXPORT void wiiuse_set_accel_threshold(struct wiimote_t *wm, int threshold)
Set the accelerometer event threshold.
Definition: wiiuse.c:892
float y
vertical position of the joystick (range [-1, 1]
Definition: wiiuse.h:527
int state
various state flags
Definition: wiiuse.h:784
int flags
options flag
Definition: wiiuse.h:788
int16_t btns_held
what buttons are being held down
Definition: wiiuse.h:574
float a_pitch
absolute pitch, unsmoothed
Definition: wiiuse.h:431
Data write request structure.
Definition: wiiuse.h:862
byte size
size of the IR dot (0-15)
Definition: wiiuse.h:470
WIIUSE_EXPORT int wiiuse_set_flags(struct wiimote_t *wm, int enable, int disable)
Set flags for the specified wiimote.
Definition: wiiuse.c:790
Wii Balance Board "expansion" device.
Definition: wiiuse.h:615
float l_shoulder
left shoulder button (range 0-1)
Definition: wiiuse.h:562
Unsigned x,y,z byte vector.
Definition: wiiuse.h:406
WIIUSE_EXPORT void wiiuse_set_output(enum wiiuse_loglevel loglevel, FILE *logtarget)
Specify an alternate FILE stream for a log level.
Definition: wiiuse.c:68
int16_t btns
what buttons have just been pressed
Definition: wiiuse.h:557
WIIUSE_EXPORT void wiiuse_set_bluetooth_stack(struct wiimote_t **wm, int wiimotes, enum win_bt_stack_t type)
Set the bluetooth stack type to use.
Definition: wiiuse.c:849
unsigned int y
interpolated Y coordinate
Definition: wiiuse.h:463
WIIUSE_EXPORT int wiiuse_write_data(struct wiimote_t *wm, unsigned int addr, const byte *data, byte len)
Write data to the wiimote.
Definition: wiiuse.c:590
struct wiimote_t wiimote
Main Wiimote device structure.
WIIUSE_EVENT_TYPE event
type of event that occurred
Definition: wiiuse.h:815
float ang
angle the joystick is being held
Definition: wiiuse.h:524
WIIUSE_EXPORT const char * wiiuse_version()
Returns the version of the library.
Definition: wiiuse.c:52
WIIUSE_EXPORT int wiiuse_poll(struct wiimote_t **wm, int wiimotes)
Poll the wiimotes for any events.
Definition: events.c:76
WIIUSE_EXPORT void wiiuse_set_ir(struct wiimote_t *wm, int status)
Set if the wiimote should track IR targets.
Definition: ir.c:87
WIIUSE_EXPORT void wiiuse_toggle_rumble(struct wiimote_t *wm)
Toggle the state of the rumble.
Definition: wiiuse.c:249
int ay
absolute Y coordinate
Definition: wiiuse.h:495
aspect_t
Screen aspect ratio.
Definition: wiiuse.h:476
Signed x,y,z float struct.
Definition: wiiuse.h:414
FILE * logtarget[]
Output FILE stream for each wiiuse_loglevel.
Definition: wiiuse.c:57
float r_shoulder
right shoulder button (range 0-1)
Definition: wiiuse.h:561
struct accel_t accel_t
Accelerometer struct.
WIIUSE_EXPORT int wiiuse_connect(struct wiimote_t **wm, int wiimotes)
Connect to a wiimote or wiimotes once an address is known.
Definition: io.c:91
win_bt_stack_t
Available bluetooth stacks for Windows.
Definition: wiiuse.h:672
struct joystick_t joystick_t
Joystick calibration structure.
WIIUSE_EXPORT void wiiuse_resync(struct wiimote_t *wm)
Try to resync with the wiimote by starting a new handshake.
Definition: wiiuse.c:923
uint16_t wait
num bytes still needed to finish read
Definition: wiiuse.h:370
Joystick calibration structure.
Definition: wiiuse.h:518
float z
calculated distance
Definition: wiiuse.h:501
byte btns
what buttons have just been pressed
Definition: wiiuse.h:540
byte expansion_state
the state of the expansion handshake
Definition: wiiuse.h:793
WIIUSE_EXPORT void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t *wm, int threshold)
Set the accelerometer event threshold for the nunchuk.
Definition: nunchuk.c:207
float orient_threshold
threshold for orient to generate an event
Definition: wiiuse.h:810