wii4r 0.5.0-x86-linux
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +675 -0
- data/README.rdoc +39 -0
- data/Rakefile +10 -0
- data/examples/playsound.rb +14 -0
- data/examples/poll.rb +104 -0
- data/ext/wii4r/classic.c +233 -0
- data/ext/wii4r/guitarhero3.c +175 -0
- data/ext/wii4r/nunchuk.c +310 -0
- data/ext/wii4r/wii4r.c +186 -0
- data/ext/wii4r/wiimote.c +1258 -0
- data/ext/wii4r/wiimotemanager.c +369 -0
- data/lib/wii4r.so +0 -0
- data/wii4r.gemspec +28 -0
- metadata +98 -0
data/ext/wii4r/wiimote.c
ADDED
@@ -0,0 +1,1258 @@
|
|
1
|
+
/*
|
2
|
+
############################################################################
|
3
|
+
# #
|
4
|
+
# Copyright (C) 2009 by KzMz KzMz@modusbibendi.org #
|
5
|
+
# Copyright (C) 2009 by BuZz Gambino.Giorgio@gmail.com #
|
6
|
+
# #
|
7
|
+
# This program is free software; you can redistribute it and/or modify #
|
8
|
+
# it under the terms of the GNU General Public License as published by #
|
9
|
+
# the Free Software Foundation; either version 2 of the License, or #
|
10
|
+
# (at your option) any later version. #
|
11
|
+
# #
|
12
|
+
# This program is distributed in the hope that it will be useful, #
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
15
|
+
# GNU General Public License for more details. #
|
16
|
+
# #
|
17
|
+
# You should have received a copy of the GNU General Public License #
|
18
|
+
# along with this program; if not, write to the #
|
19
|
+
# Free Software Foundation, Inc., #
|
20
|
+
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
|
21
|
+
############################################################################
|
22
|
+
*/
|
23
|
+
|
24
|
+
#include "wii4r.h"
|
25
|
+
|
26
|
+
//handles the disconnection of wiimote
|
27
|
+
void free_wiimote(void * wm) {
|
28
|
+
wiiuse_disconnect((wiimote *) wm);
|
29
|
+
}
|
30
|
+
|
31
|
+
void set_expansion(VALUE self, VALUE exp_obj) {
|
32
|
+
rb_iv_set(self, "@exp", exp_obj);
|
33
|
+
}
|
34
|
+
|
35
|
+
static VALUE rb_wm_new(VALUE self) {
|
36
|
+
wiimote *wm;
|
37
|
+
VALUE obj = Data_Make_Struct(self, wiimote, NULL, free_wiimote, wm);
|
38
|
+
rb_obj_call_init(obj, 0, 0);
|
39
|
+
return obj;
|
40
|
+
}
|
41
|
+
|
42
|
+
static VALUE rb_wm_init(VALUE self) {
|
43
|
+
rb_iv_set(self, "@rumble", Qfalse);
|
44
|
+
rb_iv_set(self, "@smoothed", rb_hash_new());
|
45
|
+
wiimote *wm;
|
46
|
+
Data_Get_Struct(self, wiimote, wm);
|
47
|
+
if(!wm) return Qnil;
|
48
|
+
if(!WIIUSE_USING_ACC(wm))
|
49
|
+
rb_iv_set(self, "@motion_sensing", Qfalse);
|
50
|
+
else
|
51
|
+
rb_iv_set(self, "@motion_sensing", Qtrue);
|
52
|
+
if(!WIIUSE_USING_IR(wm))
|
53
|
+
rb_iv_set(self, "@ir", Qfalse);
|
54
|
+
else
|
55
|
+
rb_iv_set(self, "@ir", Qtrue);
|
56
|
+
if(!WIIUSE_USING_SPEAKER(wm))
|
57
|
+
rb_iv_set(self, "@speaker", Qfalse);
|
58
|
+
else
|
59
|
+
rb_iv_set(self, "@speaker", Qtrue);
|
60
|
+
return self;
|
61
|
+
}
|
62
|
+
|
63
|
+
/*
|
64
|
+
* call-seq:
|
65
|
+
* wiimote.rumble? -> true or false
|
66
|
+
*
|
67
|
+
* Returns true if the <i>self</i> is rumbling.
|
68
|
+
*
|
69
|
+
*/
|
70
|
+
|
71
|
+
static VALUE rb_wm_get_rumble(VALUE self) {
|
72
|
+
VALUE rumble = rb_iv_get(self, "@rumble");
|
73
|
+
return rumble;
|
74
|
+
}
|
75
|
+
|
76
|
+
/*
|
77
|
+
* call-seq:
|
78
|
+
* wiimote.rumble = true or false -> nil
|
79
|
+
*
|
80
|
+
* Set the rumble property of <i>self</i> to true or false and makes the device rumble or stop.
|
81
|
+
*
|
82
|
+
*/
|
83
|
+
|
84
|
+
static VALUE rb_wm_set_rumble(VALUE self, VALUE arg) {
|
85
|
+
wiimote * wm;
|
86
|
+
Data_Get_Struct(self, wiimote, wm);
|
87
|
+
if(!wm) return Qnil;
|
88
|
+
|
89
|
+
int rumble;
|
90
|
+
switch(arg) {
|
91
|
+
case Qfalse:
|
92
|
+
rumble = 0;
|
93
|
+
break;
|
94
|
+
case Qtrue:
|
95
|
+
rumble = 1;
|
96
|
+
break;
|
97
|
+
default:
|
98
|
+
rb_raise(rb_eTypeError, "Invalid Argument");
|
99
|
+
break;
|
100
|
+
}
|
101
|
+
wiiuse_rumble(wm, rumble);
|
102
|
+
rb_iv_set(self, "@rumble", arg);
|
103
|
+
return arg;
|
104
|
+
}
|
105
|
+
|
106
|
+
/*
|
107
|
+
* call-seq:
|
108
|
+
* wiimote.rumble! -> nil
|
109
|
+
* wiimote.rumble!(duration) -> nil
|
110
|
+
* wiimote.rumble!(duration, times) -> nil
|
111
|
+
*
|
112
|
+
* The first form puts <i>self</i> in rumbling state.
|
113
|
+
* The second one puts <i>self</i> in rumbling state for <i>duration</i> seconds.
|
114
|
+
* The last one puts <i>self</i> in rumbling state for <i>duration</i> seconds for <i>times</i> times, separated by 1 sec of pause.
|
115
|
+
*
|
116
|
+
*/
|
117
|
+
|
118
|
+
|
119
|
+
static VALUE rb_wm_rumble(int argc, VALUE * argv, VALUE self) {
|
120
|
+
wiimote * wm;
|
121
|
+
Data_Get_Struct(self, wiimote, wm);
|
122
|
+
if(!wm) return Qnil;
|
123
|
+
|
124
|
+
wiiuse_rumble(wm, 1);
|
125
|
+
rb_iv_set(self, "@rumble", Qtrue);
|
126
|
+
if(argc == 1) {
|
127
|
+
switch(TYPE(argv[0])) {
|
128
|
+
case T_FIXNUM:
|
129
|
+
//fork o thread?
|
130
|
+
sleep(NUM2INT(argv[0]));
|
131
|
+
wiiuse_rumble(wm, 0);
|
132
|
+
rb_iv_set(self, "@rumble", Qfalse);
|
133
|
+
break;
|
134
|
+
case T_ARRAY:
|
135
|
+
default:
|
136
|
+
rb_raise(rb_eTypeError, "Invalid Argument");
|
137
|
+
break;
|
138
|
+
}
|
139
|
+
}
|
140
|
+
else if(argc == 2) {
|
141
|
+
if(TYPE(argv[0]) == T_FIXNUM && TYPE(argv[1]) == T_FIXNUM) {
|
142
|
+
int i = NUM2INT(argv[1]);
|
143
|
+
int stime = NUM2INT(argv[0]);
|
144
|
+
while(i > 1) {
|
145
|
+
sleep(stime);
|
146
|
+
wiiuse_rumble(wm, 0);
|
147
|
+
sleep(1);
|
148
|
+
wiiuse_rumble(wm, 1);
|
149
|
+
i--;
|
150
|
+
}
|
151
|
+
sleep(stime);
|
152
|
+
wiiuse_rumble(wm, 0);
|
153
|
+
rb_iv_set(self, "@rumble", Qfalse);
|
154
|
+
}
|
155
|
+
}
|
156
|
+
else {
|
157
|
+
rb_raise(rb_eTypeError, "Invalid Argument");
|
158
|
+
}
|
159
|
+
return Qnil;
|
160
|
+
}
|
161
|
+
|
162
|
+
/*
|
163
|
+
* call-seq:
|
164
|
+
* wiimote.stop! -> nil
|
165
|
+
*
|
166
|
+
* Turns the rumbling state of <i>self</i> to false.
|
167
|
+
*
|
168
|
+
*/
|
169
|
+
|
170
|
+
static VALUE rb_wm_stop(VALUE self) {
|
171
|
+
wiimote * wm;
|
172
|
+
Data_Get_Struct(self, wiimote, wm);
|
173
|
+
if(!wm) return Qnil;
|
174
|
+
|
175
|
+
wiiuse_rumble(wm, 0);
|
176
|
+
rb_iv_set(self, "@rumble", Qfalse);
|
177
|
+
return Qnil;
|
178
|
+
}
|
179
|
+
|
180
|
+
/*
|
181
|
+
* call-seq:
|
182
|
+
* wiimote.leds = led -> led
|
183
|
+
*
|
184
|
+
* Turns on the led or the leds contained in <i>led</i>.
|
185
|
+
*
|
186
|
+
* #turns on led 1
|
187
|
+
* wmote.leds = LED_1 #=>(LED_1 value)
|
188
|
+
*
|
189
|
+
* #turns on led 2 and 3
|
190
|
+
* wmote.leds = LED_2 | LED_3 #=>(LED_2 | LED_3 value)
|
191
|
+
*/
|
192
|
+
|
193
|
+
static VALUE rb_wm_leds(VALUE self, VALUE arg) {
|
194
|
+
wiimote * wm;
|
195
|
+
Data_Get_Struct(self, wiimote, wm);
|
196
|
+
if(!wm) return Qnil;
|
197
|
+
|
198
|
+
wiiuse_set_leds(wm, NUM2INT(arg));
|
199
|
+
return Qnil;
|
200
|
+
}
|
201
|
+
|
202
|
+
/*
|
203
|
+
* call-seq:
|
204
|
+
* wiimote.turn_off_leds! -> nil
|
205
|
+
*
|
206
|
+
* Turns off all the leds of <i>self</i>.
|
207
|
+
*
|
208
|
+
*/
|
209
|
+
|
210
|
+
static VALUE rb_wm_turnoff(VALUE self) {
|
211
|
+
wiimote * wm;
|
212
|
+
Data_Get_Struct(self, wiimote, wm);
|
213
|
+
if(!wm) return Qnil;
|
214
|
+
wiiuse_set_leds(wm, WIIMOTE_LED_NONE);
|
215
|
+
return Qnil;
|
216
|
+
}
|
217
|
+
|
218
|
+
/*
|
219
|
+
* call-seq:
|
220
|
+
* wiimote.motion_sensing? -> true or false
|
221
|
+
*
|
222
|
+
* Returns true if motion sensing is activated in <i>self</i>, false otherwise.
|
223
|
+
*
|
224
|
+
*/
|
225
|
+
|
226
|
+
static VALUE rb_wm_get_ms(VALUE self) {
|
227
|
+
return rb_iv_get(self, "@motion_sensing");
|
228
|
+
}
|
229
|
+
|
230
|
+
/*
|
231
|
+
* call-seq:
|
232
|
+
* wiimote.motion_sensing = true or false -> true or false
|
233
|
+
*
|
234
|
+
* Sets the motion sensing of <i>self</i> to true or false.
|
235
|
+
*
|
236
|
+
*/
|
237
|
+
|
238
|
+
static VALUE rb_wm_set_ms(VALUE self, VALUE arg) {
|
239
|
+
int motion_sensing;
|
240
|
+
|
241
|
+
switch(arg) {
|
242
|
+
case Qfalse:
|
243
|
+
motion_sensing = 0;
|
244
|
+
break;
|
245
|
+
case Qtrue:
|
246
|
+
motion_sensing = 1;
|
247
|
+
break;
|
248
|
+
default:
|
249
|
+
rb_raise(rb_eTypeError, "Invalid Argument");
|
250
|
+
}
|
251
|
+
|
252
|
+
rb_iv_set(self, "@motion_sensing", arg);
|
253
|
+
|
254
|
+
wiimote * wm;
|
255
|
+
Data_Get_Struct(self, wiimote, wm);
|
256
|
+
if(!wm) return Qnil;
|
257
|
+
|
258
|
+
wiiuse_motion_sensing(wm, motion_sensing);
|
259
|
+
return arg;
|
260
|
+
}
|
261
|
+
|
262
|
+
/*
|
263
|
+
* call-seq:
|
264
|
+
* wiimote.status -> hash
|
265
|
+
*
|
266
|
+
* Returns a hash containing the status information of <i>self</i>.
|
267
|
+
*
|
268
|
+
* h = wmote.status
|
269
|
+
* h[:speaker] #=> true or false
|
270
|
+
* h[:ir] #=> true or false
|
271
|
+
* h[:attachment] #=> string defining the expansion inserted
|
272
|
+
* h[:id] #=> int defining the id of <i>self</i>
|
273
|
+
* h[:battery] #=> float (battery level)
|
274
|
+
* h[:led] #=> string (the last led turned on)
|
275
|
+
*/
|
276
|
+
|
277
|
+
static VALUE rb_wm_status(VALUE self) {
|
278
|
+
wiimote * wm;
|
279
|
+
Data_Get_Struct(self, wiimote, wm);
|
280
|
+
if(!wm) return Qnil;
|
281
|
+
|
282
|
+
wiiuse_status(wm);
|
283
|
+
|
284
|
+
VALUE status_hash = rb_hash_new();
|
285
|
+
VALUE speaker = Qnil;
|
286
|
+
VALUE led = Qnil;
|
287
|
+
VALUE ir = Qnil;
|
288
|
+
VALUE expansion = Qnil;
|
289
|
+
|
290
|
+
if(WIIUSE_USING_SPEAKER(wm))
|
291
|
+
speaker = Qtrue;
|
292
|
+
else
|
293
|
+
speaker = Qfalse;
|
294
|
+
|
295
|
+
if(WIIUSE_USING_IR(wm))
|
296
|
+
ir = Qtrue;
|
297
|
+
else
|
298
|
+
ir = Qfalse;
|
299
|
+
|
300
|
+
switch(wm->exp.type){
|
301
|
+
case EXP_NUNCHUK:
|
302
|
+
expansion = rb_str_new2("Nunchuk");
|
303
|
+
case EXP_CLASSIC:
|
304
|
+
expansion = rb_str_new2("Classic Controller");
|
305
|
+
case EXP_GUITAR_HERO_3:
|
306
|
+
expansion = rb_str_new2("Guitar Hero Controller");
|
307
|
+
case EXP_NONE:
|
308
|
+
expansion = rb_str_new2("Nothing Inserted");
|
309
|
+
}
|
310
|
+
|
311
|
+
|
312
|
+
if(WIIUSE_IS_LED_SET(wm, 1)) led = rb_str_new2("LED_1");
|
313
|
+
else if(WIIUSE_IS_LED_SET(wm, 2)) led = rb_str_new2("LED_2");
|
314
|
+
else if(WIIUSE_IS_LED_SET(wm, 3)) led = rb_str_new2("LED_3");
|
315
|
+
else if(WIIUSE_IS_LED_SET(wm, 4)) led = rb_str_new2("LED_4");
|
316
|
+
else led = rb_str_new2("NONE");
|
317
|
+
|
318
|
+
rb_hash_aset(status_hash,ID2SYM(rb_intern("id")),INT2NUM(wm->unid));
|
319
|
+
rb_hash_aset(status_hash,ID2SYM(rb_intern("battery")),rb_float_new(wm->battery_level));
|
320
|
+
rb_hash_aset(status_hash,ID2SYM(rb_intern("speaker")),speaker);
|
321
|
+
rb_hash_aset(status_hash,ID2SYM(rb_intern("ir")),ir);
|
322
|
+
rb_hash_aset(status_hash,ID2SYM(rb_intern("led")), led);
|
323
|
+
rb_hash_aset(status_hash,ID2SYM(rb_intern("attachment")),expansion);
|
324
|
+
return status_hash;
|
325
|
+
}
|
326
|
+
|
327
|
+
/*
|
328
|
+
* call-seq:
|
329
|
+
* wiimote.disconnect! -> true or false
|
330
|
+
*
|
331
|
+
* Disconnects <i>self</i> if it is connected and returns true, false if <i>self</i> is nil or disconnected.
|
332
|
+
*
|
333
|
+
*
|
334
|
+
*/
|
335
|
+
|
336
|
+
static VALUE rb_wm_disconnect(VALUE self) {
|
337
|
+
wiimote *wm;
|
338
|
+
Data_Get_Struct(self, wiimote, wm);
|
339
|
+
if(!wm) return Qnil;
|
340
|
+
|
341
|
+
if(wm_connected(wm)) {
|
342
|
+
wiiuse_disconnected(wm);
|
343
|
+
return Qtrue;
|
344
|
+
}
|
345
|
+
else return Qfalse;
|
346
|
+
}
|
347
|
+
|
348
|
+
|
349
|
+
//checks if "wm" is connected or not
|
350
|
+
int wm_connected(wiimote *wm) {
|
351
|
+
if(!wm) return 0;
|
352
|
+
else return WIIMOTE_IS_CONNECTED(wm);
|
353
|
+
}
|
354
|
+
|
355
|
+
/*
|
356
|
+
* call-seq:
|
357
|
+
* wiimote.connected? -> true or false
|
358
|
+
*
|
359
|
+
* Returns true if <i>self</i> is connected via bluetooth, false otherwise.
|
360
|
+
*
|
361
|
+
*/
|
362
|
+
|
363
|
+
static VALUE rb_wm_connected(VALUE self) {
|
364
|
+
wiimote * wm;
|
365
|
+
Data_Get_Struct(self, wiimote, wm);
|
366
|
+
if(!wm) return Qnil;
|
367
|
+
|
368
|
+
int connected = wm_connected(wm);
|
369
|
+
if(connected == 0) return Qfalse;
|
370
|
+
else return Qtrue;
|
371
|
+
}
|
372
|
+
|
373
|
+
/*
|
374
|
+
* call-seq:
|
375
|
+
* wiimote.pressed?(button) -> true or false
|
376
|
+
*
|
377
|
+
* Returns true if <i>button</i> is being pressed on <i>self</i>.
|
378
|
+
*
|
379
|
+
*/
|
380
|
+
|
381
|
+
static VALUE rb_wm_pressed(VALUE self, VALUE arg) {
|
382
|
+
wiimote *wm;
|
383
|
+
Data_Get_Struct(self, wiimote, wm);
|
384
|
+
if(!wm) return Qnil;
|
385
|
+
Check_Type(arg, T_FIXNUM);
|
386
|
+
|
387
|
+
int pressed = IS_PRESSED(wm, NUM2INT(arg));
|
388
|
+
if(pressed == 0) return Qfalse;
|
389
|
+
else return Qtrue;
|
390
|
+
}
|
391
|
+
|
392
|
+
/*
|
393
|
+
* call-seq:
|
394
|
+
* wiimote.just_pressed?(button) -> true of false
|
395
|
+
*
|
396
|
+
* Returns true if <i>button</i> is just pressed on <i>self</i>.
|
397
|
+
*
|
398
|
+
*/
|
399
|
+
|
400
|
+
static VALUE rb_wm_just_pressed(VALUE self, VALUE arg) {
|
401
|
+
wiimote *wm;
|
402
|
+
Data_Get_Struct(self, wiimote, wm);
|
403
|
+
if(!wm) return Qnil;
|
404
|
+
Check_Type(arg, T_FIXNUM);
|
405
|
+
|
406
|
+
int pressed = IS_JUST_PRESSED(wm, NUM2INT(arg));
|
407
|
+
if(pressed == 0) return Qfalse;
|
408
|
+
else return Qtrue;
|
409
|
+
}
|
410
|
+
|
411
|
+
/*
|
412
|
+
* call-seq:
|
413
|
+
* wiimote.held?(button) -> true of false
|
414
|
+
*
|
415
|
+
* Returns true if <i>button</i> is held on <i>self</i>.
|
416
|
+
*
|
417
|
+
*/
|
418
|
+
|
419
|
+
static VALUE rb_wm_held(VALUE self, VALUE arg) {
|
420
|
+
wiimote *wm;
|
421
|
+
Data_Get_Struct(self, wiimote, wm);
|
422
|
+
if(!wm) return Qnil;
|
423
|
+
Check_Type(arg, T_FIXNUM);
|
424
|
+
|
425
|
+
int held = IS_HELD(wm, NUM2INT(arg));
|
426
|
+
if(held == 0) return Qfalse;
|
427
|
+
else return Qtrue;
|
428
|
+
}
|
429
|
+
|
430
|
+
/*
|
431
|
+
* call-seq:
|
432
|
+
* wiimote.released?(button) -> true or false
|
433
|
+
*
|
434
|
+
* Returns true if <i>button</i> is just released on <i>self</i>.
|
435
|
+
*
|
436
|
+
*/
|
437
|
+
|
438
|
+
static VALUE rb_wm_released(VALUE self, VALUE arg) {
|
439
|
+
wiimote *wm;
|
440
|
+
Data_Get_Struct(self, wiimote, wm);
|
441
|
+
if(!wm) return Qnil;
|
442
|
+
Check_Type(arg, T_FIXNUM);
|
443
|
+
|
444
|
+
int released = IS_RELEASED(wm, NUM2INT(arg));
|
445
|
+
if(released == 0) return Qfalse;
|
446
|
+
else return Qtrue;
|
447
|
+
}
|
448
|
+
|
449
|
+
/*
|
450
|
+
* call-seq:
|
451
|
+
* wiimote.yaw -> float
|
452
|
+
*
|
453
|
+
* Returns the rotation around Z axis (works only with ir tracking and at least two ir sources visible).
|
454
|
+
*
|
455
|
+
*/
|
456
|
+
|
457
|
+
static VALUE rb_wm_yaw(VALUE self) {
|
458
|
+
wiimote *wm;
|
459
|
+
Data_Get_Struct(self, wiimote, wm);
|
460
|
+
if(!wm) return Qnil;
|
461
|
+
if(!WIIUSE_USING_ACC(wm)) return Qnil;
|
462
|
+
return rb_float_new(wm->orient.yaw);
|
463
|
+
}
|
464
|
+
|
465
|
+
/*
|
466
|
+
* call-seq:
|
467
|
+
* wiimote.pitch -> float
|
468
|
+
*
|
469
|
+
* Returns the rotation around X axis (works with motion sensing activated).
|
470
|
+
* Range: [-179.9, -0.1] [0.1, 179.9]
|
471
|
+
*
|
472
|
+
*/
|
473
|
+
|
474
|
+
static VALUE rb_wm_pitch(VALUE self) {
|
475
|
+
wiimote *wm;
|
476
|
+
Data_Get_Struct(self, wiimote, wm);
|
477
|
+
if(!wm) return Qnil;
|
478
|
+
if(!WIIUSE_USING_ACC(wm)) return Qnil;
|
479
|
+
return rb_float_new(wm->orient.pitch);
|
480
|
+
}
|
481
|
+
|
482
|
+
/*
|
483
|
+
* call-seq:
|
484
|
+
* wiimote.absolute_pitch -> float
|
485
|
+
*
|
486
|
+
* Returns the absolute rotation around X axis (works with motion sensing activated).
|
487
|
+
* Range: [-179.9, -0.1] [0.1, 179.9]
|
488
|
+
*
|
489
|
+
*/
|
490
|
+
|
491
|
+
static VALUE rb_wm_apitch(VALUE self) {
|
492
|
+
wiimote *wm;
|
493
|
+
Data_Get_Struct(self, wiimote, wm);
|
494
|
+
if(!wm) return Qnil;
|
495
|
+
if(!WIIUSE_USING_ACC(wm)) return Qnil;
|
496
|
+
return rb_float_new(wm->orient.a_pitch);
|
497
|
+
}
|
498
|
+
|
499
|
+
/*
|
500
|
+
* call-seq:
|
501
|
+
* wiimote.roll -> float
|
502
|
+
*
|
503
|
+
* Returns the rotation around Y axis (works with motion sensing activated).
|
504
|
+
* Range: [-179.9, -0.1] [0.1, 179.9]
|
505
|
+
*
|
506
|
+
*/
|
507
|
+
|
508
|
+
static VALUE rb_wm_roll(VALUE self) {
|
509
|
+
wiimote *wm;
|
510
|
+
Data_Get_Struct(self, wiimote, wm);
|
511
|
+
if(!wm) return Qnil;
|
512
|
+
if(!WIIUSE_USING_ACC(wm)) return Qnil;
|
513
|
+
return rb_float_new(wm->orient.roll);
|
514
|
+
}
|
515
|
+
|
516
|
+
/*
|
517
|
+
* call-seq:
|
518
|
+
* wiimote.absolute_roll -> float
|
519
|
+
*
|
520
|
+
* Returns the absolute rotation around Y axis (works with motion sensing activated).
|
521
|
+
* Range: [-179.9, -0.1] [0.1, 179.9]
|
522
|
+
*
|
523
|
+
*/
|
524
|
+
|
525
|
+
static VALUE rb_wm_aroll(VALUE self) {
|
526
|
+
wiimote *wm;
|
527
|
+
Data_Get_Struct(self, wiimote, wm);
|
528
|
+
if(!wm) return Qnil;
|
529
|
+
if(!WIIUSE_USING_ACC(wm)) return Qnil;
|
530
|
+
return rb_float_new(wm->orient.a_roll);
|
531
|
+
}
|
532
|
+
|
533
|
+
/*
|
534
|
+
* call-seq:
|
535
|
+
* wiimote.ir? -> true or false
|
536
|
+
*
|
537
|
+
* Returns true if ir tracking is enabled, false otherwise.
|
538
|
+
*
|
539
|
+
*/
|
540
|
+
|
541
|
+
static VALUE rb_wm_ir(VALUE self) {
|
542
|
+
return rb_iv_get(self, "@ir");
|
543
|
+
}
|
544
|
+
|
545
|
+
/*
|
546
|
+
* call-seq:
|
547
|
+
* wiimote.ir = true or false -> true or false
|
548
|
+
*
|
549
|
+
* Sets ir tracking to enabled/disabled.
|
550
|
+
* [BUG in wiiuse] when activated, ir tracking cannot be disabled.
|
551
|
+
*
|
552
|
+
*/
|
553
|
+
|
554
|
+
static VALUE rb_wm_set_ir(VALUE self, VALUE arg) {
|
555
|
+
wiimote *wm;
|
556
|
+
Data_Get_Struct(self, wiimote, wm);
|
557
|
+
if(!wm) return Qnil;
|
558
|
+
int ir;
|
559
|
+
if(arg == Qtrue) ir = 1;
|
560
|
+
else if(arg == Qfalse) ir = 0;
|
561
|
+
else rb_raise(gen_exp_class, "Invalid Argument");
|
562
|
+
|
563
|
+
if(WIIUSE_USING_IR(wm) && ir == 0) wiiuse_set_ir(wm, ir);
|
564
|
+
else if(ir == 1) wiiuse_set_ir(wm, ir);
|
565
|
+
|
566
|
+
if(WIIUSE_USING_IR(wm)) rb_iv_set(self, "@ir", Qtrue);
|
567
|
+
else rb_iv_set(self, "@ir", Qfalse);
|
568
|
+
return arg;
|
569
|
+
}
|
570
|
+
|
571
|
+
/*
|
572
|
+
* call-seq:
|
573
|
+
* wiimote.ir_sources -> array
|
574
|
+
*
|
575
|
+
* Returns an array containing the position [x, y] of all the ir sources seen by <i>self</i>.
|
576
|
+
*
|
577
|
+
*/
|
578
|
+
|
579
|
+
static VALUE rb_wm_ir_sources(VALUE self) {
|
580
|
+
wiimote *wm;
|
581
|
+
Data_Get_Struct(self, wiimote, wm);
|
582
|
+
if(!wm) return Qnil;
|
583
|
+
if(!WIIUSE_USING_IR(wm)) return Qnil;
|
584
|
+
VALUE ary = rb_ary_new();
|
585
|
+
int i = 0;
|
586
|
+
VALUE source;
|
587
|
+
for(; i < 4; i++) {
|
588
|
+
if(wm->ir.dot[i].visible) {
|
589
|
+
source = rb_ary_new();
|
590
|
+
rb_ary_push(source, INT2NUM(wm->ir.dot[i].x));
|
591
|
+
rb_ary_push(source, INT2NUM(wm->ir.dot[i].y));
|
592
|
+
rb_ary_push(ary, source);
|
593
|
+
}
|
594
|
+
}
|
595
|
+
return ary;
|
596
|
+
}
|
597
|
+
|
598
|
+
/*
|
599
|
+
* call-seq:
|
600
|
+
* wiimote.position -> array
|
601
|
+
*
|
602
|
+
* Returns an array containing the position [x, y] of <i>self</i> (works only with ir tracking enabled and at least one ir source visible).
|
603
|
+
*
|
604
|
+
*/
|
605
|
+
|
606
|
+
static VALUE rb_wm_ir_cursor(VALUE self) {
|
607
|
+
wiimote *wm;
|
608
|
+
Data_Get_Struct(self, wiimote, wm);
|
609
|
+
if(!wm) return Qnil;
|
610
|
+
if(!WIIUSE_USING_IR(wm)) return Qnil;
|
611
|
+
VALUE ary = rb_ary_new();
|
612
|
+
rb_ary_push(ary, INT2NUM(wm->ir.x));
|
613
|
+
rb_ary_push(ary, INT2NUM(wm->ir.y));
|
614
|
+
return ary;
|
615
|
+
}
|
616
|
+
|
617
|
+
/*
|
618
|
+
* call-seq:
|
619
|
+
* wiimote.distance -> float
|
620
|
+
*
|
621
|
+
* Returns the distance of <i>self</i> from the ir sources (works only with ir tracking enabled and at least two ir source visible).
|
622
|
+
*
|
623
|
+
*/
|
624
|
+
|
625
|
+
static VALUE rb_wm_ir_z(VALUE self) {
|
626
|
+
wiimote *wm;
|
627
|
+
Data_Get_Struct(self, wiimote, wm);
|
628
|
+
if(!wm) return Qnil;
|
629
|
+
if(!WIIUSE_USING_IR(wm)) return Qnil;
|
630
|
+
return rb_float_new(wm->ir.z);
|
631
|
+
}
|
632
|
+
|
633
|
+
/*
|
634
|
+
* call-seq:
|
635
|
+
* wiimote.sensitivity -> int
|
636
|
+
*
|
637
|
+
* Returns the sensitivity level of ir camera.
|
638
|
+
* Range: [1, 5]
|
639
|
+
*
|
640
|
+
*/
|
641
|
+
|
642
|
+
static VALUE rb_wm_sensitivity(VALUE self) {
|
643
|
+
wiimote *wm;
|
644
|
+
int level;
|
645
|
+
Data_Get_Struct(self, wiimote, wm);
|
646
|
+
if(!wm) return Qnil;
|
647
|
+
if(!WIIUSE_USING_IR(wm)) return Qnil;
|
648
|
+
WIIUSE_GET_IR_SENSITIVITY(wm, &level);
|
649
|
+
return INT2NUM(level);
|
650
|
+
}
|
651
|
+
|
652
|
+
/*
|
653
|
+
* call-seq:
|
654
|
+
* wiimote.sensitivity = level -> int
|
655
|
+
*
|
656
|
+
* Sets the sensitivity level of ir camera to <i>level</i>.
|
657
|
+
* The value will be truncated to 5 or 1.
|
658
|
+
*
|
659
|
+
*/
|
660
|
+
|
661
|
+
static VALUE rb_wm_set_sens(VALUE self, VALUE arg) {
|
662
|
+
wiimote *wm;
|
663
|
+
Data_Get_Struct(self,wiimote,wm);
|
664
|
+
if(!wm) return Qnil;
|
665
|
+
wiiuse_set_ir_sensitivity(wm,NUM2INT(arg));
|
666
|
+
return Qnil;
|
667
|
+
}
|
668
|
+
|
669
|
+
/*
|
670
|
+
* call-seq:
|
671
|
+
* wiimote.speaker? -> true or false
|
672
|
+
*
|
673
|
+
* Returns true if speaker is enabled, false otherwise.
|
674
|
+
*
|
675
|
+
*/
|
676
|
+
|
677
|
+
static VALUE rb_wm_speaker(VALUE self) {
|
678
|
+
wiimote *wm;
|
679
|
+
Data_Get_Struct(self, wiimote, wm);
|
680
|
+
if(!wm) return Qnil;
|
681
|
+
if (WIIUSE_USING_SPEAKER(wm)) return Qtrue;
|
682
|
+
else return Qfalse;
|
683
|
+
}
|
684
|
+
|
685
|
+
/*
|
686
|
+
* call-seq:
|
687
|
+
* wiimote.battery_level -> float
|
688
|
+
*
|
689
|
+
* Returns the battery level of <i>self</i>.
|
690
|
+
*
|
691
|
+
*/
|
692
|
+
|
693
|
+
static VALUE rb_wm_bl(VALUE self) {
|
694
|
+
wiimote *wm;
|
695
|
+
Data_Get_Struct(self,wiimote,wm);
|
696
|
+
if(!wm) return Qnil;
|
697
|
+
wiiuse_status(wm);
|
698
|
+
return rb_float_new(wm->battery_level);
|
699
|
+
}
|
700
|
+
|
701
|
+
/*
|
702
|
+
* call-seq:
|
703
|
+
* wiimote.aspect_ratio -> string
|
704
|
+
*
|
705
|
+
* Returns a string identificating the aspect ratio of the TV/monitor.
|
706
|
+
*
|
707
|
+
*/
|
708
|
+
|
709
|
+
static VALUE rb_wm_aratio(VALUE self) {
|
710
|
+
wiimote *wm;
|
711
|
+
Data_Get_Struct(self,wiimote,wm);
|
712
|
+
if(!wm) return Qnil;
|
713
|
+
wiiuse_status(wm);
|
714
|
+
if (wm->ir.aspect == WIIUSE_ASPECT_4_3) return rb_str_new2("4:3");
|
715
|
+
else if (wm->ir.aspect == WIIUSE_ASPECT_16_9) return rb_str_new2("16:9");
|
716
|
+
return Qnil;
|
717
|
+
}
|
718
|
+
|
719
|
+
/*
|
720
|
+
* call-seq:
|
721
|
+
* wiimote.aspect_ratio = ratio -> (value of aspect ratio constant)
|
722
|
+
*
|
723
|
+
* Sets the aspect ratio of the TV/monitor of <i>self</i> to <i>ratio</i>.
|
724
|
+
*
|
725
|
+
*/
|
726
|
+
|
727
|
+
static VALUE rb_wm_set_aratio(VALUE self, VALUE arg) {
|
728
|
+
wiimote *wm;
|
729
|
+
Data_Get_Struct(self,wiimote,wm);
|
730
|
+
if(!wm) return Qnil;
|
731
|
+
Check_Type(arg, T_FIXNUM);
|
732
|
+
wiiuse_set_aspect_ratio(wm,NUM2INT(arg));
|
733
|
+
return Qnil;
|
734
|
+
}
|
735
|
+
|
736
|
+
/*
|
737
|
+
* call-seq:
|
738
|
+
* wiimote.virtual_resolution -> array
|
739
|
+
*
|
740
|
+
* Returns an array containing the virtual resolution [n. pixel x, n. pixel y].
|
741
|
+
*
|
742
|
+
*/
|
743
|
+
|
744
|
+
static VALUE rb_wm_vres(VALUE self) {
|
745
|
+
wiimote *wm;
|
746
|
+
Data_Get_Struct(self,wiimote,wm);
|
747
|
+
if(!wm) return Qnil;
|
748
|
+
VALUE v_res = rb_ary_new();
|
749
|
+
rb_ary_push(v_res, INT2NUM(wm->ir.vres[0]));
|
750
|
+
rb_ary_push(v_res, INT2NUM(wm->ir.vres[1]));
|
751
|
+
return v_res;
|
752
|
+
}
|
753
|
+
|
754
|
+
/*
|
755
|
+
* call-seq:
|
756
|
+
* wiimote.virtual_resolution = resolution_array -> array
|
757
|
+
*
|
758
|
+
* Sets the virtual resolution of the screen to the values in the <i>resolution_array</i>.
|
759
|
+
*
|
760
|
+
*/
|
761
|
+
|
762
|
+
static VALUE rb_wm_set_vres(VALUE self, VALUE arg) {
|
763
|
+
wiimote *wm;
|
764
|
+
Data_Get_Struct(self,wiimote,wm);
|
765
|
+
if(!wm) return Qnil;
|
766
|
+
Check_Type(arg, T_ARRAY);
|
767
|
+
|
768
|
+
VALUE v_ary[2],argv[1];
|
769
|
+
int i = 0;
|
770
|
+
for(;i < 2;i++)
|
771
|
+
{
|
772
|
+
argv[0] = INT2NUM(i);
|
773
|
+
v_ary[i] = rb_ary_aref(1, argv, arg);
|
774
|
+
Check_Type(v_ary[i], T_FIXNUM);
|
775
|
+
}
|
776
|
+
wiiuse_set_ir_vres(wm, NUM2INT(v_ary[0]), NUM2INT(v_ary[1]));
|
777
|
+
return Qnil;
|
778
|
+
}
|
779
|
+
|
780
|
+
/*
|
781
|
+
* call-seq:
|
782
|
+
* wiimote.sensor_bar_position -> string
|
783
|
+
*
|
784
|
+
* Returns a string which represents the position of the sensor bar relative to <i>self</i>.
|
785
|
+
*
|
786
|
+
*/
|
787
|
+
|
788
|
+
static VALUE rb_wm_pos(VALUE self) {
|
789
|
+
wiimote *wm;
|
790
|
+
Data_Get_Struct(self,wiimote,wm);
|
791
|
+
if(!wm) return Qnil;
|
792
|
+
if(wm->ir.pos == WIIUSE_IR_ABOVE) return rb_str_new2("ABOVE");
|
793
|
+
else if (wm->ir.pos == WIIUSE_IR_BELOW) return rb_str_new2("BELOW");
|
794
|
+
return Qnil;
|
795
|
+
}
|
796
|
+
|
797
|
+
/*
|
798
|
+
* call-seq:
|
799
|
+
* wiimote.sensor_bar_position = pos -> int
|
800
|
+
*
|
801
|
+
* Sets the sensor bar position relative to <i>self</i> to <i>pos</i>.
|
802
|
+
*
|
803
|
+
*/
|
804
|
+
|
805
|
+
static VALUE rb_wm_set_pos(VALUE self, VALUE arg) {
|
806
|
+
wiimote *wm;
|
807
|
+
Data_Get_Struct(self,wiimote,wm);
|
808
|
+
if(!wm) return Qnil;
|
809
|
+
wiiuse_set_ir_position(wm,NUM2INT(arg));
|
810
|
+
return Qnil;
|
811
|
+
}
|
812
|
+
|
813
|
+
/*
|
814
|
+
* call-seq:
|
815
|
+
* wiimote.led -> string
|
816
|
+
*
|
817
|
+
* Returns a string which represents the led actually on.
|
818
|
+
*
|
819
|
+
*/
|
820
|
+
|
821
|
+
static VALUE rb_wm_led(VALUE self) {
|
822
|
+
wiimote *wm;
|
823
|
+
Data_Get_Struct(self, wiimote, wm);
|
824
|
+
if(!wm) return Qnil;
|
825
|
+
if(WIIUSE_IS_LED_SET(wm, 1)) return rb_str_new2("LED_1");
|
826
|
+
if(WIIUSE_IS_LED_SET(wm, 2)) return rb_str_new2("LED_2");
|
827
|
+
if(WIIUSE_IS_LED_SET(wm, 3)) return rb_str_new2("LED_3");
|
828
|
+
if(WIIUSE_IS_LED_SET(wm, 4)) return rb_str_new2("LED_4");
|
829
|
+
return Qnil;
|
830
|
+
}
|
831
|
+
|
832
|
+
/*
|
833
|
+
* call-seq:
|
834
|
+
* wiimote.expansion? -> true or false
|
835
|
+
* wiimote.expansion?(exp) -> true or false
|
836
|
+
*
|
837
|
+
* The first form returns true if a expansion is inserted into <i>self</i>.
|
838
|
+
* The second one return true if the expansion <i>exp</i> is inserted into <i>self</i>.
|
839
|
+
*
|
840
|
+
*/
|
841
|
+
|
842
|
+
static VALUE rb_wm_exp(int argc, VALUE * argv, VALUE self) {
|
843
|
+
wiimote *wm;
|
844
|
+
Data_Get_Struct(self, wiimote, wm);
|
845
|
+
if(!wm) return Qnil;
|
846
|
+
if(argc == 0) {
|
847
|
+
if(wm->exp.type != EXP_NONE) {
|
848
|
+
return Qtrue;
|
849
|
+
}
|
850
|
+
else {
|
851
|
+
return Qfalse;
|
852
|
+
}
|
853
|
+
}
|
854
|
+
else {
|
855
|
+
Check_Type(argv[0], T_FIXNUM);
|
856
|
+
switch(wm->exp.type) {
|
857
|
+
case EXP_NONE:
|
858
|
+
return Qfalse;
|
859
|
+
case EXP_NUNCHUK:
|
860
|
+
if(NUM2INT(argv[0]) == EXP_NUNCHUK) return Qtrue;
|
861
|
+
else return Qfalse;
|
862
|
+
case EXP_CLASSIC:
|
863
|
+
if(NUM2INT(argv[0]) == EXP_CLASSIC) return Qtrue;
|
864
|
+
else return Qfalse;
|
865
|
+
case EXP_GUITAR_HERO_3:
|
866
|
+
if(NUM2INT(argv[0]) == EXP_GUITAR_HERO_3) return Qtrue;
|
867
|
+
else return Qfalse;
|
868
|
+
}
|
869
|
+
}
|
870
|
+
return Qfalse;
|
871
|
+
}
|
872
|
+
|
873
|
+
/*
|
874
|
+
* call-seq:
|
875
|
+
* wiimote.has_nunchuk? -> true or false
|
876
|
+
*
|
877
|
+
* Returns true if a nunchuk is attached to <i>self</i>.
|
878
|
+
*
|
879
|
+
*/
|
880
|
+
|
881
|
+
static VALUE rb_wm_nunchuk(VALUE self) {
|
882
|
+
wiimote *wm;
|
883
|
+
Data_Get_Struct(self, wiimote, wm);
|
884
|
+
if(!wm) return Qnil;
|
885
|
+
if(wm->exp.type == EXP_NUNCHUK) return Qtrue;
|
886
|
+
else return Qfalse;
|
887
|
+
}
|
888
|
+
|
889
|
+
/*
|
890
|
+
* call-seq:
|
891
|
+
* wiimote.has_classic_controller? ->true or false
|
892
|
+
*
|
893
|
+
* Returns true if a classic controller is attached to <i>self</i>.
|
894
|
+
*
|
895
|
+
*/
|
896
|
+
|
897
|
+
static VALUE rb_wm_cc(VALUE self) {
|
898
|
+
wiimote *wm;
|
899
|
+
Data_Get_Struct(self, wiimote, wm);
|
900
|
+
if(!wm) return Qnil;
|
901
|
+
if(wm->exp.type == EXP_CLASSIC) return Qtrue;
|
902
|
+
else return Qfalse;
|
903
|
+
}
|
904
|
+
|
905
|
+
/*
|
906
|
+
* call-seq:
|
907
|
+
* wiimote.has_guitar_hero_controller? -> true or false
|
908
|
+
*
|
909
|
+
* Returns true if a guitar hero 3 controller is attached to <i>self</i>.
|
910
|
+
*
|
911
|
+
*/
|
912
|
+
|
913
|
+
static VALUE rb_wm_gh(VALUE self) {
|
914
|
+
wiimote *wm;
|
915
|
+
Data_Get_Struct(self, wiimote, wm);
|
916
|
+
if(!wm) return Qnil;
|
917
|
+
if(wm->exp.type == EXP_GUITAR_HERO_3) return Qtrue;
|
918
|
+
else return Qfalse;
|
919
|
+
}
|
920
|
+
|
921
|
+
/*
|
922
|
+
* call-seq:
|
923
|
+
* wiimote.absolute_position -> array
|
924
|
+
*
|
925
|
+
* Returns an array containing the absolute position [x, y] of <i>self</i>.
|
926
|
+
*
|
927
|
+
*/
|
928
|
+
|
929
|
+
static VALUE rb_wm_ir_acursor(VALUE self) {
|
930
|
+
wiimote *wm;
|
931
|
+
Data_Get_Struct(self, wiimote, wm);
|
932
|
+
if(!wm) return Qnil;
|
933
|
+
VALUE ary = rb_ary_new();
|
934
|
+
rb_ary_push(ary, INT2NUM(wm->ir.ax));
|
935
|
+
rb_ary_push(ary, INT2NUM(wm->ir.ay));
|
936
|
+
return ary;
|
937
|
+
}
|
938
|
+
|
939
|
+
/*
|
940
|
+
* call-seq:
|
941
|
+
* wiimote.acceleration -> array
|
942
|
+
*
|
943
|
+
* Returns an array containing the three components of acceleration [x, y, z] of <i>self</i>.
|
944
|
+
*
|
945
|
+
*/
|
946
|
+
|
947
|
+
static VALUE rb_wm_accel(VALUE self) {
|
948
|
+
wiimote *wm;
|
949
|
+
Data_Get_Struct(self, wiimote, wm);
|
950
|
+
if(!wm) return Qnil;
|
951
|
+
VALUE ary = rb_ary_new();
|
952
|
+
rb_ary_push(ary, INT2NUM(wm->accel.x));
|
953
|
+
rb_ary_push(ary, INT2NUM(wm->accel.y));
|
954
|
+
rb_ary_push(ary, INT2NUM(wm->accel.z));
|
955
|
+
return ary;
|
956
|
+
}
|
957
|
+
|
958
|
+
/*
|
959
|
+
* call-seq:
|
960
|
+
* wiimote.gravity_force -> array
|
961
|
+
*
|
962
|
+
* Returns an array containing the three components of gravity force [x, y, z] of <i>self</i>.
|
963
|
+
*
|
964
|
+
*/
|
965
|
+
|
966
|
+
static VALUE rb_wm_gforce(VALUE self) {
|
967
|
+
wiimote *wm;
|
968
|
+
Data_Get_Struct(self, wiimote, wm);
|
969
|
+
if(!wm) return Qnil;
|
970
|
+
VALUE ary = rb_ary_new();
|
971
|
+
rb_ary_push(ary, rb_float_new(wm->gforce.x));
|
972
|
+
rb_ary_push(ary, rb_float_new(wm->gforce.y));
|
973
|
+
rb_ary_push(ary, rb_float_new(wm->gforce.z));
|
974
|
+
return ary;
|
975
|
+
}
|
976
|
+
|
977
|
+
/*
|
978
|
+
* call-seq:
|
979
|
+
* wiimote.accel_threshold -> float
|
980
|
+
*
|
981
|
+
* Returns the accelerometer event threshold for <i>self</i>.
|
982
|
+
*
|
983
|
+
*/
|
984
|
+
|
985
|
+
static VALUE rb_wm_accel_threshold(VALUE self) {
|
986
|
+
wiimote *wm;
|
987
|
+
Data_Get_Struct(self, wiimote, wm);
|
988
|
+
if(!wm) return Qnil;
|
989
|
+
return INT2NUM(wm->accel_threshold);
|
990
|
+
}
|
991
|
+
|
992
|
+
/*
|
993
|
+
* call-seq:
|
994
|
+
* wiimote.accel_threshold = t -> int
|
995
|
+
*
|
996
|
+
* Sets the accelerometer event threshold for <i>self</i>.
|
997
|
+
*
|
998
|
+
*/
|
999
|
+
|
1000
|
+
static VALUE rb_wm_set_accel_threshold(VALUE self, VALUE arg) {
|
1001
|
+
wiimote *wm;
|
1002
|
+
Data_Get_Struct(self, wiimote, wm);
|
1003
|
+
if(!wm) return Qnil;
|
1004
|
+
wiiuse_set_accel_threshold(wm, NUM2INT(arg));
|
1005
|
+
return Qnil;
|
1006
|
+
}
|
1007
|
+
|
1008
|
+
/*
|
1009
|
+
* call-seq:
|
1010
|
+
* wiimote.orient_threshold -> float
|
1011
|
+
*
|
1012
|
+
* Returns the orientation event threshold for <i>self</i>.
|
1013
|
+
*
|
1014
|
+
*/
|
1015
|
+
|
1016
|
+
static VALUE rb_wm_orient_threshold(VALUE self) {
|
1017
|
+
wiimote *wm;
|
1018
|
+
Data_Get_Struct(self, wiimote, wm);
|
1019
|
+
if(!wm) return Qnil;
|
1020
|
+
return INT2NUM(wm->orient_threshold);
|
1021
|
+
}
|
1022
|
+
|
1023
|
+
/*
|
1024
|
+
* call-seq:
|
1025
|
+
* wiimote.orient_threshold = t -> float
|
1026
|
+
*
|
1027
|
+
* Sets the orientation event threshold for <i>self</i>.
|
1028
|
+
*
|
1029
|
+
*/
|
1030
|
+
|
1031
|
+
static VALUE rb_wm_set_orient_threshold(VALUE self, VALUE arg) {
|
1032
|
+
wiimote *wm;
|
1033
|
+
Data_Get_Struct(self, wiimote, wm);
|
1034
|
+
if(!wm) return Qnil;
|
1035
|
+
wiiuse_set_orient_threshold(wm,(float)NUM2DBL(arg));
|
1036
|
+
return Qnil;
|
1037
|
+
}
|
1038
|
+
|
1039
|
+
/*
|
1040
|
+
* call-seq:
|
1041
|
+
* wiimote.nunchuk_accel_threshold = t -> int
|
1042
|
+
*
|
1043
|
+
* Sets the accelerometer event threshold for the nunchuk attached to <i>self</i>.
|
1044
|
+
*
|
1045
|
+
*/
|
1046
|
+
|
1047
|
+
static VALUE rb_wm_set_nun_athreshold(VALUE self, VALUE arg) {
|
1048
|
+
wiimote *wm;
|
1049
|
+
VALUE nun = rb_funcall(self, rb_intern("has_nunchuk?"), 0, NULL);
|
1050
|
+
if(nun == Qtrue) {
|
1051
|
+
Data_Get_Struct(self, wiimote, wm);
|
1052
|
+
if(!wm) return Qnil;
|
1053
|
+
Check_Type(arg, T_FIXNUM);
|
1054
|
+
wiiuse_set_nunchuk_accel_threshold(wm, NUM2INT(arg));
|
1055
|
+
}
|
1056
|
+
return Qnil;
|
1057
|
+
}
|
1058
|
+
|
1059
|
+
/*
|
1060
|
+
* call-seq:
|
1061
|
+
* wiimote.nunchuk_orient_threshold = t -> float
|
1062
|
+
*
|
1063
|
+
* Sets the orientation event threshold for the nunchuk attached to <i>self</i>.
|
1064
|
+
*
|
1065
|
+
*/
|
1066
|
+
|
1067
|
+
static VALUE rb_wm_set_nun_othreshold(VALUE self, VALUE arg) {
|
1068
|
+
wiimote *wm;
|
1069
|
+
VALUE nun = rb_funcall(self, rb_intern("has_nunchuk?"), 0, NULL);
|
1070
|
+
if(nun == Qtrue) {
|
1071
|
+
Data_Get_Struct(self, wiimote, wm);
|
1072
|
+
if(!wm) return Qnil;
|
1073
|
+
Check_Type(arg, T_FLOAT);
|
1074
|
+
wiiuse_set_nunchuk_orient_threshold(wm, (float)NUM2DBL(arg));
|
1075
|
+
}
|
1076
|
+
return Qnil;
|
1077
|
+
}
|
1078
|
+
|
1079
|
+
/*
|
1080
|
+
* call-seq:
|
1081
|
+
* wiimote.speaker = true or false -> true or false
|
1082
|
+
*
|
1083
|
+
* Activates the speaker of <i>self</i>.
|
1084
|
+
*
|
1085
|
+
*/
|
1086
|
+
|
1087
|
+
static VALUE rb_wm_set_speaker(VALUE self, VALUE arg) {
|
1088
|
+
wiimote *wm;
|
1089
|
+
Data_Get_Struct(self, wiimote, wm);
|
1090
|
+
if(!wm) return Qnil;
|
1091
|
+
int speaker = 0;
|
1092
|
+
if(arg == Qtrue) speaker = 1;
|
1093
|
+
else if(arg != Qfalse) rb_raise(rb_eTypeError, "Invalid Argument");
|
1094
|
+
wiiuse_set_speaker(wm, speaker);
|
1095
|
+
return Qnil;
|
1096
|
+
}
|
1097
|
+
|
1098
|
+
/*
|
1099
|
+
* call-seq:
|
1100
|
+
* wiimote.mute! -> nil
|
1101
|
+
*
|
1102
|
+
* Mutes the speaker of <i>self</i>.
|
1103
|
+
*
|
1104
|
+
*/
|
1105
|
+
|
1106
|
+
static VALUE rb_wm_mute_speaker(VALUE self) {
|
1107
|
+
wiimote *wm;
|
1108
|
+
Data_Get_Struct(self, wiimote, wm);
|
1109
|
+
if(!wm) return Qnil;
|
1110
|
+
wiiuse_mute_speaker(wm, 1);
|
1111
|
+
return Qnil;
|
1112
|
+
}
|
1113
|
+
|
1114
|
+
/*
|
1115
|
+
* call-seq:
|
1116
|
+
* wiimote.unmute! -> nil
|
1117
|
+
*
|
1118
|
+
* Unmutes the speaker of <i>self</i>.
|
1119
|
+
*
|
1120
|
+
*/
|
1121
|
+
|
1122
|
+
static VALUE rb_wm_unmute_speaker(VALUE self) {
|
1123
|
+
wiimote *wm;
|
1124
|
+
Data_Get_Struct(self, wiimote, wm);
|
1125
|
+
if(!wm) return Qnil;
|
1126
|
+
wiiuse_mute_speaker(wm, 0);
|
1127
|
+
return Qnil;
|
1128
|
+
}
|
1129
|
+
|
1130
|
+
/*
|
1131
|
+
* call-seq:
|
1132
|
+
* wiimote.play(wav_file_path) -> nil
|
1133
|
+
*
|
1134
|
+
* Plays the 16 bit WAV file passed as argument, converting it to the right format for the wiimote speaker.
|
1135
|
+
* If speaker is disabled or muted it'll be enabled/unmuted first.
|
1136
|
+
*
|
1137
|
+
*/
|
1138
|
+
|
1139
|
+
static VALUE rb_wm_play(VALUE self, VALUE file) {
|
1140
|
+
wiimote *wm;
|
1141
|
+
Data_Get_Struct(self, wiimote, wm);
|
1142
|
+
if(!wm) return Qnil;
|
1143
|
+
Check_Type(file, T_STRING);
|
1144
|
+
|
1145
|
+
byte *w_sample = NULL;
|
1146
|
+
w_sample = wiiuse_convert_wav(StringValue(file), 10);
|
1147
|
+
if(!WIIUSE_USING_SPEAKER(wm))
|
1148
|
+
wiiuse_set_speaker(wm, 1);
|
1149
|
+
if(WIIUSE_SPEAKER_MUTE(wm))
|
1150
|
+
wiiuse_mute_speaker(wm, 0);
|
1151
|
+
wiiuse_play_sound(wm, w_sample, sizeof(w_sample));
|
1152
|
+
return Qnil;
|
1153
|
+
}
|
1154
|
+
|
1155
|
+
static VALUE rb_wm_ps(VALUE self) {
|
1156
|
+
wiimote *wm;
|
1157
|
+
Data_Get_Struct(self, wiimote, wm);
|
1158
|
+
if(!WIIUSE_USING_SPEAKER(wm))
|
1159
|
+
wiiuse_set_speaker(wm, 1);
|
1160
|
+
if(WIIUSE_SPEAKER_MUTE(wm))
|
1161
|
+
wiiuse_mute_speaker(wm, 0);
|
1162
|
+
byte song[8] = { 0xCC, 0x33, 0xCC, 0x33, 0xCC, 0x33, 0xCC, 0x33 };
|
1163
|
+
wiiuse_play_sound(wm, song, 8);
|
1164
|
+
return Qnil;
|
1165
|
+
}
|
1166
|
+
|
1167
|
+
|
1168
|
+
/*
|
1169
|
+
* call-seq:
|
1170
|
+
* wiimote.exp -> Nunchuk or ClassicController or GH3Controller
|
1171
|
+
*
|
1172
|
+
* Returns an object representating the expansion attached to <i>self</i>.
|
1173
|
+
*
|
1174
|
+
*/
|
1175
|
+
|
1176
|
+
static VALUE rb_wm_get_exp(VALUE self) {
|
1177
|
+
return rb_iv_get(self, "@exp");
|
1178
|
+
}
|
1179
|
+
|
1180
|
+
/*
|
1181
|
+
*
|
1182
|
+
* Provides a set of methods to access Wiimote functionalities.
|
1183
|
+
* A Wiimote object can:
|
1184
|
+
* - put the wiimote in rumble state
|
1185
|
+
* - control the leds
|
1186
|
+
* - control and access accelerometer measurement
|
1187
|
+
* - control and access ir camera measurement
|
1188
|
+
* - manage expansions
|
1189
|
+
* - manage pressed, held, released buttons
|
1190
|
+
* - access battery level, acceleration vector and gravity vector
|
1191
|
+
*
|
1192
|
+
*/
|
1193
|
+
|
1194
|
+
void init_wiimote(void) {
|
1195
|
+
|
1196
|
+
wii_class = rb_define_class_under(cm_class, "Wiimote", rb_cObject);
|
1197
|
+
//rb_define_singleton_method(wii_class, "new", rb_wm_new, 0);
|
1198
|
+
rb_define_method(wii_class, "initialize", rb_wm_init, 0);
|
1199
|
+
rb_define_method(wii_class, "disconnect!", rb_wm_disconnect, 0);
|
1200
|
+
rb_define_method(wii_class, "rumble?", rb_wm_get_rumble, 0);
|
1201
|
+
rb_define_method(wii_class, "rumble=", rb_wm_set_rumble, 1);
|
1202
|
+
rb_define_method(wii_class, "rumble!", rb_wm_rumble, -1);
|
1203
|
+
rb_define_method(wii_class, "stop!", rb_wm_stop, 0);
|
1204
|
+
rb_define_method(wii_class, "leds=", rb_wm_leds, 1);
|
1205
|
+
rb_define_method(wii_class, "led", rb_wm_led, 0);
|
1206
|
+
rb_define_method(wii_class, "turn_off_leds!", rb_wm_turnoff, 0);
|
1207
|
+
rb_define_method(wii_class, "motion_sensing?", rb_wm_get_ms, 0);
|
1208
|
+
rb_define_method(wii_class, "motion_sensing=", rb_wm_set_ms, 1);
|
1209
|
+
rb_define_method(wii_class, "status", rb_wm_status, 0);
|
1210
|
+
rb_define_method(wii_class, "connected?", rb_wm_connected, 0);
|
1211
|
+
rb_define_method(wii_class, "expansion?", rb_wm_exp, -1);
|
1212
|
+
rb_define_method(wii_class, "has_nunchuk?", rb_wm_nunchuk, 0);
|
1213
|
+
rb_define_method(wii_class, "has_classic_controller?", rb_wm_cc, 0);
|
1214
|
+
rb_define_method(wii_class, "has_guitar_hero_controller?", rb_wm_gh, 0);
|
1215
|
+
rb_define_method(wii_class, "pressed?", rb_wm_pressed, 1);
|
1216
|
+
rb_define_method(wii_class, "just_pressed?", rb_wm_just_pressed, 1);
|
1217
|
+
rb_define_method(wii_class, "held?", rb_wm_held, 1);
|
1218
|
+
rb_define_method(wii_class, "released?", rb_wm_released, 1);
|
1219
|
+
rb_define_alias(wii_class, "using_accelerometer?", "motion_sensing?");
|
1220
|
+
rb_define_method(wii_class, "roll", rb_wm_roll, 0);
|
1221
|
+
rb_define_method(wii_class, "absolute_roll", rb_wm_aroll, 0);
|
1222
|
+
rb_define_method(wii_class, "pitch", rb_wm_pitch, 0);
|
1223
|
+
rb_define_method(wii_class, "absolute_pitch", rb_wm_apitch, 0);
|
1224
|
+
rb_define_method(wii_class, "yaw", rb_wm_yaw, 0);
|
1225
|
+
rb_define_method(wii_class, "using_ir?", rb_wm_ir, 0);
|
1226
|
+
rb_define_method(wii_class, "ir_sources", rb_wm_ir_sources, 0);
|
1227
|
+
rb_define_method(wii_class, "position", rb_wm_ir_cursor, 0);
|
1228
|
+
rb_define_method(wii_class, "absolute_position", rb_wm_ir_acursor, 0);
|
1229
|
+
rb_define_method(wii_class, "distance", rb_wm_ir_z, 0);
|
1230
|
+
rb_define_method(wii_class, "ir=", rb_wm_set_ir, 1);
|
1231
|
+
rb_define_method(wii_class, "speaker=", rb_wm_set_speaker, 1);
|
1232
|
+
rb_define_method(wii_class, "speaker?", rb_wm_speaker, 0);
|
1233
|
+
rb_define_method(wii_class, "play", rb_wm_play, 1);
|
1234
|
+
rb_define_method(wii_class, "play_sound", rb_wm_ps, 0);
|
1235
|
+
rb_define_method(wii_class, "mute!", rb_wm_mute_speaker, 0);
|
1236
|
+
//rb_define_method(wii_class, "muted?", rb_wm_muted, 0);
|
1237
|
+
//rb_define_method(wii_class, "playing?", rb_wm_playing, 0);
|
1238
|
+
rb_define_method(wii_class, "unmute!", rb_wm_unmute_speaker, 0);
|
1239
|
+
rb_define_method(wii_class, "exp", rb_wm_get_exp, 0);
|
1240
|
+
rb_define_method(wii_class, "sensitivity", rb_wm_sensitivity, 0);
|
1241
|
+
rb_define_method(wii_class, "sensitivity=", rb_wm_set_sens, 1);
|
1242
|
+
rb_define_method(wii_class, "sensor_bar_position", rb_wm_pos, 0);
|
1243
|
+
rb_define_method(wii_class, "sensor_bar_position=", rb_wm_set_pos, 1);
|
1244
|
+
rb_define_method(wii_class, "virtual_resolution=", rb_wm_set_vres, 1);
|
1245
|
+
rb_define_method(wii_class, "virtual_resolution", rb_wm_vres, 0);
|
1246
|
+
rb_define_method(wii_class, "aspect_ratio=", rb_wm_set_aratio, 1);
|
1247
|
+
rb_define_method(wii_class, "aspect_ratio", rb_wm_aratio, 0);
|
1248
|
+
rb_define_method(wii_class, "battery_level", rb_wm_bl, 0);
|
1249
|
+
rb_define_method(wii_class, "acceleration", rb_wm_accel, 0);
|
1250
|
+
rb_define_method(wii_class, "gravity_force", rb_wm_gforce, 0);
|
1251
|
+
rb_define_method(wii_class, "orient_threshold", rb_wm_orient_threshold, 0);
|
1252
|
+
rb_define_method(wii_class, "orient_threshold=", rb_wm_set_orient_threshold, 1);
|
1253
|
+
rb_define_method(wii_class, "nunchuk_orient_threshold=", rb_wm_set_nun_othreshold, 1);
|
1254
|
+
rb_define_method(wii_class, "nunchuk_accel_threshold=", rb_wm_set_nun_athreshold, 1);
|
1255
|
+
rb_define_method(wii_class, "accel_threshold", rb_wm_accel_threshold, 0);
|
1256
|
+
rb_define_method(wii_class, "accel_threshold=", rb_wm_set_accel_threshold, 1);
|
1257
|
+
|
1258
|
+
}
|