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 16
76 #define WIIUSE_MICRO 0
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 #ifndef _WIN32_WINNT
104 #define _WIN32_WINNT 0x0A00
105 #endif
106 #include <windows.h>
107 #endif
108 #ifdef WIIUSE_BLUEZ
109 /* nix */
110 #include <bluetooth/bluetooth.h>
111 #endif
112 #ifdef WIIUSE_BT_EMBEDDED
113 #include <bt-embedded/l2cap.h>
114 #endif
115 
116 #if defined(_MSC_VER) && _MSC_VER < 1700
117 /* MS compilers of pre-VC2010 versions don't have stdint.h
118  * and I can't get VC2010's stdint.h to compile nicely in
119  * WiiUse
120  */
121 #include "wiiuse_msvcstdint.h"
122 #else
123 #include <stdint.h>
124 #endif
125 
126 #include <stdio.h> /* for FILE */
127 
133 #define WIIMOTE_STATE_DEV_FOUND 0x0001
134 #define WIIMOTE_STATE_HANDSHAKE 0x0002 /* actual connection exists but no handshake yet */
135 #define WIIMOTE_STATE_HANDSHAKE_COMPLETE 0x0004 /* actual connection exists but no handshake yet */
136 #define WIIMOTE_STATE_CONNECTED 0x0008
137 #define WIIMOTE_STATE_RUMBLE 0x0010
138 #define WIIMOTE_STATE_ACC 0x0020
139 #define WIIMOTE_STATE_EXP 0x0040
140 #define WIIMOTE_STATE_IR 0x0080
141 #define WIIMOTE_STATE_SPEAKER 0x0100
142 #define WIIMOTE_STATE_IR_SENS_LVL1 0x0200
143 #define WIIMOTE_STATE_IR_SENS_LVL2 0x0400
144 #define WIIMOTE_STATE_IR_SENS_LVL3 0x0800
145 #define WIIMOTE_STATE_IR_SENS_LVL4 0x1000
146 #define WIIMOTE_STATE_IR_SENS_LVL5 0x2000
147 #define WIIMOTE_STATE_EXP_HANDSHAKE 0x10000 /* actual M+ connection exists but no handshake yet */
148 #define WIIMOTE_STATE_EXP_EXTERN 0x20000 /* actual M+ connection exists but handshake failed */
149 #define WIIMOTE_STATE_EXP_FAILED 0x40000 /* actual M+ connection exists but handshake failed */
150 #define WIIMOTE_STATE_MPLUS_PRESENT 0x80000 /* Motion+ is connected */
151 
152 #define WIIMOTE_ID(wm) (wm->unid)
153 
154 #define WIIMOTE_IS_SET(wm, s) ((wm->state & (s)) == (s))
155 #define WIIMOTE_IS_CONNECTED(wm) (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED))
156 
160 #define WIIMOTE_LED_NONE 0x00
161 #define WIIMOTE_LED_1 0x10
162 #define WIIMOTE_LED_2 0x20
163 #define WIIMOTE_LED_3 0x40
164 #define WIIMOTE_LED_4 0x80
165 
169 #define WIIMOTE_BUTTON_TWO 0x0001
170 #define WIIMOTE_BUTTON_ONE 0x0002
171 #define WIIMOTE_BUTTON_B 0x0004
172 #define WIIMOTE_BUTTON_A 0x0008
173 #define WIIMOTE_BUTTON_MINUS 0x0010
174 #define WIIMOTE_BUTTON_YACCEL_LSB 0x0020
175 #define WIIMOTE_BUTTON_ZACCEL_LSB 0x0040
176 #define WIIMOTE_BUTTON_HOME 0x0080
177 #define WIIMOTE_BUTTON_LEFT 0x0100
178 #define WIIMOTE_BUTTON_RIGHT 0x0200
179 #define WIIMOTE_BUTTON_DOWN 0x0400
180 #define WIIMOTE_BUTTON_UP 0x0800
181 #define WIIMOTE_BUTTON_PLUS 0x1000
182 #define WIIMOTE_BUTTON_XACCEL_LSB0 0x2000
183 #define WIIMOTE_BUTTON_XACCEL_LSB1 0x4000
184 #define WIIMOTE_BUTTON_UNKNOWN 0x8000
185 #define WIIMOTE_BUTTON_ALL 0x1F9F
186 
190 #define NUNCHUK_BUTTON_Z 0x01
191 #define NUNCHUK_BUTTON_C 0x02
192 #define NUNCHUK_BUTTON_ALL 0x03
193 
197 #define CLASSIC_CTRL_BUTTON_UP 0x0001
198 #define CLASSIC_CTRL_BUTTON_LEFT 0x0002
199 #define CLASSIC_CTRL_BUTTON_ZR 0x0004
200 #define CLASSIC_CTRL_BUTTON_X 0x0008
201 #define CLASSIC_CTRL_BUTTON_A 0x0010
202 #define CLASSIC_CTRL_BUTTON_Y 0x0020
203 #define CLASSIC_CTRL_BUTTON_B 0x0040
204 #define CLASSIC_CTRL_BUTTON_ZL 0x0080
205 #define CLASSIC_CTRL_BUTTON_FULL_R 0x0200
206 #define CLASSIC_CTRL_BUTTON_PLUS 0x0400
207 #define CLASSIC_CTRL_BUTTON_HOME 0x0800
208 #define CLASSIC_CTRL_BUTTON_MINUS 0x1000
209 #define CLASSIC_CTRL_BUTTON_FULL_L 0x2000
210 #define CLASSIC_CTRL_BUTTON_DOWN 0x4000
211 #define CLASSIC_CTRL_BUTTON_RIGHT 0x8000
212 #define CLASSIC_CTRL_BUTTON_ALL 0xFEFF
213 
217 #define GUITAR_HERO_3_BUTTON_STRUM_UP 0x0001
218 #define GUITAR_HERO_3_BUTTON_YELLOW 0x0008
219 #define GUITAR_HERO_3_BUTTON_GREEN 0x0010
220 #define GUITAR_HERO_3_BUTTON_BLUE 0x0020
221 #define GUITAR_HERO_3_BUTTON_RED 0x0040
222 #define GUITAR_HERO_3_BUTTON_ORANGE 0x0080
223 #define GUITAR_HERO_3_BUTTON_PLUS 0x0400
224 #define GUITAR_HERO_3_BUTTON_MINUS 0x1000
225 #define GUITAR_HERO_3_BUTTON_STRUM_DOWN 0x4000
226 #define GUITAR_HERO_3_BUTTON_ALL 0xFEFF
227 
231 #define TATACON_BUTTON_CENTER_LEFT 0x40
232 #define TATACON_BUTTON_CENTER_RIGHT 0x10
233 #define TATACON_BUTTON_RIM_LEFT 0x20
234 #define TATACON_BUTTON_RIM_RIGHT 0x08
235 #define TATACON_BUTTON_ALL 0x78
236 
240 #define WIIUSE_SMOOTHING 0x01
241 #define WIIUSE_CONTINUOUS 0x02
242 #define WIIUSE_ORIENT_THRESH 0x04
243 #define WIIUSE_INIT_FLAGS (WIIUSE_SMOOTHING | WIIUSE_ORIENT_THRESH)
244 
245 #define WIIUSE_ORIENT_PRECISION 100.0f
246 
250 #define EXP_NONE 0
251 #define EXP_NUNCHUK 1
252 #define EXP_CLASSIC 2
253 #define EXP_GUITAR_HERO_3 3
254 #define EXP_WII_BOARD 4
255 #define EXP_MOTION_PLUS 5
256 #define EXP_MOTION_PLUS_NUNCHUK 6 /* Motion+ in nunchuk pass-through mode */
257 #define EXP_MOTION_PLUS_CLASSIC 7 /* Motion+ in classic ctr. pass-through mode */
258 #define EXP_TATACON 8
259 
262 typedef enum ir_position_t { WIIUSE_IR_ABOVE, WIIUSE_IR_BELOW } ir_position_t;
263 
272 #define IS_PRESSED(dev, button) ((dev->btns & button) == button)
273 
280 #define IS_HELD(dev, button) ((dev->btns_held & button) == button)
281 
291 #define IS_RELEASED(dev, button) ((dev->btns_released & button) == button)
292 
299 #define IS_JUST_PRESSED(dev, button) (IS_PRESSED(dev, button) && !IS_HELD(dev, button))
300 
307 #define WIIUSE_GET_IR_SENSITIVITY(wm, lvl) \
308  do \
309  { \
310  if ((wm->state & 0x0200) == 0x0200) \
311  *lvl = 1; \
312  else if ((wm->state & 0x0400) == 0x0400) \
313  *lvl = 2; \
314  else if ((wm->state & 0x0800) == 0x0800) \
315  *lvl = 3; \
316  else if ((wm->state & 0x1000) == 0x1000) \
317  *lvl = 4; \
318  else if ((wm->state & 0x2000) == 0x2000) \
319  *lvl = 5; \
320  else \
321  *lvl = 0; \
322  } while (0)
323 
324 #define WIIUSE_USING_ACC(wm) ((wm->state & 0x020) == 0x020)
325 #define WIIUSE_USING_EXP(wm) ((wm->state & 0x040) == 0x040)
326 #define WIIUSE_USING_IR(wm) ((wm->state & 0x080) == 0x080)
327 #define WIIUSE_USING_SPEAKER(wm) ((wm->state & 0x100) == 0x100)
328 
329 #define WIIUSE_IS_LED_SET(wm, num) ((wm->leds & WIIMOTE_LED_##num) == WIIMOTE_LED_##num)
330 
332 /*
333  * This is left over from an old hack, but it may actually
334  * be a useful feature to keep so it wasn't removed.
335  */
336 #ifdef WIIUSE_WIN32
337 #define WIIMOTE_DEFAULT_TIMEOUT 10
338 #define WIIMOTE_EXP_TIMEOUT 10
339 #endif
340 
341 #define WIIUSE_SYNC_HANDSHAKE
342 
343 typedef unsigned char byte;
344 typedef char sbyte;
345 
346 struct wiimote_t;
347 struct vec3b_t;
348 struct orient_t;
349 struct gforce_t;
350 
364 typedef void (*wiiuse_read_cb)(struct wiimote_t *wm, byte *data, uint16_t len);
365 
370 {
373  byte *buf;
374  uint32_t addr;
375  uint16_t size;
376  uint16_t wait;
377  byte dirty;
379  struct read_req_t
380  *next;
381 };
382 
387 typedef struct ang3s_t
388 {
389  int16_t roll, pitch, yaw;
390 } ang3s_t;
391 
396 typedef struct ang3f_t
397 {
398  float roll, pitch, yaw;
399 } ang3f_t;
400 
404 typedef struct vec2b_t
405 {
406  byte x, y;
407 } vec2b_t;
408 
412 typedef struct vec3b_t
413 {
414  byte x, y, z;
415 } vec3b_t;
416 
420 typedef struct vec3f_t
421 {
422  float x, y, z;
423 } vec3f_t;
424 
446 typedef struct vec3w_t
447 {
448  uint16_t x, y, z;
449 } vec3w_t;
450 
456 typedef struct orient_t
457 {
458  float roll;
459  float pitch;
460  float yaw;
461 
462  float a_roll;
463  float a_pitch;
464 } orient_t;
465 
469 typedef struct gforce_t
470 {
471  float x, y, z;
472 } gforce_t;
473 
477 typedef struct accel_t
478 {
479  struct vec3b_t cal_zero;
480  struct vec3b_t cal_g;
489  struct vec3b_t cal_zero_lsb;
490  struct vec3b_t cal_g_lsb;
491 
492  float st_roll;
493  float st_pitch;
494  float st_alpha;
495 } accel_t;
496 
500 typedef struct ir_dot_t
501 {
502  byte visible;
504  unsigned int x;
505  unsigned int y;
507  int16_t rx;
508  int16_t ry;
510  byte order;
512  byte size;
513 } ir_dot_t;
514 
518 typedef enum aspect_t { WIIUSE_ASPECT_4_3, WIIUSE_ASPECT_16_9 } aspect_t;
519 
523 typedef struct ir_t
524 {
525  struct ir_dot_t dot[4];
526  byte num_dots;
528  enum aspect_t aspect;
530  enum ir_position_t pos;
532  unsigned int vres[2];
533  int offset[2];
534  int state;
536  int ax;
537  int ay;
539  int x;
540  int y;
542  float distance;
543  float z;
544 } ir_t;
545 
560 typedef struct joystick_t
561 {
562  struct vec2b_t max;
563  struct vec2b_t min;
564  struct vec2b_t center;
566  float ang;
567  float mag;
568  float x;
569  float y;
570 } joystick_t;
571 
575 typedef struct nunchuk_t
576 {
577  struct accel_t accel_calib;
578  struct joystick_t js;
580  int *flags;
582  byte btns;
583  byte btns_held;
589  struct vec3w_t accel;
590  struct orient_t orient;
591  struct gforce_t gforce;
592 } nunchuk_t;
593 
597 typedef struct classic_ctrl_t
598 {
599  int16_t btns;
600  int16_t btns_held;
601  int16_t btns_released;
603  float r_shoulder;
604  float l_shoulder;
606  struct joystick_t ljs;
607  struct joystick_t rjs;
609 
613 typedef struct guitar_hero_3_t
614 {
615  int16_t btns;
616  int16_t btns_held;
617  int16_t btns_released;
619  float whammy_bar;
621  struct joystick_t js;
623 
627 typedef struct motion_plus_t
628 {
629  byte ext;
631  struct ang3s_t raw_gyro;
632  struct ang3s_t cal_gyro;
633  struct ang3f_t angle_rate_gyro;
634  struct orient_t orient;
635  byte acc_mode;
639  struct nunchuk_t *nc;
640  struct classic_ctrl_t *classic;
641 } motion_plus_t;
642 
646 typedef struct tatacon_t
647 {
648  int8_t btns;
649 } tatacon_t;
650 
657 typedef struct wii_board_t
658 {
667  float tl;
668  float tr;
669  float bl;
670  float br;
675  uint16_t rtl;
676  uint16_t rtr;
677  uint16_t rbl;
678  uint16_t rbr;
683  uint16_t ctl[3]; /* Calibration */
684  uint16_t ctr[3];
685  uint16_t cbl[3];
686  uint16_t cbr[3]; /* /Calibration */
688  uint8_t update_calib;
689  uint8_t use_alternate_report;
690 } wii_board_t;
691 
695 typedef struct expansion_t
696 {
697  int type;
699  struct motion_plus_t mp;
700 
701  union
702  {
703  struct nunchuk_t nunchuk;
704  struct classic_ctrl_t classic;
705  struct guitar_hero_3_t gh3;
706  struct wii_board_t wb;
707  struct tatacon_t tatacon;
708  };
709 } expansion_t;
710 
714 typedef enum win_bt_stack_t { WIIUSE_STACK_UNKNOWN, WIIUSE_STACK_MS, WIIUSE_STACK_BLUESOLEIL } win_bt_stack_t;
715 
719 typedef struct wiimote_state_t
720 {
721  /* expansion_t */
722  float exp_ljs_ang;
723  float exp_rjs_ang;
724  float exp_ljs_mag;
725  float exp_rjs_mag;
726  uint16_t exp_btns;
727  struct orient_t exp_orient;
728  struct vec3w_t exp_accel;
729  float exp_r_shoulder;
730  float exp_l_shoulder;
731 
732  /* motion plus */
733  short drx;
734  short dry;
735  short drz;
736 
737  /* wiiboard */
738  uint16_t exp_wb_rtr;
739  uint16_t exp_wb_rtl;
740  uint16_t exp_wb_rbr;
741  uint16_t exp_wb_rbl;
742 
743  /* ir_t */
744  int ir_ax;
745  int ir_ay;
746  float ir_distance;
747 
748  struct orient_t orient;
749  uint16_t btns;
750 
751  struct vec3w_t accel;
753 
757 typedef enum WIIUSE_EVENT_TYPE {
758  WIIUSE_NONE = 0,
759  WIIUSE_EVENT,
760  WIIUSE_STATUS,
761  WIIUSE_CONNECT,
762  WIIUSE_DISCONNECT,
763  WIIUSE_UNEXPECTED_DISCONNECT,
764  WIIUSE_READ_DATA,
765  WIIUSE_WRITE_DATA,
766  WIIUSE_NUNCHUK_INSERTED,
767  WIIUSE_NUNCHUK_REMOVED,
768  WIIUSE_CLASSIC_CTRL_INSERTED,
769  WIIUSE_CLASSIC_CTRL_REMOVED,
770  WIIUSE_GUITAR_HERO_3_CTRL_INSERTED,
771  WIIUSE_GUITAR_HERO_3_CTRL_REMOVED,
772  WIIUSE_WII_BOARD_CTRL_INSERTED,
773  WIIUSE_WII_BOARD_CTRL_REMOVED,
774  WIIUSE_MOTION_PLUS_ACTIVATED,
775  WIIUSE_MOTION_PLUS_REMOVED,
776  WIIUSE_TATACON_CTRL_INSERTED,
777  WIIUSE_TATACON_CTRL_REMOVED
779 
783 typedef enum WIIUSE_WIIMOTE_TYPE {
784  WIIUSE_WIIMOTE_REGULAR = 0,
785  WIIUSE_WIIMOTE_MOTION_PLUS_INSIDE,
787 
793 typedef struct wiimote_t
794 {
795  int unid;
797 #ifdef WIIUSE_BLUEZ
798 
800  char bdaddr_str[18];
801  bdaddr_t bdaddr;
802  int out_sock;
803  int in_sock;
805 #endif
806 
807 #ifdef WIIUSE_BT_EMBEDDED
808 
810  BteBdAddr address;
811  BteL2cap *ctrl_channel;
812  BteL2cap *intr_channel;
813  BteBuffer *incoming_queue;
815 #endif
816 
817 #ifdef WIIUSE_WIN32
818 
820  HANDLE dev_handle;
821  OVERLAPPED hid_overlap;
822  enum win_bt_stack_t stack;
823  int timeout;
824  byte normal_timeout;
825  byte exp_timeout;
827 #endif
828 
829 #ifdef WIIUSE_MAC
830 
832  void *objc_wm;
834 #endif
835 
836  int state;
837  byte leds;
840  int flags;
842 #ifndef WIIUSE_SYNC_HANDSHAKE
843  byte handshake_state;
844 #endif
849  struct accel_t accel_calib;
850  struct expansion_t exp;
852  struct vec3w_t accel;
853  struct orient_t orient;
854  struct gforce_t gforce;
856  struct ir_t ir;
858  uint16_t btns;
859  uint16_t btns_held;
860  uint16_t btns_released;
863  int32_t accel_threshold;
865  struct wiimote_state_t lstate;
868  byte motion_plus_id[6];
869  WIIUSE_WIIMOTE_TYPE type;
870 } wiimote;
871 
874 {
875  int uid;
876  byte leds;
877  float battery_level;
878  struct vec3w_t accel;
879  struct orient_t orient;
880  struct gforce_t gforce;
881  struct ir_t ir;
882  uint16_t buttons;
883  uint16_t buttons_held;
884  uint16_t buttons_released;
885  WIIUSE_EVENT_TYPE event;
886  int state;
887  struct expansion_t expansion;
889 
891 typedef void (*wiiuse_update_cb)(struct wiimote_callback_data_t *wm);
892 
906 typedef void (*wiiuse_write_cb)(struct wiimote_t *wm, unsigned char *data, unsigned short len);
907 
908 typedef enum data_req_s { REQ_READY = 0, REQ_SENT, REQ_DONE } data_req_s;
909 
915 {
916 
917  byte data[21];
918  byte len;
919  unsigned int addr;
920  data_req_s state;
923  struct data_req_t *next;
924 };
925 
929 typedef enum wiiuse_loglevel {
930  LOGLEVEL_ERROR = 0,
931  LOGLEVEL_WARNING = 1,
932  LOGLEVEL_INFO = 2,
933  LOGLEVEL_DEBUG = 3
935 
936 /*****************************************
937  *
938  * Include API specific stuff
939  *
940  *****************************************/
941 
942 #ifdef WIIUSE_WIN32
943 #ifdef WIIUSE_STATIC
944 #define WIIUSE_EXPORT_DECL
945 #define WIIUSE_IMPORT_DECL
946 #else
947 #define WIIUSE_EXPORT_DECL __declspec(dllexport)
948 #define WIIUSE_IMPORT_DECL __declspec(dllimport)
949 #endif
950 #else
951 #define WIIUSE_EXPORT_DECL
952 #define WIIUSE_IMPORT_DECL
953 #endif
954 
955 #ifdef WIIUSE_COMPILE_LIB
956 #define WIIUSE_EXPORT WIIUSE_EXPORT_DECL
957 #else
958 #define WIIUSE_EXPORT WIIUSE_IMPORT_DECL
959 #endif
960 
961 #ifdef __cplusplus
962 extern "C" {
963 #endif
964 
965 /* wiiuse.c */
966 WIIUSE_EXPORT extern const char *wiiuse_version();
967 
971 #define WIIUSE_HAS_OUTPUT_REDIRECTION
972 WIIUSE_EXPORT extern void wiiuse_set_output(enum wiiuse_loglevel loglevel, FILE *logtarget);
973 
974 WIIUSE_EXPORT extern struct wiimote_t **wiiuse_init(int wiimotes);
975 WIIUSE_EXPORT extern void wiiuse_disconnected(struct wiimote_t *wm);
976 WIIUSE_EXPORT extern void wiiuse_cleanup(struct wiimote_t **wm, int wiimotes);
977 WIIUSE_EXPORT extern void wiiuse_rumble(struct wiimote_t *wm, int status);
978 WIIUSE_EXPORT extern void wiiuse_toggle_rumble(struct wiimote_t *wm);
979 WIIUSE_EXPORT extern void wiiuse_set_leds(struct wiimote_t *wm, int leds);
980 WIIUSE_EXPORT extern void wiiuse_motion_sensing(struct wiimote_t *wm, int status);
981 WIIUSE_EXPORT extern int wiiuse_read_data(struct wiimote_t *wm, byte *buffer, unsigned int offset,
982  uint16_t len);
983 WIIUSE_EXPORT extern int wiiuse_write_data(struct wiimote_t *wm, unsigned int addr, const byte *data,
984  byte len);
985 WIIUSE_EXPORT extern void wiiuse_status(struct wiimote_t *wm);
986 WIIUSE_EXPORT extern struct wiimote_t *wiiuse_get_by_id(struct wiimote_t **wm, int wiimotes, int unid);
987 WIIUSE_EXPORT extern int wiiuse_set_flags(struct wiimote_t *wm, int enable, int disable);
988 WIIUSE_EXPORT extern float wiiuse_set_smooth_alpha(struct wiimote_t *wm, float alpha);
989 WIIUSE_EXPORT extern void wiiuse_set_bluetooth_stack(struct wiimote_t **wm, int wiimotes,
990  enum win_bt_stack_t type);
991 WIIUSE_EXPORT extern void wiiuse_set_orient_threshold(struct wiimote_t *wm, float threshold);
992 WIIUSE_EXPORT extern void wiiuse_resync(struct wiimote_t *wm);
993 WIIUSE_EXPORT extern void wiiuse_set_timeout(struct wiimote_t **wm, int wiimotes, byte normal_timeout,
994  byte exp_timeout);
995 WIIUSE_EXPORT extern void wiiuse_set_accel_threshold(struct wiimote_t *wm, int threshold);
996 WIIUSE_EXPORT extern void wiiuse_wiiboard_use_alternate_report(struct wiimote_t *wm, int enabled);
997 
998 /* io.c */
999 WIIUSE_EXPORT extern int wiiuse_find(struct wiimote_t **wm, int max_wiimotes, int timeout);
1000 WIIUSE_EXPORT extern int wiiuse_connect(struct wiimote_t **wm, int wiimotes);
1001 WIIUSE_EXPORT extern void wiiuse_disconnect(struct wiimote_t *wm);
1002 
1003 /* events.c */
1004 WIIUSE_EXPORT extern int wiiuse_poll(struct wiimote_t **wm, int wiimotes);
1005 
1015 WIIUSE_EXPORT extern int wiiuse_update(struct wiimote_t **wm, int wiimotes, wiiuse_update_cb callback);
1016 
1017 /* ir.c */
1018 WIIUSE_EXPORT extern void wiiuse_set_ir(struct wiimote_t *wm, int status);
1019 WIIUSE_EXPORT extern void wiiuse_set_ir_vres(struct wiimote_t *wm, unsigned int x, unsigned int y);
1020 WIIUSE_EXPORT extern void wiiuse_set_ir_position(struct wiimote_t *wm, enum ir_position_t pos);
1021 WIIUSE_EXPORT extern void wiiuse_set_aspect_ratio(struct wiimote_t *wm, enum aspect_t aspect);
1022 WIIUSE_EXPORT extern void wiiuse_set_ir_sensitivity(struct wiimote_t *wm, int level);
1023 
1024 /* nunchuk.c */
1025 WIIUSE_EXPORT extern void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t *wm, float threshold);
1026 WIIUSE_EXPORT extern void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t *wm, int threshold);
1027 
1028 /* wiiboard.c */
1029 WIIUSE_EXPORT extern void wiiuse_set_wii_board_calib(struct wiimote_t *wm);
1030 
1031 WIIUSE_EXPORT extern void wiiuse_set_motion_plus(struct wiimote_t *wm, int status);
1032 
1033 #ifdef __cplusplus
1034 }
1035 #endif
1036 
1039 #endif /* WIIUSE_H_INCLUDED */
int x
calculated X coordinate
Definition: wiiuse.h:539
WIIUSE_EXPORT void wiiuse_status(struct wiimote_t *wm)
Request the wiimote controller status.
Definition: wiiuse.c:536
Nunchuk expansion device.
Definition: wiiuse.h:575
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:77
uint16_t btns_held
what buttons are being held down
Definition: wiiuse.h:859
Significant data from the previous event.
Definition: wiiuse.h:719
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:568
float orient_threshold
threshold for orient to generate an event
Definition: wiiuse.h:586
float pitch
pitch, this may be smoothed if enabled
Definition: wiiuse.h:459
uint32_t addr
the offset that the read started at
Definition: wiiuse.h:374
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:502
Main Wiimote device structure.
Definition: wiiuse.h:793
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:846
int32_t accel_threshold
threshold for accel to generate an event
Definition: wiiuse.h:863
Accelerometer struct.
Definition: wiiuse.h:477
WIIUSE_EVENT_TYPE
Events that wiiuse can generate from a poll.
Definition: wiiuse.h:757
A single IR source.
Definition: wiiuse.h:500
int type
type of expansion attached
Definition: wiiuse.h:697
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:492
wiiuse_read_cb cb
read data callback
Definition: wiiuse.h:371
int16_t btns_held
what buttons are being held down
Definition: wiiuse.h:600
float st_alpha
alpha value for smoothing [0-1]
Definition: wiiuse.h:494
wiiuse_write_cb cb
read data callback
Definition: wiiuse.h:921
Roll/Pitch/Yaw short angles.
Definition: wiiuse.h:387
struct nunchuk_t * nc
pointers to nunchuk & classic in pass-through-mode
Definition: wiiuse.h:639
float roll
roll, this may be smoothed if enabled
Definition: wiiuse.h:458
byte order
increasing order by x-axis value
Definition: wiiuse.h:510
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:379
struct nunchuk_t nunchuk_t
Nunchuk expansion device.
byte num_dots
number of dots at this time
Definition: wiiuse.h:526
uint16_t size
the length of the data read
Definition: wiiuse.h:375
int16_t btns
what buttons have just been pressed
Definition: wiiuse.h:615
float distance
pixel distance between first 2 dots
Definition: wiiuse.h:542
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:587
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:913
struct wiimote_callback_data_t wiimote_callback_data_t
Data passed to a callback during wiiuse_update()
Motion Plus expansion device.
Definition: wiiuse.h:627
void(* wiiuse_update_cb)(struct wiimote_callback_data_t *wm)
Callback type.
Definition: wiiuse.h:891
int y
calculated Y coordinate
Definition: wiiuse.h:540
uint16_t btns
what buttons have just been pressed
Definition: wiiuse.h:858
float whammy_bar
whammy bar (range 0-1)
Definition: wiiuse.h:619
uint16_t btns_released
what buttons were just released this
Definition: wiiuse.h:860
float st_pitch
last smoothed roll pitch
Definition: wiiuse.h:493
int16_t ry
raw Y coordinate (0-767)
Definition: wiiuse.h:508
data_req_s state
set to 1 if not using callback and needs to be cleaned up
Definition: wiiuse.h:920
int * flags
options flag (points to wiimote_t.flags)
Definition: wiiuse.h:580
ir_position_t
IR correction types.
Definition: wiiuse.h:262
struct read_req_t * read_req
list of data read requests
Definition: wiiuse.h:848
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:534
Unsigned x,y byte vector.
Definition: wiiuse.h:404
int16_t btns_released
what buttons were just released this
Definition: wiiuse.h:601
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.
Unsigned x,y,z 16-bit vector.
Definition: wiiuse.h:446
Classic controller expansion device.
Definition: wiiuse.h:597
Tatacon expansion device.
Definition: wiiuse.h:646
Gravity force struct.
Definition: wiiuse.h:469
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:949
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:929
WIIUSE_EXPORT float wiiuse_set_smooth_alpha(struct wiimote_t *wm, float alpha)
Set the wiimote smoothing alpha value.
Definition: wiiuse.c:825
byte * buf
buffer where read data is written
Definition: wiiuse.h:373
byte dirty
set to 1 if not using callback and needs to be cleaned up
Definition: wiiuse.h:377
void(* wiiuse_read_cb)(struct wiimote_t *wm, byte *data, uint16_t len)
Callback that handles a read event.
Definition: wiiuse.h:364
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:783
int16_t rx
raw X coordinate (0-1023)
Definition: wiiuse.h:507
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:462
Guitar Hero 3 expansion device.
Definition: wiiuse.h:613
byte acc_mode
Fast/slow rotation mode for roll, pitch and yaw (0 if rotating fast, 1 if slow or still) ...
Definition: wiiuse.h:635
int8_t btns
what buttons have just been pressed
Definition: wiiuse.h:648
Data passed to a callback during wiiuse_update()
Definition: wiiuse.h:873
IR struct.
Definition: wiiuse.h:523
struct ir_dot_t ir_dot_t
A single IR source.
Orientation struct.
Definition: wiiuse.h:456
byte btns_released
what buttons were just released this
Definition: wiiuse.h:584
WIIUSE_EXPORT int wiiuse_find(struct wiimote_t **wm, int max_wiimotes, int timeout)
Find a wiimote or wiimotes.
Definition: io.c:66
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:617
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:629
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:202
WIIUSE_EXPORT void wiiuse_set_orient_threshold(struct wiimote_t *wm, float threshold)
Set the orientation event threshold.
Definition: wiiuse.c:881
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:795
void(* wiiuse_write_cb)(struct wiimote_t *wm, unsigned char *data, unsigned short len)
Callback that handles a write event.
Definition: wiiuse.h:906
unsigned int x
interpolated X coordinate
Definition: wiiuse.h:504
Data read request structure.
Definition: wiiuse.h:369
byte btns_held
what buttons are being held down
Definition: wiiuse.h:583
float battery_level
battery level
Definition: wiiuse.h:838
int ax
absolute X coordinate
Definition: wiiuse.h:536
float mag
magnitude of the joystick (range 0-1)
Definition: wiiuse.h:567
struct tatacon_t tatacon_t
Tatacon expansion device.
Generic expansion device plugged into wiimote.
Definition: wiiuse.h:695
byte leds
currently lit leds
Definition: wiiuse.h:837
int raw_gyro_threshold
threshold for gyroscopes to generate an event
Definition: wiiuse.h:637
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:109
Roll/Pitch/Yaw float angles.
Definition: wiiuse.h:396
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:897
float y
vertical position of the joystick (range [-1, 1]
Definition: wiiuse.h:569
int state
various state flags
Definition: wiiuse.h:836
int flags
options flag
Definition: wiiuse.h:840
int16_t btns_held
what buttons are being held down
Definition: wiiuse.h:616
float a_pitch
absolute pitch, unsmoothed
Definition: wiiuse.h:463
Data write request structure.
Definition: wiiuse.h:914
byte size
size of the IR dot (0-15)
Definition: wiiuse.h:512
WIIUSE_EXPORT int wiiuse_set_flags(struct wiimote_t *wm, int enable, int disable)
Set flags for the specified wiimote.
Definition: wiiuse.c:795
Wii Balance Board "expansion" device.
Definition: wiiuse.h:657
float l_shoulder
left shoulder button (range 0-1)
Definition: wiiuse.h:604
struct vec3w_t vec3w_t
Unsigned x,y,z 16-bit vector.
Unsigned x,y,z byte vector.
Definition: wiiuse.h:412
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:599
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:854
unsigned int y
interpolated Y coordinate
Definition: wiiuse.h:505
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:867
float ang
angle the joystick is being held
Definition: wiiuse.h:566
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:75
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:537
aspect_t
Screen aspect ratio.
Definition: wiiuse.h:518
Signed x,y,z float struct.
Definition: wiiuse.h:420
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:603
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:92
win_bt_stack_t
Available bluetooth stacks for Windows.
Definition: wiiuse.h:714
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:928
uint16_t wait
num bytes still needed to finish read
Definition: wiiuse.h:376
Joystick calibration structure.
Definition: wiiuse.h:560
float z
calculated distance
Definition: wiiuse.h:543
byte btns
what buttons have just been pressed
Definition: wiiuse.h:582
byte expansion_state
the state of the expansion handshake
Definition: wiiuse.h:845
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:220
float orient_threshold
threshold for orient to generate an event
Definition: wiiuse.h:862