wii4r 0.5.0-x86-linux

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,39 @@
1
+ = Wii4R
2
+
3
+ Ruby C Extension for controlling Wii Remote devices via bluetooth connection.
4
+ Binding of C wiiuse library (http://www.wiiuse.net)
5
+
6
+ == Install
7
+
8
+ $ make
9
+ $ make install
10
+ $ make clean
11
+
12
+ That should be all.
13
+
14
+ == Dependencies
15
+
16
+ * wiiuse lib (http://www.wiiuse.net) (lacks of speaker support and small fixes)
17
+ * wiiuse_fork (github) (lacks of speaker support as for now)
18
+
19
+ == Usage
20
+
21
+ require 'wii4r'
22
+ include Wii
23
+
24
+ w = WiimoteManager.new
25
+ w.connect
26
+ w.poll do |(wiimote, event)|
27
+ if event == :generic
28
+ if wiimote.pressed? BUTTON_A
29
+ puts "button a pressed!"
30
+ end
31
+ end
32
+ end
33
+
34
+ See rdoc documentation at doc/ for more details
35
+
36
+ == Copyright
37
+ Copyright (c) 2009 KzMz & BuZz.
38
+
39
+ LICENSE for details
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rake/extensiontask'
2
+
3
+ load "wii4r.gemspec"
4
+
5
+ Rake::GemPackageTask.new(GEM_SPEC) do |pkg|
6
+ pkg.need_zip = false
7
+ pkg.need_tar = false
8
+ end
9
+
10
+ Rake::ExtensionTask.new("wii4r", GEM_SPEC)
@@ -0,0 +1,14 @@
1
+ require 'wii4r'
2
+
3
+ include Wii
4
+
5
+ w = WiimoteManager.new
6
+
7
+ begin
8
+ w.connect
9
+
10
+ wm = w.wiimotes.first
11
+ wm.play_sound
12
+ ensure
13
+ w.cleanup!
14
+ end
data/examples/poll.rb ADDED
@@ -0,0 +1,104 @@
1
+ #! /usr/bin/env/ruby
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
+ require '../wii4r'
24
+ include Wii
25
+
26
+ def set_rumble(w)
27
+ w.rumble= w.rumble? ? false : true
28
+ end
29
+
30
+ def status(w)
31
+ puts w.status
32
+ end
33
+
34
+ def accel_on(w)
35
+ w.motion_sensing = true
36
+ puts "Pitch: #{w.pitch}"
37
+ puts "Roll: #{w.roll}"
38
+ w.motion_sensing = false
39
+ end
40
+
41
+ def vres(w)
42
+ puts "Virtual Resolution => #{w.virtual_resolution}"
43
+ end
44
+
45
+ def sens_pos(w)
46
+ puts "Sensor Bar Position => #{w.sensor_bar_position}"
47
+ end
48
+
49
+ def a_ratio(w)
50
+ puts "Aspect Ratio => #{w.aspect_ratio}"
51
+ end
52
+
53
+ def sens(w)
54
+ w.ir = true
55
+ puts "IR Sensitivity Level => #{w.sensitivity}"
56
+ end
57
+
58
+ def speaker(w)
59
+
60
+ if w.speaker?
61
+ puts "Wiimote is using speaker"
62
+ else puts "Wiimote is not using speaker"
63
+ end
64
+ end
65
+
66
+ begin
67
+
68
+ w = WiimoteManager.new
69
+
70
+ puts "Connecting.... Press 1 and 2 BUTTONS"
71
+
72
+ w.connect
73
+
74
+ while(!w.wiimotes[0].pressed? Wii::BUTTON_UP)
75
+ w.poll do |(wm, event)|
76
+ if event == :generic
77
+ if wm.pressed? Wii::BUTTON_A
78
+ set_rumble(wm)
79
+ elsif wm.pressed? Wii::BUTTON_B
80
+ status(wm)
81
+ elsif wm.pressed? Wii::BUTTON_DOWN
82
+ speaker(wm)
83
+ elsif wm.pressed? Wii::BUTTON_LEFT
84
+ puts "LEFT!"
85
+ elsif wm.pressed? Wii::BUTTON_RIGHT
86
+ puts "RIGHT!"
87
+ elsif wm.pressed? Wii::BUTTON_PLUS
88
+ accel_on(wm)
89
+ elsif wm.pressed? Wii::BUTTON_MINUS
90
+ vres(wm)
91
+ elsif wm.pressed? Wii::BUTTON_HOME
92
+ sens_pos(wm)
93
+ elsif wm.pressed? Wii::BUTTON_ONE
94
+ a_ratio(wm)
95
+ elsif wm.pressed? Wii::BUTTON_TWO
96
+ sens(wm)
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ ensure
103
+ w.cleanup!
104
+ end
@@ -0,0 +1,233 @@
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
+ * classicctrl.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_cc_pressed(VALUE self, VALUE arg) {
35
+ classic_ctrl_t *cc;
36
+ Data_Get_Struct(self, classic_ctrl_t, cc);
37
+ if(!cc) return Qnil;
38
+ Check_Type(arg, T_FIXNUM);
39
+ if(IS_PRESSED(cc, NUM2INT(arg)))
40
+ return Qtrue;
41
+ else
42
+ return Qfalse;
43
+ }
44
+
45
+ /*
46
+ * call-seq:
47
+ * classicctrl.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_cc_jpressed(VALUE self, VALUE arg) {
54
+ classic_ctrl_t *cc;
55
+ Data_Get_Struct(self, classic_ctrl_t, cc);
56
+ if(!cc) return Qnil;
57
+ Check_Type(arg, T_FIXNUM);
58
+ if(IS_JUST_PRESSED(cc, NUM2INT(arg)))
59
+ return Qtrue;
60
+ else
61
+ return Qfalse;
62
+ }
63
+
64
+ /*
65
+ * call-seq:
66
+ * classicctrl.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_cc_held(VALUE self, VALUE arg) {
73
+ classic_ctrl_t *cc;
74
+ Data_Get_Struct(self, classic_ctrl_t, cc);
75
+ if(!cc) return Qnil;
76
+ Check_Type(arg, T_FIXNUM);
77
+ if(IS_HELD(cc, NUM2INT(arg)))
78
+ return Qtrue;
79
+ else
80
+ return Qfalse;
81
+ }
82
+
83
+ /*
84
+ * call-seq:
85
+ * classicctrl.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_cc_rel(VALUE self, VALUE arg) {
92
+ classic_ctrl_t *cc;
93
+ Data_Get_Struct(self, classic_ctrl_t, cc);
94
+ if(!cc) return Qnil;
95
+ Check_Type(arg, T_FIXNUM);
96
+ if(IS_RELEASED(cc, NUM2INT(arg)))
97
+ return Qtrue;
98
+ else
99
+ return Qfalse;
100
+ }
101
+
102
+ /*
103
+ * call-seq:
104
+ * classicctrl.right_joystick_angle -> float
105
+ *
106
+ * Returns the angle at which the right joystick is being held.
107
+ * 0 => Straight up
108
+ * 90 => right
109
+ * 180 => down
110
+ * 270 => left
111
+ *
112
+ */
113
+
114
+ static VALUE rb_cc_rjangle(VALUE self) {
115
+ classic_ctrl_t *cc;
116
+ Data_Get_Struct(self, classic_ctrl_t, cc);
117
+ if(!cc) return Qnil;
118
+ return rb_float_new(cc->rjs.ang);
119
+ }
120
+
121
+ /*
122
+ * call-seq:
123
+ * classicctrl.right_joystick_magnitude -> float
124
+ *
125
+ * Returns the magnitude at which the right joystick is being held.
126
+ * Range: [0, 1]
127
+ * 0 => center
128
+ * 1 => edges
129
+ *
130
+ */
131
+
132
+ static VALUE rb_cc_rjmag(VALUE self) {
133
+ classic_ctrl_t *cc;
134
+ Data_Get_Struct(self, classic_ctrl_t, cc);
135
+ if(!cc) return Qnil;
136
+ return rb_float_new(cc->rjs.mag);
137
+ }
138
+
139
+ /*
140
+ * call-seq:
141
+ * classicctrl.left_joystick_angle -> float
142
+ *
143
+ * Returns the angle at which the left joystick is being held.
144
+ * 0 => Straight up
145
+ * 90 => right
146
+ * 180 => down
147
+ * 270 => left
148
+ *
149
+ */
150
+
151
+ static VALUE rb_cc_ljangle(VALUE self) {
152
+ classic_ctrl_t *cc;
153
+ Data_Get_Struct(self, classic_ctrl_t, cc);
154
+ if(!cc) return Qnil;
155
+ return rb_float_new(cc->ljs.ang);
156
+ }
157
+
158
+ /*
159
+ * call-seq:
160
+ * classicctrl.left_joystick_magnitude -> float
161
+ *
162
+ * Returns the magnitude at which the left joystick is being held.
163
+ * Range: [0, 1]
164
+ * 0 => center
165
+ * 1 => edges
166
+ *
167
+ */
168
+
169
+ static VALUE rb_cc_ljmag(VALUE self) {
170
+ classic_ctrl_t *cc;
171
+ Data_Get_Struct(self, classic_ctrl_t, cc);
172
+ if(!cc) return Qnil;
173
+ return rb_float_new(cc->ljs.mag);
174
+ }
175
+
176
+ /*
177
+ * call-seq:
178
+ * classicctrl.left_shoulder -> float
179
+ *
180
+ * Returns the magnitude at which the left shoulder button is being held.
181
+ * Range: [0, 1]
182
+ * 0 => not pressed
183
+ * 1 => fully pressed
184
+ *
185
+ */
186
+
187
+ static VALUE rb_cc_lshoulder(VALUE self) {
188
+ classic_ctrl_t *cc;
189
+ Data_Get_Struct(self, classic_ctrl_t, cc);
190
+ if(!cc) return Qnil;
191
+ return rb_float_new(cc->l_shoulder);
192
+ }
193
+
194
+ /*
195
+ * call-seq:
196
+ * classicctrl.right_shoulder -> float
197
+ *
198
+ * Returns the magnitude at which the right shoulder button is being held.
199
+ * Range: [0, 1]
200
+ * 0 => not pressed
201
+ * 1 => fully pressed
202
+ *
203
+ */
204
+
205
+ static VALUE rb_cc_rshoulder(VALUE self) {
206
+ classic_ctrl_t *cc;
207
+ Data_Get_Struct(self, classic_ctrl_t, cc);
208
+ if(!cc) return Qnil;
209
+ return rb_float_new(cc->r_shoulder);
210
+ }
211
+
212
+ /*
213
+ * Provides a set of methods for accessing ClassicController properties and members.
214
+ * - button events (pressed, released, held, just pressed)
215
+ * - joystick values (angles & magnitude)
216
+ *
217
+ *
218
+ */
219
+
220
+ void init_cc() {
221
+ cc_class = rb_define_class_under(wii_class, "ClassicController", rb_cObject);
222
+
223
+ rb_define_method(cc_class, "pressed?", rb_cc_pressed, 1);
224
+ rb_define_method(cc_class, "just_pressed?", rb_cc_jpressed, 1);
225
+ rb_define_method(cc_class, "held?", rb_cc_held, 1);
226
+ rb_define_method(cc_class, "released?", rb_cc_rel, 1);
227
+ rb_define_method(cc_class, "left_joystick_angle", rb_cc_ljangle, 0);
228
+ rb_define_method(cc_class, "left_joystick_magnitude", rb_cc_ljmag, 0);
229
+ rb_define_method(cc_class, "right_joystick_angle", rb_cc_rjangle, 0);
230
+ rb_define_method(cc_class, "right_joystick_magnitude", rb_cc_rjmag, 0);
231
+ rb_define_method(cc_class, "right_shoulder", rb_cc_rshoulder, 0);
232
+ rb_define_method(cc_class, "left_shoulder", rb_cc_lshoulder, 0);
233
+ }
@@ -0,0 +1,175 @@
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
+ * gh3ctrl.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_gh3_pressed(VALUE self, VALUE arg) {
35
+ guitar_hero_3_t *gh3;
36
+ Data_Get_Struct(self, guitar_hero_3_t, gh3);
37
+ if(!gh3) return Qnil;
38
+ Check_Type(arg, T_FIXNUM);
39
+ if(IS_PRESSED(gh3, NUM2INT(arg)))
40
+ return Qtrue;
41
+ else
42
+ return Qfalse;
43
+ }
44
+
45
+ /*
46
+ * call-seq:
47
+ * gh3ctrl.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_gh3_jpressed(VALUE self, VALUE arg) {
54
+ guitar_hero_3_t *gh3;
55
+ Data_Get_Struct(self, guitar_hero_3_t, gh3);
56
+ if(!gh3) return Qnil;
57
+ Check_Type(arg, T_FIXNUM);
58
+ if(IS_JUST_PRESSED(gh3, NUM2INT(arg)))
59
+ return Qtrue;
60
+ else
61
+ return Qfalse;
62
+ }
63
+
64
+ /*
65
+ * call-seq:
66
+ * gh3ctrl.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_gh3_held(VALUE self, VALUE arg) {
73
+ guitar_hero_3_t *gh3;
74
+ Data_Get_Struct(self, guitar_hero_3_t, gh3);
75
+ if(!gh3) return Qnil;
76
+ Check_Type(arg, T_FIXNUM);
77
+ if(IS_HELD(gh3, NUM2INT(arg)))
78
+ return Qtrue;
79
+ else
80
+ return Qfalse;
81
+ }
82
+
83
+ /*
84
+ * call-seq:
85
+ * gh3ctrl.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_gh3_rel(VALUE self, VALUE arg) {
92
+ guitar_hero_3_t *gh3;
93
+ Data_Get_Struct(self, guitar_hero_3_t, gh3);
94
+ if(!gh3) return Qnil;
95
+ Check_Type(arg, T_FIXNUM);
96
+ if(IS_RELEASED(gh3, NUM2INT(arg)))
97
+ return Qtrue;
98
+ else
99
+ return Qfalse;
100
+ }
101
+
102
+ /*
103
+ * call-seq:
104
+ * gh3ctrl.joystick_angle -> float
105
+ *
106
+ * Returns the angle at which the joystick is being held.
107
+ * 0 => Straight up
108
+ * 90 => right
109
+ * 180 => down
110
+ * 270 => left
111
+ *
112
+ */
113
+
114
+ static VALUE rb_gh3_jangle(VALUE self) {
115
+ guitar_hero_3_t *gh3;
116
+ Data_Get_Struct(self, guitar_hero_3_t, gh3);
117
+ if(!gh3) return Qnil;
118
+ return rb_float_new(gh3->js.ang);
119
+ }
120
+
121
+ /*
122
+ * call-seq:
123
+ * gh3ctrl.joystick_magnitude -> float
124
+ *
125
+ * Returns the magnitude at which the joystick is being held.
126
+ * Range: [0, 1]
127
+ * 0 => center
128
+ * 1 => edges
129
+ *
130
+ */
131
+
132
+ static VALUE rb_gh3_jmag(VALUE self) {
133
+ guitar_hero_3_t *gh3;
134
+ Data_Get_Struct(self, guitar_hero_3_t, gh3);
135
+ if(!gh3) return Qnil;
136
+ return rb_float_new(gh3->js.mag);
137
+ }
138
+
139
+ /*
140
+ * call-seq:
141
+ * gh3ctrl.whammy_bar -> float
142
+ *
143
+ * Returns the magnitude at which the whammy bar is being held.
144
+ * Range: [0, 1]
145
+ * 0 => not pressed
146
+ * 1 => fully pressed
147
+ *
148
+ */
149
+
150
+ static VALUE rb_gh3_wbar(VALUE self) {
151
+ guitar_hero_3_t *gh3;
152
+ Data_Get_Struct(self, guitar_hero_3_t, gh3);
153
+ if(!gh3) return Qnil;
154
+ return rb_float_new(gh3->whammy_bar);
155
+ }
156
+
157
+ /*
158
+ * Provides a set of methods for accessing Guitar Hero 3 Controller properties and members.
159
+ * - button events (pressed, just pressed, held, released)
160
+ * - whammy bar value
161
+ * - joystick values (angle, magnitude)
162
+ *
163
+ */
164
+
165
+ void init_gh3() {
166
+ gh3_class = rb_define_class_under(wii_class, "GH3Controller", rb_cObject);
167
+
168
+ rb_define_method(gh3_class, "pressed?", rb_gh3_pressed, 1);
169
+ rb_define_method(gh3_class, "just_pressed?", rb_gh3_jpressed, 1);
170
+ rb_define_method(gh3_class, "held?", rb_gh3_held, 1);
171
+ rb_define_method(gh3_class, "released?", rb_gh3_rel, 1);
172
+ rb_define_method(gh3_class, "whammy_bar", rb_gh3_wbar, 0);
173
+ rb_define_method(gh3_class, "joystick_angle", rb_gh3_jangle, 0);
174
+ rb_define_method(gh3_class, "joystick_magnitude", rb_gh3_jmag, 0);
175
+ }