wii4r 0.5.0-x86-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,310 @@
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
+ /*
27
+ * call-seq:
28
+ * nunchuk.pressed?(button) -> true or false
29
+ *
30
+ * Returns true if <i>button</i> is being pressed on <i>self</i>.
31
+ *
32
+ */
33
+
34
+ static VALUE rb_nun_pressed(VALUE self, VALUE arg) {
35
+ nunchuk_t *nun;
36
+ Data_Get_Struct(self, nunchuk_t, nun);
37
+ if(!nun) return Qnil;
38
+ Check_Type(arg, T_FIXNUM);
39
+ if(IS_PRESSED(nun, NUM2INT(arg)))
40
+ return Qtrue;
41
+ else
42
+ return Qfalse;
43
+ }
44
+
45
+ /*
46
+ * call-seq:
47
+ * nunchuk.just_pressed?(button) -> true of false
48
+ *
49
+ * Returns true if <i>button</i> is just pressed on <i>self</i>.
50
+ *
51
+ */
52
+
53
+ static VALUE rb_nun_jpressed(VALUE self, VALUE arg) {
54
+ nunchuk_t *nun;
55
+ Data_Get_Struct(self, nunchuk_t, nun);
56
+ if(!nun) return Qnil;
57
+ Check_Type(arg, T_FIXNUM);
58
+ if(IS_JUST_PRESSED(nun, NUM2INT(arg)))
59
+ return Qtrue;
60
+ else
61
+ return Qfalse;
62
+ }
63
+
64
+ /*
65
+ * call-seq:
66
+ * nunchuk.held?(button) -> true of false
67
+ *
68
+ * Returns true if <i>button</i> is being held on <i>self</i>.
69
+ *
70
+ */
71
+
72
+ static VALUE rb_nun_held(VALUE self, VALUE arg) {
73
+ nunchuk_t *nun;
74
+ Data_Get_Struct(self, nunchuk_t, nun);
75
+ if(!nun) return Qnil;
76
+ Check_Type(arg, T_FIXNUM);
77
+ if(IS_HELD(nun, NUM2INT(arg)))
78
+ return Qtrue;
79
+ else
80
+ return Qfalse;
81
+ }
82
+
83
+ /*
84
+ * call-seq:
85
+ * nunchuk.released?(button) -> true or false
86
+ *
87
+ * Returns true if <i>button</i> is just released on <i>self</i>.
88
+ *
89
+ */
90
+
91
+ static VALUE rb_nun_rel(VALUE self, VALUE arg) {
92
+ nunchuk_t *nun;
93
+ Data_Get_Struct(self, nunchuk_t, nun);
94
+ if(!nun) return Qnil;
95
+ Check_Type(arg, T_FIXNUM);
96
+ if(IS_RELEASED(nun, NUM2INT(arg)))
97
+ return Qtrue;
98
+ else
99
+ return Qfalse;
100
+ }
101
+
102
+ /*
103
+ * call-seq:
104
+ * nunchuk.pitch -> float
105
+ *
106
+ * Returns the rotation around X axis (works with motion sensing activated).
107
+ *
108
+ * Range: [-179.9, -0.1] [0.1, 179.9]
109
+ *
110
+ */
111
+
112
+ static VALUE rb_nun_pitch(VALUE self) {
113
+ nunchuk_t *nun;
114
+ Data_Get_Struct(self, nunchuk_t, nun);
115
+ if(!nun) return Qnil;
116
+ return rb_float_new(nun->orient.pitch);
117
+ }
118
+
119
+ /*
120
+ * call-seq:
121
+ * nunchuk.absolute_pitch -> float
122
+ *
123
+ * Returns the absolute rotation around X axis (works with motion sensing activated).
124
+ *
125
+ * Range: [-179.9, -0.1] [0.1, 179.9]
126
+ *
127
+ */
128
+
129
+ static VALUE rb_nun_apitch(VALUE self) {
130
+ nunchuk_t *nun;
131
+ Data_Get_Struct(self, nunchuk_t, nun);
132
+ if(!nun) return Qnil;
133
+ return rb_float_new(nun->orient.a_pitch);
134
+ }
135
+
136
+ /*
137
+ * call-seq:
138
+ * nunchuk.roll -> float
139
+ *
140
+ * Returns the rotation around Y axis (works with motion sensing activated).
141
+ *
142
+ * Range: [-179.9, -0.1] [0.1, 179.9]
143
+ *
144
+ */
145
+
146
+ static VALUE rb_nun_roll(VALUE self) {
147
+ nunchuk_t *nun;
148
+ Data_Get_Struct(self, nunchuk_t, nun);
149
+ if(!nun) return Qnil;
150
+ return rb_float_new(nun->orient.roll);
151
+ }
152
+
153
+ /*
154
+ * call-seq:
155
+ * nunchuk.absolute_roll -> float
156
+ *
157
+ * Returns the absolute rotation around Y axis (works with motion sensing activated).
158
+ *
159
+ * Range: [-179.9, -0.1] [0.1, 179.9]
160
+ *
161
+ */
162
+
163
+ static VALUE rb_nun_aroll(VALUE self) {
164
+ nunchuk_t *nun;
165
+ Data_Get_Struct(self, nunchuk_t, nun);
166
+ if(!nun) return Qnil;
167
+ return rb_float_new(nun->orient.a_roll);
168
+ }
169
+
170
+ /*
171
+ * call-seq:
172
+ * nunchuk.acceleration -> array
173
+ *
174
+ * Returns an array containing the three components of acceleration [x, y, z] of <i>self</i>.
175
+ *
176
+ */
177
+
178
+ static VALUE rb_nun_accel(VALUE self) {
179
+ nunchuk_t *nun;
180
+ Data_Get_Struct(self, nunchuk_t, nun);
181
+ VALUE ary = rb_ary_new();
182
+ if(nun) {
183
+ rb_ary_push(ary, INT2NUM(nun->accel.x));
184
+ rb_ary_push(ary, INT2NUM(nun->accel.y));
185
+ rb_ary_push(ary, INT2NUM(nun->accel.z));
186
+ }
187
+ return ary;
188
+ }
189
+
190
+ /*
191
+ * call-seq:
192
+ * nunchuk.gravity_force -> array
193
+ *
194
+ * Returns an array containing the three components of gravity force [x, y, z] of <i>self</i>.
195
+ *
196
+ */
197
+
198
+ static VALUE rb_nun_gforce(VALUE self) {
199
+ nunchuk_t *nun;
200
+ Data_Get_Struct(self, nunchuk_t, nun);
201
+ VALUE ary = rb_ary_new();
202
+ if(nun) {
203
+ rb_ary_push(ary, INT2NUM(nun->gforce.x));
204
+ rb_ary_push(ary, INT2NUM(nun->gforce.y));
205
+ rb_ary_push(ary, INT2NUM(nun->gforce.z));
206
+ }
207
+ return ary;
208
+ }
209
+
210
+ /*
211
+ * call-seq:
212
+ * wiimote.accel_threshold -> int
213
+ *
214
+ * Returns the accelerometer event threshold for <i>self</i>.
215
+ *
216
+ */
217
+
218
+ static VALUE rb_nun_athreshold(VALUE self) {
219
+ nunchuk_t *nun;
220
+ Data_Get_Struct(self, nunchuk_t, nun);
221
+ if(!nun) return Qnil;
222
+ return INT2NUM(nun->accel_threshold);
223
+ }
224
+
225
+ /*
226
+ * call-seq:
227
+ * nunchuk.orient_threshold -> int
228
+ *
229
+ * Returns the orientation event threshold for <i>self</i>.
230
+ *
231
+ */
232
+
233
+ static VALUE rb_nun_othreshold(VALUE self) {
234
+ nunchuk_t *nun;
235
+ Data_Get_Struct(self, nunchuk_t, nun);
236
+ if(!nun) return Qnil;
237
+ return rb_float_new(nun->orient_threshold);
238
+ }
239
+
240
+ /*
241
+ * call-seq:
242
+ * nunchuk.joystick_angle -> float
243
+ *
244
+ * Returns the angle at which the joystick is being held.
245
+ *
246
+ * 0 => Straight up
247
+ *
248
+ * 90 => right
249
+ *
250
+ * 180 => down
251
+ *
252
+ * 270 => left
253
+ *
254
+ */
255
+
256
+ static VALUE rb_nun_jangle(VALUE self) {
257
+ nunchuk_t *nun;
258
+ Data_Get_Struct(self, nunchuk_t, nun);
259
+ if(!nun) return Qnil;
260
+ return rb_float_new(nun->js.ang);
261
+ }
262
+
263
+ /*
264
+ * call-seq:
265
+ * nunchuk.joystick_magnitude -> float
266
+ *
267
+ * Returns the magnitude at which the joystick is being held.
268
+ *
269
+ * Range: [0, 1]
270
+ *
271
+ * 0 => center
272
+ *
273
+ * 1 => edges
274
+ *
275
+ */
276
+
277
+ static VALUE rb_nun_jmag(VALUE self) {
278
+ nunchuk_t *nun;
279
+ Data_Get_Struct(self, nunchuk_t, nun);
280
+ if(!nun) return Qnil;
281
+ return rb_float_new(nun->js.mag);
282
+ }
283
+
284
+ /*
285
+ * Provides a set of methods for accessing Nunchuk properties and members.
286
+ * - button events (pressed, just pressed, released, held)
287
+ * - motion sensing capabilities (roll, pitch)
288
+ * - acceleration & gravity force vectors
289
+ * - joystick values (angle & magnitude)
290
+ *
291
+ */
292
+
293
+ void init_nunchuk() {
294
+ nun_class = rb_define_class_under(wii_class, "Nunchuk", rb_cObject);
295
+
296
+ rb_define_method(nun_class, "pressed?", rb_nun_pressed, 1);
297
+ rb_define_method(nun_class, "just_pressed?", rb_nun_jpressed, 1);
298
+ rb_define_method(nun_class, "held?", rb_nun_held, 1);
299
+ rb_define_method(nun_class, "released?", rb_nun_rel, 1);
300
+ rb_define_method(nun_class, "roll", rb_nun_roll, 0);
301
+ rb_define_method(nun_class, "absolute_roll", rb_nun_aroll, 0);
302
+ rb_define_method(nun_class, "pitch", rb_nun_pitch, 0);
303
+ rb_define_method(nun_class, "absolute_pitch", rb_nun_apitch, 0);
304
+ rb_define_method(nun_class, "acceleration", rb_nun_accel, 0);
305
+ rb_define_method(nun_class, "gravity_force", rb_nun_gforce, 0);
306
+ rb_define_method(nun_class, "orient_threshold", rb_nun_othreshold, 0);
307
+ rb_define_method(nun_class, "accel_thresold", rb_nun_athreshold, 0);
308
+ rb_define_method(nun_class, "joystick_angle", rb_nun_jangle, 0);
309
+ rb_define_method(nun_class, "joystick_magnitude", rb_nun_jmag, 0);
310
+ }
data/ext/wii4r/wii4r.c ADDED
@@ -0,0 +1,186 @@
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
+ //Wii module
27
+ VALUE wii_mod = Qnil;
28
+
29
+ //WiimoteManager class
30
+ VALUE cm_class = Qnil;
31
+
32
+ //Wiimote class
33
+ VALUE wii_class = Qnil;
34
+
35
+ //ClassicController class
36
+ VALUE cc_class = Qnil;
37
+
38
+ //GH3Controller class
39
+ VALUE gh3_class = Qnil;
40
+
41
+ //Nunchuk class
42
+ VALUE nun_class = Qnil;
43
+
44
+ //Wii4RGenericException class
45
+ VALUE gen_exp_class = Qnil;
46
+
47
+ //define Wiimote class
48
+ extern void init_wiimote(void);
49
+
50
+ //define WiimoteManager class
51
+ extern void init_wiimotemanager(void);
52
+
53
+ //define ClassicController class
54
+ extern void init_cc(void);
55
+
56
+ //define GH3Controller class
57
+ extern void init_gh3(void);
58
+
59
+ //define Nunchuk class
60
+ extern void init_nunchuk(void);
61
+
62
+ void init_exceptions(void) {
63
+ gen_exp_class = rb_define_class("Wii4RuntimeException", rb_eRuntimeError);
64
+ }
65
+
66
+ /*
67
+ * Document-class: Wii
68
+ *
69
+ * Module that encapsulates Wiimote and WiimoteManager classes and defines some constants
70
+ *
71
+ * Led Constants:
72
+ * - LED_1
73
+ * - LED_2
74
+ * - LED_3
75
+ * - LED_4
76
+ * - LED_NONE
77
+ *
78
+ * Wiimote Button Constants:
79
+ * - BUTTON_A
80
+ * - BUTTON_B
81
+ * - BUTTON_ONE
82
+ * - BUTTON_TWO
83
+ * - BUTTON_PLUS
84
+ * - BUTTON_MINUS
85
+ * - BUTTON_HOME
86
+ * - BUTTON_LEFT
87
+ * - BUTTON_RIGHT
88
+ * - BUTTON_UP
89
+ * - BUTTON_DOWN
90
+ *
91
+ * Expansion Constants:
92
+ * - EXP_NONE
93
+ * - EXP_NUNCHUK
94
+ * - EXP_CLASSIC
95
+ * - EXP_GUITAR
96
+ *
97
+ * Aspect Ratio Constants:
98
+ * - ASPECT_4_3
99
+ * - ASPECT_16_9
100
+ *
101
+ * Sensor Bar Position Constants:
102
+ * - ABOVE
103
+ * - BELOW
104
+ */
105
+
106
+ void Init_wii4r() {
107
+ wii_mod = rb_define_module("Wii");
108
+ rb_define_const(wii_mod, "MAX_WIIMOTES", INT2NUM(4));
109
+ rb_define_const(wii_mod, "TIMEOUT", INT2NUM(5));
110
+
111
+ //Wiimote led consts
112
+ rb_define_const(wii_mod, "LED_NONE", INT2NUM(WIIMOTE_LED_NONE));
113
+ rb_define_const(wii_mod, "LED_1", INT2NUM(WIIMOTE_LED_1));
114
+ rb_define_const(wii_mod, "LED_2", INT2NUM(WIIMOTE_LED_2));
115
+ rb_define_const(wii_mod, "LED_3", INT2NUM(WIIMOTE_LED_3));
116
+ rb_define_const(wii_mod, "LED_4", INT2NUM(WIIMOTE_LED_4));
117
+
118
+ //Wiimote button consts
119
+ rb_define_const(wii_mod, "BUTTON_A", INT2NUM(WIIMOTE_BUTTON_A));
120
+ rb_define_const(wii_mod, "BUTTON_B", INT2NUM(WIIMOTE_BUTTON_B));
121
+ rb_define_const(wii_mod, "BUTTON_ONE", INT2NUM(WIIMOTE_BUTTON_ONE));
122
+ rb_define_const(wii_mod, "BUTTON_TWO", INT2NUM(WIIMOTE_BUTTON_TWO));
123
+ rb_define_const(wii_mod, "BUTTON_PLUS", INT2NUM(WIIMOTE_BUTTON_PLUS));
124
+ rb_define_const(wii_mod, "BUTTON_MINUS", INT2NUM(WIIMOTE_BUTTON_MINUS));
125
+ rb_define_const(wii_mod, "BUTTON_HOME", INT2NUM(WIIMOTE_BUTTON_HOME));
126
+ rb_define_const(wii_mod, "BUTTON_LEFT", INT2NUM(WIIMOTE_BUTTON_LEFT));
127
+ rb_define_const(wii_mod, "BUTTON_RIGHT", INT2NUM(WIIMOTE_BUTTON_RIGHT));
128
+ rb_define_const(wii_mod, "BUTTON_DOWN", INT2NUM(WIIMOTE_BUTTON_DOWN));
129
+ rb_define_const(wii_mod, "BUTTON_UP", INT2NUM(WIIMOTE_BUTTON_UP));
130
+ rb_define_const(wii_mod, "BUTTON_ALL", INT2NUM(WIIMOTE_BUTTON_ALL));
131
+
132
+ //Wiimote nunchuk button consts
133
+ rb_define_const(wii_mod, "N_BUTTON_Z", INT2NUM(NUNCHUK_BUTTON_Z));
134
+ rb_define_const(wii_mod, "N_BUTTON_C", INT2NUM(NUNCHUK_BUTTON_C));
135
+ rb_define_const(wii_mod, "N_BUTTON_ALL", INT2NUM(NUNCHUK_BUTTON_ALL));
136
+
137
+ //Wiimote classic controller button codes
138
+ rb_define_const(wii_mod, "C_BUTTON_UP", INT2NUM(CLASSIC_CTRL_BUTTON_UP));
139
+ rb_define_const(wii_mod, "C_BUTTON_LEFT", INT2NUM(CLASSIC_CTRL_BUTTON_LEFT));
140
+ rb_define_const(wii_mod, "C_BUTTON_ZR", INT2NUM(CLASSIC_CTRL_BUTTON_ZR));
141
+ rb_define_const(wii_mod, "C_BUTTON_X", INT2NUM(CLASSIC_CTRL_BUTTON_X));
142
+ rb_define_const(wii_mod, "C_BUTTON_A", INT2NUM(CLASSIC_CTRL_BUTTON_A));
143
+ rb_define_const(wii_mod, "C_BUTTON_Y", INT2NUM(CLASSIC_CTRL_BUTTON_Y));
144
+ rb_define_const(wii_mod, "C_BUTTON_B", INT2NUM(CLASSIC_CTRL_BUTTON_B));
145
+ rb_define_const(wii_mod, "C_BUTTON_ZL", INT2NUM(CLASSIC_CTRL_BUTTON_ZL));
146
+ rb_define_const(wii_mod, "C_BUTTON_FULL_R", INT2NUM(CLASSIC_CTRL_BUTTON_FULL_R));
147
+ rb_define_const(wii_mod, "C_BUTTON_PLUS", INT2NUM(CLASSIC_CTRL_BUTTON_PLUS));
148
+ rb_define_const(wii_mod, "C_BUTTON_HOME", INT2NUM(CLASSIC_CTRL_BUTTON_HOME));
149
+ rb_define_const(wii_mod, "C_BUTTON_MINUS", INT2NUM(CLASSIC_CTRL_BUTTON_MINUS));
150
+ rb_define_const(wii_mod, "C_BUTTON_FULL_L", INT2NUM(CLASSIC_CTRL_BUTTON_FULL_L));
151
+ rb_define_const(wii_mod, "C_BUTTON_DOWN", INT2NUM(CLASSIC_CTRL_BUTTON_DOWN));
152
+ rb_define_const(wii_mod, "C_BUTTON_RIGHT", INT2NUM(CLASSIC_CTRL_BUTTON_RIGHT));
153
+ rb_define_const(wii_mod, "C_BUTTON_ALL", INT2NUM(CLASSIC_CTRL_BUTTON_ALL));
154
+
155
+ //Wiimote hero button codes
156
+ rb_define_const(wii_mod, "GUITAR_BUTTON_UP", INT2NUM(GUITAR_HERO_3_BUTTON_STRUM_UP));
157
+ rb_define_const(wii_mod, "GUITAR_BUTTON_YELLOW", INT2NUM(GUITAR_HERO_3_BUTTON_YELLOW));
158
+ rb_define_const(wii_mod, "GUITAR_BUTTON_GREEN", INT2NUM(GUITAR_HERO_3_BUTTON_GREEN));
159
+ rb_define_const(wii_mod, "GUITAR_BUTTON_BLUE", INT2NUM(GUITAR_HERO_3_BUTTON_BLUE));
160
+ rb_define_const(wii_mod, "GUITAR_BUTTON_RED", INT2NUM(GUITAR_HERO_3_BUTTON_RED));
161
+ rb_define_const(wii_mod, "GUITAR_BUTTON_ORANGE", INT2NUM(GUITAR_HERO_3_BUTTON_ORANGE));
162
+ rb_define_const(wii_mod, "GUITAR_BUTTON_PLUS", INT2NUM(GUITAR_HERO_3_BUTTON_PLUS));
163
+ rb_define_const(wii_mod, "GUITAR_BUTTON_MINUS", INT2NUM(GUITAR_HERO_3_BUTTON_MINUS));
164
+ rb_define_const(wii_mod, "GUITAR_BUTTON_DOWN", INT2NUM(GUITAR_HERO_3_BUTTON_STRUM_DOWN));
165
+ rb_define_const(wii_mod, "GUITAR_BUTTON_ALL", INT2NUM(GUITAR_HERO_3_BUTTON_ALL));
166
+
167
+ //Wiimote expansion codes
168
+ rb_define_const(wii_mod, "EXP_NONE", INT2NUM(EXP_NONE));
169
+ rb_define_const(wii_mod, "EXP_NUNCHUK", INT2NUM(EXP_NUNCHUK));
170
+ rb_define_const(wii_mod, "EXP_CLASSIC", INT2NUM(EXP_CLASSIC));
171
+ rb_define_const(wii_mod, "EXP_GUITAR", INT2NUM(EXP_GUITAR_HERO_3));
172
+
173
+ //Aspect ratio and sensor bar position constants
174
+ rb_define_const(wii_mod, "ASPECT_4_3", INT2NUM(WIIUSE_ASPECT_4_3));
175
+ rb_define_const(wii_mod, "ASPECT_16_9", INT2NUM(WIIUSE_ASPECT_16_9));
176
+ rb_define_const(wii_mod, "ABOVE", INT2NUM(WIIUSE_IR_ABOVE));
177
+ rb_define_const(wii_mod, "BELOW", INT2NUM(WIIUSE_IR_BELOW));
178
+
179
+ init_wiimotemanager();
180
+ init_wiimote();
181
+ init_nunchuk();
182
+ init_gh3();
183
+ init_cc();
184
+ init_exceptions();
185
+ }
186
+