simple_wiimote 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/simple_wiimote.rb +22 -39
- metadata +1 -1
data/lib/simple_wiimote.rb
CHANGED
@@ -4,9 +4,7 @@
|
|
4
4
|
|
5
5
|
require 'cwiid'
|
6
6
|
|
7
|
-
class WiiMote
|
8
|
-
attr_accessor :active
|
9
|
-
end
|
7
|
+
class WiiMote attr_accessor :active end
|
10
8
|
|
11
9
|
class SimpleWiimote
|
12
10
|
|
@@ -15,22 +13,24 @@ class SimpleWiimote
|
|
15
13
|
def initialize()
|
16
14
|
|
17
15
|
puts 'Put Wiimote in discoverable mode now (press 1+2)...'
|
16
|
+
|
18
17
|
@wiimote = WiiMote.new
|
19
18
|
@wiimote.rpt_mode = WiiMote::RPT_BTN | WiiMote::RPT_ACC
|
20
|
-
|
21
19
|
@wiimote.active = false
|
22
|
-
|
23
|
-
@events
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
20
|
+
|
21
|
+
@events = {
|
22
|
+
WiiMote::BTN_PLUS => -> {puts 'you pressed plus'},
|
23
|
+
WiiMote::BTN_UP => -> {puts 'you pressed up'},
|
24
|
+
WiiMote::BTN_DOWN => -> {puts 'you pressed down'},
|
25
|
+
WiiMote::BTN_RIGHT => -> {puts 'you pressed right'},
|
26
|
+
WiiMote::BTN_LEFT => -> {puts 'you pressed left'},
|
27
|
+
WiiMote::BTN_HOME => -> {puts 'you pressed home'},
|
28
|
+
WiiMote::BTN_MINUS => -> {puts 'you pressed minus'},
|
29
|
+
WiiMote::BTN_A => -> {puts 'you pressed a'},
|
30
|
+
WiiMote::BTN_B => -> {puts 'you pressed b'},
|
31
|
+
WiiMote::BTN_1 => -> {puts 'you pressed 1'},
|
32
|
+
WiiMote::BTN_2 => -> {puts 'you pressed 2'}
|
33
|
+
}
|
34
34
|
|
35
35
|
@terminator = WiiMote::BTN_A
|
36
36
|
end
|
@@ -42,32 +42,15 @@ class SimpleWiimote
|
|
42
42
|
@wiimote.active = true
|
43
43
|
yield(@wiimote) if block_given?
|
44
44
|
|
45
|
-
old_btn ||= @wiimote.buttons
|
46
45
|
if @wiimote.buttons > 0 then
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
old_btn = @wiimote.buttons
|
51
|
-
|
52
|
-
else
|
53
|
-
sleep 0.2
|
54
|
-
old_btn = 0
|
55
|
-
end
|
46
|
+
r = @events[@wiimote.buttons]
|
47
|
+
sleep 0.2
|
48
|
+
r.call if r
|
56
49
|
end
|
57
50
|
end until (@wiimote.buttons & @terminator ) != 0 || !@wiimote.active
|
58
51
|
end
|
59
52
|
|
60
|
-
def led=(val)
|
61
|
-
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
def rumble=(bool)
|
66
|
-
@rumble = bool
|
67
|
-
@wiimote.rumble = bool
|
68
|
-
end
|
69
|
-
|
70
|
-
def close()
|
71
|
-
@wiimote.close
|
72
|
-
end
|
53
|
+
def led=(val) @led = @wiimote.led = val end
|
54
|
+
def rumble=(bool) @rumble = @wiimote.rumble = bool end
|
55
|
+
def close() @wiimote.close end
|
73
56
|
end
|