simple_wiimote 0.1.4 → 0.2.0
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.
- data/lib/simple_wiimote.rb +75 -18
- metadata +2 -2
data/lib/simple_wiimote.rb
CHANGED
@@ -19,37 +19,94 @@ class SimpleWiimote
|
|
19
19
|
@wiimote = WiiMote.new
|
20
20
|
@wiimote.rpt_mode = WiiMote::RPT_BTN | WiiMote::RPT_ACC
|
21
21
|
@wiimote.active = false
|
22
|
-
|
22
|
+
|
23
23
|
@events = {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
24
|
+
'2' => -> {puts 'you pressed 2'},
|
25
|
+
'1' => -> {puts 'you pressed 1'},
|
26
|
+
'b' => -> {puts 'you pressed b'},
|
27
|
+
'a' => -> {puts 'you pressed a'},
|
28
|
+
'minus' => -> {puts 'you pressed minus'},
|
29
|
+
'void1' => nil,
|
30
|
+
'void2' => nil,
|
31
|
+
'home' => -> {puts 'you pressed home'},
|
32
|
+
'left' => -> {puts 'you pressed left'},
|
33
|
+
'right' => -> {puts 'you pressed right'},
|
34
|
+
'down' => -> {puts 'you pressed down'},
|
35
|
+
'up' => -> {puts 'you pressed up'},
|
36
|
+
'plus' => {
|
37
|
+
on_buttondown: -> {puts 'you pressed plus'},
|
38
|
+
on_buttonup: -> {puts 'plus button raised'}
|
39
|
+
}
|
35
40
|
}
|
36
41
|
|
37
|
-
@terminator =
|
42
|
+
@terminator = ['1','2']
|
38
43
|
end
|
39
44
|
|
40
45
|
def activate()
|
41
46
|
|
47
|
+
previously_pressed, pressed = [], []
|
48
|
+
|
42
49
|
begin
|
50
|
+
|
43
51
|
@wiimote.get_state
|
44
52
|
@wiimote.active = true
|
45
53
|
yield(@wiimote) if block_given?
|
46
54
|
|
47
|
-
if @wiimote.buttons > 0
|
48
|
-
|
49
|
-
|
50
|
-
|
55
|
+
if @wiimote.buttons > 0 then
|
56
|
+
|
57
|
+
val = @wiimote.buttons
|
58
|
+
|
59
|
+
@events.keys.reverse.each_with_index do |x,i|
|
60
|
+
|
61
|
+
n = @events.length - 1 - i
|
62
|
+
next if x == 32 or x == 64
|
63
|
+
|
64
|
+
xval = 2**n
|
65
|
+
(val -= xval; pressed << x) if xval <= val
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
@wiimote.active = (not (@terminator & pressed) == @terminator)
|
70
|
+
|
71
|
+
new_keypresses = pressed - previously_pressed
|
72
|
+
expired_keypresses = previously_pressed - pressed
|
73
|
+
|
74
|
+
previously_pressed = pressed
|
75
|
+
pressed = []
|
76
|
+
|
77
|
+
procs1 = {
|
78
|
+
Hash: lambda {|x| x[:on_buttondown].call},
|
79
|
+
Proc: lambda {|x| x.call}
|
80
|
+
}
|
81
|
+
|
82
|
+
procs2 = {
|
83
|
+
Hash: lambda {|x| x[:on_buttonup].call},
|
84
|
+
Proc: lambda {|x| }
|
85
|
+
}
|
86
|
+
|
87
|
+
new_keypresses.each do |x|
|
88
|
+
procs1[@events[x].class.to_s.to_sym].call(@events[x])
|
89
|
+
end
|
90
|
+
|
91
|
+
expired_keypresses.each do |x|
|
92
|
+
procs2[@events[x].class.to_s.to_sym].call(@events[x])
|
93
|
+
end
|
94
|
+
|
95
|
+
else
|
96
|
+
|
97
|
+
if previously_pressed.length > 0 then
|
98
|
+
|
99
|
+
expired_keypresses = previously_pressed
|
100
|
+
|
101
|
+
expired_keypresses.each do |x|
|
102
|
+
procs2[@events[x].class.to_s.to_sym].call(@events[x])
|
103
|
+
end
|
104
|
+
|
105
|
+
previously_pressed, expired_keypressed, pressed = [], [], []
|
106
|
+
end
|
51
107
|
end
|
52
|
-
|
108
|
+
|
109
|
+
end until ( not @wiimote.active )
|
53
110
|
end
|
54
111
|
|
55
112
|
def led=(val) @led = @wiimote.led = val end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: simple_wiimote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James Robertson
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-12-
|
13
|
+
date: 2012-12-19 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: cwiid
|