1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
|
{$IFDEF OGC_INTERFACE}
type
ir_position_t = integer;
data_req_s = integer;
cmd_blk_s = integer;
aspect_t = integer;
win_bt_stack_t = integer;
WIIUSE_EVENT_TYPE = integer;
ubyte = cuchar;
Pubyte = ^ubyte;
sbyte = cchar;
uword = cushort;
sword = cshort;
uint = cuint;
sint = cchar;
const
WIIMOTE_LED_NONE = $00;
WIIMOTE_LED_1 = $10;
WIIMOTE_LED_2 = $20;
WIIMOTE_LED_3 = $40;
WIIMOTE_LED_4 = $80;
WIIMOTE_BUTTON_TWO = $0001;
WIIMOTE_BUTTON_ONE = $0002;
WIIMOTE_BUTTON_B = $0004;
WIIMOTE_BUTTON_A = $0008;
WIIMOTE_BUTTON_MINUS = $0010;
WIIMOTE_BUTTON_ZACCEL_BIT6 = $0020;
WIIMOTE_BUTTON_ZACCEL_BIT7 = $0040;
WIIMOTE_BUTTON_HOME = $0080;
WIIMOTE_BUTTON_LEFT = $0100;
WIIMOTE_BUTTON_RIGHT = $0200;
WIIMOTE_BUTTON_DOWN = $0400;
WIIMOTE_BUTTON_UP = $0800;
WIIMOTE_BUTTON_PLUS = $1000;
WIIMOTE_BUTTON_ZACCEL_BIT4 = $2000;
WIIMOTE_BUTTON_ZACCEL_BIT5 = $4000;
WIIMOTE_BUTTON_UNKNOWN = $8000;
WIIMOTE_BUTTON_ALL = $1F9F;
NUNCHUK_BUTTON_Z = $01;
NUNCHUK_BUTTON_C = $02;
NUNCHUK_BUTTON_ALL = $03;
CLASSIC_CTRL_BUTTON_UP = $0001;
CLASSIC_CTRL_BUTTON_LEFT = $0002;
CLASSIC_CTRL_BUTTON_ZR = $0004;
CLASSIC_CTRL_BUTTON_X = $0008;
CLASSIC_CTRL_BUTTON_A = $0010;
CLASSIC_CTRL_BUTTON_Y = $0020;
CLASSIC_CTRL_BUTTON_B = $0040;
CLASSIC_CTRL_BUTTON_ZL = $0080;
CLASSIC_CTRL_BUTTON_FULL_R = $0200;
CLASSIC_CTRL_BUTTON_PLUS = $0400;
CLASSIC_CTRL_BUTTON_HOME = $0800;
CLASSIC_CTRL_BUTTON_MINUS = $1000;
CLASSIC_CTRL_BUTTON_FULL_L = $2000;
CLASSIC_CTRL_BUTTON_DOWN = $4000;
CLASSIC_CTRL_BUTTON_RIGHT = $8000;
CLASSIC_CTRL_BUTTON_ALL = $FEFF;
GUITAR_HERO_3_BUTTON_STRUM_UP = $0001;
GUITAR_HERO_3_BUTTON_YELLOW = $0008;
GUITAR_HERO_3_BUTTON_GREEN = $0010;
GUITAR_HERO_3_BUTTON_BLUE = $0020;
GUITAR_HERO_3_BUTTON_RED = $0040;
GUITAR_HERO_3_BUTTON_ORANGE = $0080;
GUITAR_HERO_3_BUTTON_PLUS = $0400;
GUITAR_HERO_3_BUTTON_MINUS = $1000;
GUITAR_HERO_3_BUTTON_STRUM_DOWN = $4000;
GUITAR_HERO_3_BUTTON_ALL = $FEFF;
GUITAR_HERO_3_TOUCH_AVAILABLE = $1000;
GUITAR_HERO_3_TOUCH_GREEN = $1001;
GUITAR_HERO_3_TOUCH_RED = $1002;
GUITAR_HERO_3_TOUCH_YELLOW = $1004;
GUITAR_HERO_3_TOUCH_BLUE = $1008;
GUITAR_HERO_3_TOUCH_ORANGE = $1010;
WIIUSE_SMOOTHING = $01;
WIIUSE_CONTINUOUS = $02;
WIIUSE_ACCEL_THRESH = $04;
WIIUSE_IR_THRESH = $08;
WIIUSE_JS_THRESH = $10;
WIIUSE_INIT_FLAGS = WIIUSE_SMOOTHING;
WIIUSE_ORIENT_PRECISION = 100.0;
EXP_NONE = 0;
EXP_NUNCHUK = 1;
EXP_CLASSIC = 2;
EXP_GUITAR_HERO_3 = 3;
EXP_WII_BOARD = 4;
EXP_MOTION_PLUS = 5;
MAX_PAYLOAD = 32;
WIIUSE_IR_ABOVE: ir_position_t = 0;
WIIUSE_IR_BELOW: ir_position_t = 1;
REQ_READY: data_req_s = 0;
REQ_SENT: data_req_s = 1;
REQ_DONE: data_req_s = 2;
CMD_READY: cmd_blk_s = 0;
CMD_SENT: cmd_blk_s = 1;
CMD_DONE: cmd_blk_s = 2;
WIIUSE_ASPECT_4_3: aspect_t = 0;
WIIUSE_ASPECT_16_9: aspect_t = 1;
WIIUSE_STACK_UNKNOWN: win_bt_stack_t = 0;
WIIUSE_STACK_MS: win_bt_stack_t = 1;
WIIUSE_STACK_BLUESOLEIL: win_bt_stack_t = 2;
WIIUSE_NONE: WIIUSE_EVENT_TYPE = 0;
WIIUSE_EVENT: WIIUSE_EVENT_TYPE = 1;
_WIIUSE_STATUS: WIIUSE_EVENT_TYPE = 2;
_WIIUSE_CONNECT: WIIUSE_EVENT_TYPE = 3;
_WIIUSE_DISCONNECT: WIIUSE_EVENT_TYPE = 4;
WIIUSE_UNEXPECTED_DISCONNECT: WIIUSE_EVENT_TYPE = 5;
_WIIUSE_READ_DATA: WIIUSE_EVENT_TYPE = 6;
WIIUSE_ACK: WIIUSE_EVENT_TYPE = 7;
WIIUSE_NUNCHUK_INSERTED: WIIUSE_EVENT_TYPE = 8;
WIIUSE_NUNCHUK_REMOVED: WIIUSE_EVENT_TYPE = 9;
WIIUSE_CLASSIC_CTRL_INSERTED: WIIUSE_EVENT_TYPE = 10;
WIIUSE_CLASSIC_CTRL_REMOVED: WIIUSE_EVENT_TYPE = 11;
WIIUSE_GUITAR_HERO_3_CTRL_INSERTED: WIIUSE_EVENT_TYPE = 12;
WIIUSE_GUITAR_HERO_3_CTRL_REMOVED: WIIUSE_EVENT_TYPE = 13;
WIIUSE_WII_BOARD_INSERTED: WIIUSE_EVENT_TYPE = 14;
WIIUSE_WII_BOARD_REMOVED: WIIUSE_EVENT_TYPE = 15;
WIIUSE_MOTION_PLUS_ACTIVATED: WIIUSE_EVENT_TYPE = 16;
WIIUSE_MOTION_PLUS_REMOVED: WIIUSE_EVENT_TYPE = 17;
//struct wiimote_t;
//struct vec3b_t;
//struct orient_t;
//struct gforce_t;
type
Pwiimote_t = ^wiimote_t;
{ $ifdef GEKKO}
wii_event_cb = procedure(par0: Pwiimote_t; event: cint); cdecl;
pwii_event_cb = ^wii_event_cb;
{ $endif}
wiiuse_data_cb = procedure(wm: Pwiimote_t; data: Pubyte; len: cushort); cdecl;
Pdata_req_t = ^data_req_t;
data_req_t = packed record
node : lwp_node;
data : array [0..47] of ubyte; (**< buffer where read data is written *)
len : cuint;
state : data_req_s; (**< set to 1 if not using callback and needs to be cleaned up *)
cb : wiiuse_data_cb; (**< read data callback *)
next : Pdata_req_t;
end;
cmd_blk_cb = procedure(wm: Pwiimote_t; data: Pubyte; len: uword); cdecl;
Pcmd_blk_t = ^cmd_blk_t;
cmd_blk_t = packed record
node : lwp_node;
data : array [0..47] of ubyte;
len : uint;
state : cmd_blk_s;
cb : cmd_blk_cb;
next : Pcmd_blk_t;
end;
vec2b_t = packed record
x : ubyte;
y : ubyte;
end;
pvec2b_t = ^vec2b_t;
vec3b_t = packed record
x : ubyte;
y : ubyte;
z : ubyte;
end;
pvec3b_t = ^vec3b_t;
vec3w_t = packed record
x : uword;
y : uword;
z : uword;
end;
pvec3w_t = ^vec3w_t;
vec3f_t = packed record
x : cfloat;
y : cfloat;
z : cfloat;
end;
pvec3f_t = ^vec3f_t;
orient_t = packed record
roll : cfloat; (**< roll, this may be smoothed if enabled *)
pitch : cfloat; (**< pitch, this may be smoothed if enabled *)
yaw : cfloat;
a_roll : cfloat; (**< absolute roll, unsmoothed *)
a_pitch : cfloat; (**< absolute pitch, unsmoothed *)
end;
porient_t =^orient_t;
gforce_t = packed record
x : cfloat;
y : cfloat;
z : cfloat;
end;
pgforce_t = ^gforce_t;
accel_t = packed record
cal_zero : vec3w_t; (**< zero calibration *)
cal_g : vec3w_t; (**< 1g difference around 0cal *)
st_roll : cfloat; (**< last smoothed roll value *)
st_pitch : cfloat; (**< last smoothed roll pitch *)
st_alpha : cfloat; (**< alpha value for smoothing [0-1] *)
end;
paccel_t = ^accel_t;
ir_dot_t = packed record
visible : ubyte; (**< if the IR source is visible *)
rx : cshort; (**< raw X coordinate (0-1023) *)
ry : cshort; (**< raw Y coordinate (0-767) *)
size : ubyte; (**< size of the IR dot (0-15) *)
end;
pir_dot_t = ^ir_dot_t;
fdot_t = packed record
x : cfloat;
y : cfloat;
end;
pfdot_t = ^fdot_t;
sb_t = packed record
dots : array [0..1] of fdot_t;
acc_dots : array [0..1] of fdot_t;
rot_dots : array [0..1] of fdot_t;
angle : cfloat;
off_angle : cfloat;
score : cfloat;
end;
psb_t = ^sb_t;
ir_t = packed record
dot : array [0..3] of ir_dot_t; (**< IR dots *)
num_dots : ubyte; (**< number of dots at this time *)
state : cint; (**< keeps track of the IR state *)
raw_valid : cint; (**< is the raw position valid? *)
sensorbar : sb_t; (**< sensor bar, detected or guessed *)
ax : cfloat; (**< raw X coordinate *)
ay : cfloat; (**< raw Y coordinate *)
distance : cfloat; (**< pixel width of the sensor bar *)
z : cfloat; (**< calculated distance in meters *)
angle : cfloat; (**< angle of the wiimote to the sensor bar *)
smooth_valid : cint; (**< is the smoothed position valid? *)
sx : cfloat; (**< smoothed X coordinate *)
sy : cfloat; (**< smoothed Y coordinate *)
error_cnt : cfloat; (**< error count, for smoothing algorithm *)
glitch_cnt : cfloat; (**< glitch count, same *)
valid : cint; (**< is the bounded position valid? *)
x : cfloat; (**< bounded X coordinate *)
y : cfloat; (**< bounded Y coordinate *)
aspect : aspect_t; (**< aspect ratio of the screen *)
pos : ir_position_t; (**< IR sensor bar position *)
vres : array [0..1] of cuint; (**< IR virtual screen resolution *)
offset : array [0..1] of cint; (**< IR XY correction offset *)
end;
pir_t = ^ir_t;
joystick_t = packed record
max : vec2b_t; (**< maximum joystick values *)
min : vec2b_t; (**< minimum joystick values *)
center : vec2b_t; (**< center joystick values *)
pos : vec2b_t; (**< raw position values *)
ang : cfloat; (**< angle the joystick is being held *)
mag : cfloat; (**< magnitude of the joystick (range 0-1) *)
end;
pjoystick_t = ^joystick_t;
nunchuk_t = packed record
accel_calib : accel_t; (**< nunchuk accelerometer calibration *)
js : joystick_t; (**< joystick calibration *)
flags : pcint; (**< options flag (points to wiimote_t.flags) *)
btns : ubyte; (**< what buttons have just been pressed *)
btns_last : ubyte; (**< what buttons have just been pressed *)
btns_held : ubyte; (**< what buttons are being held down *)
btns_released : ubyte; (**< what buttons were just released this *)
accel : vec3w_t; (**< current raw acceleration data *)
orient : orient_t; (**< current orientation on each axis *)
gforce : gforce_t; (**< current gravity forces on each axis *)
end;
pnunchuk_t = ^nunchuk_t;
classic_ctrl_t = packed record
btns : cshort; (**< what buttons have just been pressed *)
btns_last : cshort; (**< what buttons have just been pressed *)
btns_held : cshort; (**< what buttons are being held down *)
btns_released : cshort; (**< what buttons were just released this *)
rs_raw : ubyte;
ls_raw : ubyte;
r_shoulder : cfloat; (**< right shoulder button (range 0-1) *)
l_shoulder : cfloat; (**< left shoulder button (range 0-1) *)
ljs : joystick_t; (**< left joystick calibration *)
rjs : joystick_t; (**< right joystick calibration *)
end;
pclassic_ctrl_t = ^classic_ctrl_t;
guitar_hero_3_t = packed record
btns : cshort; (**< what buttons have just been pressed *)
btns_last : cshort; (**< what buttons have just been pressed *)
btns_held : cshort; (**< what buttons are being held down *)
btns_released : cshort; (**< what buttons were just released this *)
wb_raw : ubyte;
whammy_bar : cfloat; (**< whammy bar (range 0-1) *)
tb_raw : ubyte;
touch_bar : cint; (**< touch bar *)
js : joystick_t; (**< joystick calibration *)
end;
pguitar_hero_3_t = ^guitar_hero_3_t;
wii_board_t = packed record
tl : cfloat; (* Interpolated *)
tr : cfloat;
bl : cfloat;
br : cfloat; (* End interp *)
rtl : cshort; (* RAW *)
rtr : cshort;
rbl : cshort;
rbr : cshort; (* /RAW *)
ctl : array [0..2] of cshort; (* Calibration *)
ctr : array [0..2] of cshort;
cbl : array [0..2] of cshort;
cbr : array [0..2] of cshort; (* /Calibration *)
x : cfloat;
y : cfloat;
end;
pwii_board_t = ^wii_board_t;
motion_plus_t = packed record
rx : cshort;
ry : cshort;
rz : cshort;
status : ubyte;
ext : ubyte;
end;
pmotion_plus_t = ^motion_plus_t;
expansion_t = packed record
_type: cint;
case integer of
0: (nunchuk: nunchuk_t);
1: (classic: classic_ctrl_t);
2: (gh3: guitar_hero_3_t);
3: (wb: wii_board_t);
4: (mp: motion_plus_t);
end;
Pexpansion_t = ^expansion_t;
wiimote_state_t = packed record
btns : cushort;
ir : ir_t;
accel : vec3w_t;
exp : expansion_t;
end;
Pwiimote_state_t = ^wiimote_state_t;
// Pbte_pcb = ^bte_pcb;
wiimote_t = packed record
unid : cint; (**< user specified id *)
cmdq : lwp_queue;
bdaddr : _bd_addr; (**< bt address *)
bdaddr_str : array [0..17] of char; (**< readable bt address *)
sock : Pbte_pcb; (**< output socket *)
event_cb : wii_event_cb; (**< event callback *)
state : cint; (**< various state flags *)
leds : ubyte; (**< currently lit leds *)
battery_level : ubyte; (**< battery level *)
flags : cint; (**< options flag *)
handshake_state : ubyte; (**< the state of the connection handshake *)
expansion_state : ubyte; (**< the state of the expansion handshake *)
data_req : Pdata_req_t; (**< list of data read requests *)
cmd_head : Pcmd_blk_t;
cmd_tail : Pcmd_blk_t;
accel_calib : accel_t; (**< wiimote accelerometer calibration *)
exp : expansion_t; (**< wiimote expansion device *)
accel : vec3w_t; (**< current raw acceleration data *)
orient : orient_t; (**< current orientation on each axis *)
gforce : gforce_t; (**< current gravity forces on each axis *)
ir : ir_t; (**< IR data *)
btns : cushort; (**< what buttons are down *)
btns_last : cushort; (**< what buttons were down before *)
btns_held : cushort; (**< what buttons are and were held down *)
btns_released : cushort; (**< what buttons were just released *)
lstate : wiimote_state_t; (**< last saved state *)
event : WIIUSE_EVENT_TYPE; (**< type of event that occured *)
event_buf : array [0..MAX_PAYLOAD-1] of ubyte; (**< event buffer *)
motion_plus_id : array [0..5] of ubyte;
end;
wiimote = wiimote_t;
function IS_PRESSED(var dev: wiimote_t; button: cint): boolean; inline;
function IS_PRESSED(var dev: nunchuk_t; button: cint): boolean; inline;
function IS_PRESSED(var dev: classic_ctrl_t; button: cint): boolean; inline;
function IS_PRESSED(var dev: guitar_hero_3_t; button: cint): boolean; inline;
function IS_HELD(var dev: wiimote_t; button: cint): boolean; inline;
function IS_HELD(var dev: nunchuk_t; button: cint): boolean; inline;
function IS_HELD(var dev: classic_ctrl_t; button: cint): boolean; inline;
function IS_HELD(var dev: guitar_hero_3_t; button: cint): boolean; inline;
function IS_RELEASED(var dev: wiimote_t; button: cint): boolean; inline;
function IS_RELEASED(var dev: nunchuk_t; button: cint): boolean; inline;
function IS_RELEASED(var dev: classic_ctrl_t; button: cint): boolean; inline;
function IS_RELEASED(var dev: guitar_hero_3_t; button: cint): boolean; inline;
function IS_JUST_PRESSED(var dev: wiimote_t; button: cint): boolean; inline;
function IS_JUST_PRESSED(var dev: nunchuk_t; button: cint): boolean; inline;
function IS_JUST_PRESSED(var dev: classic_ctrl_t; button: cint): boolean; inline;
function IS_JUST_PRESSED(var dev: guitar_hero_3_t; button: cint): boolean; inline;
procedure WIIUSE_GET_IR_SENSITIVITY(var wm: wiimote_t; var lvl: cint);
// /**
// * @brief Return the IR sensitivity level.
// * @param wm Pointer to a wiimote_t structure.
// * @param lvl [out] Pointer to an int that will hold the level setting.
// * If no level is set 'lvl' will be set to 0.
// */
//#define WIIUSE_GET_IR_SENSITIVITY(dev, lvl) \
// do { \
// if ((wm->state & 0x01000) == 0x01000) *lvl = 1; \
// else if ((wm->state & 0x02000) == 0x02000) *lvl = 2; \
// else if ((wm->state & 0x04000) == 0x04000) *lvl = 3; \
// else if ((wm->state & 0x08000) == 0x08000) *lvl = 4; \
// else if ((wm->state & 0x10000) == 0x10000) *lvl = 5; \
// else *lvl = 0; \
// } while (0)
function WIIUSE_USING_ACC(var wm: wiimote_t): boolean; inline;
function WIIUSE_USING_EXP(var wm: wiimote_t): boolean; inline;
function WIIUSE_USING_IR(var wm: wiimote_t): boolean; inline;
function WIIUSE_USING_SPEAKER(var wm: wiimote_t): boolean; inline;
function WIIUSE_IS_LED_SET(var wm: wiimote_t; num: byte): boolean; inline;
{$ifdef GEKKO}
type
P_bd_addr = ^_bd_addr;
wiimote_listen_t = packed record
bdaddr : _bd_addr;
sock : Pbte_pcb;
assign_cb : function(bdaddr: P_bd_addr): Pwiimote_t; cdecl;
wm : Pwiimote_t;
end;
wiimote_listen = wiimote_listen_t;
pwiimote_listen = ^wiimote_listen_t;
{$endif}
///*****************************************
// *
// * Include API specific stuff
// *
// *****************************************/
//#ifdef _WIN32
// #define WIIUSE_EXPORT_DECL __declspec(dllexport)
// #define WIIUSE_IMPORT_DECL __declspec(dllimport)
//#else
// #define WIIUSE_EXPORT_DECL
// #define WIIUSE_IMPORT_DECL
//#endif
//#ifdef WIIUSE_COMPILE_LIB
// #define WIIUSE_EXPORT WIIUSE_EXPORT_DECL
//#else
// #define WIIUSE_EXPORT WIIUSE_IMPORT_DECL
//#endif
function wiiuse_version: pcchar; cdecl; external;
{$ifndef GEKKO}
type
PPwiimote_t = ^Pwiimote_t;
function wiiuse_init(wiimotes: cint): PPwiimote_t; cdecl; external;
{$else}
type
Tassign_cb = function(bdaddr: P_bd_addr): Pwiimote_t; cdecl;
function wiiuse_register(wml: Pwiimote_listen_t; bdaddr: P_bd_addr;
assign_cb: Tassign_cb): cint; cdecl; external;
function wiiuse_init(wiimotes: cint; event_cb: wii_event_cb): PPwiimote_t; cdecl; external;
procedure wiiuse_sensorbar_enable(enable: cint); cdecl; external;
{$endif}
procedure wiiuse_disconnected(wm: Pwiimote_t); cdecl; external;
procedure wiiuse_cleanup(wm: PPwiimote_t; wiimotes: cint); cdecl; external;
procedure wiiuse_rumble(wm: Pwiimote_t; status: cint); cdecl; external;
procedure wiiuse_toggle_rumble(wm: Pwiimote_t); cdecl; external;
procedure wiiuse_set_leds(wm: Pwiimote_t; leds: cint; cb: cmd_blk_cb); cdecl; external;
procedure wiiuse_motion_sensing(wm: Pwiimote_t; status: cint); cdecl; external;
function wiiuse_read_data(wm: Pwiimote_t; buffer: Pubyte; offset: cuint;
len: cushort; cb: cmd_blk_cb): cint; cdecl; external;
function wiiuse_write_data(wm: Pwiimote_t; addr: cuint; data: Pubyte;
len: ubyte; cb: cmd_blk_cb): cint; cdecl; external;
procedure wiiuse_status(wm: Pwiimote_t; cb: cmd_blk_cb); cdecl; external;
function wiiuse_get_by_id(wm: PPwiimote_t; wiimotes, unid: cint): Pwiimote_t; cdecl; external;
function wiiuse_set_flags(wm: Pwiimote_t; enable, disable: cint): cint; cdecl; external;
function wiiuse_set_smooth_alpha(wm: Pwiimote_t; alpha: cfloat): cfloat; cdecl; external;
procedure wiiuse_set_bluetooth_stack(wm: PPwiimote_t; wiimotes: cint;
type_: win_bt_stack_t); cdecl; external;
procedure wiiuse_resync(wm: Pwiimote_t); cdecl; external;
procedure wiiuse_set_timeout(wm: PPwiimote_t; wiimotes: cint;
normal_timeout, exp_timeout: ubyte); cdecl; external;
function wiiuse_write_streamdata(wm: Pwiimote_t; data: Pubyte; len: ubyte;
cb: cmd_blk_cb): cint; cdecl; external;
(* connect.c *)
function wiiuse_find(wm: PPwiimote_t; max_wiimotes, timeout: cint): cint; cdecl; external;
function wiiuse_connect(wm: PPwiimote_t; wiimotes: cint): cint; cdecl; external;
procedure wiiuse_disconnect(wm: Pwiimote_t); cdecl; external;
(* events.c *)
function wiiuse_poll(wm: PPwiimote_t; wiimotes: cint): cint; cdecl; external;
(* ir.c *)
procedure wiiuse_set_ir_mode(wm: Pwiimote_t); cdecl; external;
procedure wiiuse_set_ir(wm: Pwiimote_t; status: cint); cdecl; external;
procedure wiiuse_set_ir_vres(wm: Pwiimote_t; x, y: cuint); cdecl; external;
procedure wiiuse_set_ir_position(wm: Pwiimote_t; pos: ir_position_t); cdecl; external;
procedure wiiuse_set_aspect_ratio(wm: Pwiimote_t; aspect: aspect_t); cdecl; external;
procedure wiiuse_set_ir_sensitivity(wm: Pwiimote_t; level: cint); cdecl; external;
(* motion_plus.c *)
procedure wiiuse_set_motion_plus(wm: Pwiimote_t; status: cint); cdecl; external;
(* speaker.c *)
procedure wiiuse_set_speaker(wm: Pwiimote_t; status: cint); cdecl; external;
{$ENDIF OGC_INTERFACE}
{$IFDEF OGC_IMPLEMENTATION}
function IS_PRESSED(var dev: wiimote_t; button: cint): boolean; inline;
begin
IS_PRESSED := (dev.btns and button) = button;
end;
function IS_PRESSED(var dev: nunchuk_t; button: cint): boolean; inline;
begin
IS_PRESSED := (dev.btns and button) = button;
end;
function IS_PRESSED(var dev: classic_ctrl_t; button: cint): boolean; inline;
begin
IS_PRESSED := (dev.btns and button) = button;
end;
function IS_PRESSED(var dev: guitar_hero_3_t; button: cint): boolean; inline;
begin
IS_PRESSED := (dev.btns and button) = button;
end;
function IS_HELD(var dev: wiimote_t; button: cint): boolean; inline;
begin
IS_HELD := (dev.btns_held and button) = button;
end;
function IS_HELD(var dev: nunchuk_t; button: cint): boolean; inline;
begin
IS_HELD := (dev.btns_held and button) = button;
end;
function IS_HELD(var dev: classic_ctrl_t; button: cint): boolean; inline;
begin
IS_HELD := (dev.btns_held and button) = button;
end;
function IS_HELD(var dev: guitar_hero_3_t; button: cint): boolean; inline;
begin
IS_HELD := (dev.btns_held and button) = button;
end;
function IS_RELEASED(var dev: wiimote_t; button: cint): boolean; inline;
begin
IS_RELEASED := (dev.btns_released and button) = button;
end;
function IS_RELEASED(var dev: nunchuk_t; button: cint): boolean; inline;
begin
IS_RELEASED := (dev.btns_released and button) = button;
end;
function IS_RELEASED(var dev: classic_ctrl_t; button: cint): boolean; inline;
begin
IS_RELEASED := (dev.btns_released and button) = button;
end;
function IS_RELEASED(var dev: guitar_hero_3_t; button: cint): boolean; inline;
begin
IS_RELEASED := (dev.btns_released and button) = button;
end;
function IS_JUST_PRESSED(var dev: wiimote_t; button: cint): boolean; inline;
begin
IS_JUST_PRESSED := IS_PRESSED(dev, button) and not IS_HELD(dev, button);
end;
function IS_JUST_PRESSED(var dev: nunchuk_t; button: cint): boolean; inline;
begin
IS_JUST_PRESSED := IS_PRESSED(dev, button) and not IS_HELD(dev, button);
end;
function IS_JUST_PRESSED(var dev: classic_ctrl_t; button: cint): boolean; inline;
begin
IS_JUST_PRESSED := IS_PRESSED(dev, button) and not IS_HELD(dev, button);
end;
function IS_JUST_PRESSED(var dev: guitar_hero_3_t; button: cint): boolean; inline;
begin
IS_JUST_PRESSED := IS_PRESSED(dev, button) and not IS_HELD(dev, button);
end;
procedure WIIUSE_GET_IR_SENSITIVITY(var wm: wiimote_t; var lvl: cint);
begin
repeat
if (wm.state and $01000) = $01000 then
lvl := 1
else
if (wm.state and $02000) = $02000 then
lvl := 2
else
if (wm.state and $04000) = $04000 then
lvl := 3
else
if (wm.state and $08000) = $08000 then
lvl := 4
else
if (wm.state and $10000) = $10000 then
lvl := 5
else
lvl := 0;
until false;
end;
// /**
// * @brief Return the IR sensitivity level.
// * @param wm Pointer to a wiimote_t structure.
// * @param lvl [out] Pointer to an int that will hold the level setting.
// * If no level is set 'lvl' will be set to 0.
// */
//#define WIIUSE_GET_IR_SENSITIVITY(dev, lvl) \
// do { \
// if ((wm->state & 0x01000) == 0x01000) *lvl = 1; \
// else if ((wm->state & 0x02000) == 0x02000) *lvl = 2; \
// else if ((wm->state & 0x04000) == 0x04000) *lvl = 3; \
// else if ((wm->state & 0x08000) == 0x08000) *lvl = 4; \
// else if ((wm->state & 0x10000) == 0x10000) *lvl = 5; \
// else *lvl = 0; \
// } while (0)
function WIIUSE_USING_ACC(var wm: wiimote_t): boolean; inline;
begin
WIIUSE_USING_ACC := (wm.state and $00100) = $00100;
end;
function WIIUSE_USING_EXP(var wm: wiimote_t): boolean; inline;
begin
WIIUSE_USING_EXP := (wm.state and $00200) = $00200;
end;
function WIIUSE_USING_IR(var wm: wiimote_t): boolean; inline;
begin
WIIUSE_USING_IR := (wm.state and $00400) = $00400;
end;
function WIIUSE_USING_SPEAKER(var wm: wiimote_t): boolean; inline;
begin
WIIUSE_USING_SPEAKER := (wm.state and $00800) = $00800;
end;
function WIIUSE_IS_LED_SET(var wm: wiimote_t; num: byte): boolean; inline;
begin
WIIUSE_IS_LED_SET := (wm.leds and (num shl 4)) = (num shl 4);
end;
{$ENDIF OGC_IMPLEMENTATION}
|