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.
Files changed (2) hide show
  1. data/lib/simple_wiimote.rb +22 -39
  2. metadata +1 -1
@@ -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
- @events = {}
23
- @events[WiiMote::BTN_PLUS] = -> {puts 'you pressed plus'}
24
- @events[WiiMote::BTN_UP] = -> {puts 'you pressed up'}
25
- @events[WiiMote::BTN_DOWN] = -> {puts 'you pressed down'}
26
- @events[WiiMote::BTN_RIGHT] =-> {puts 'you pressed right'}
27
- @events[WiiMote::BTN_LEFT] = -> {puts 'you pressed left'}
28
- @events[WiiMote::BTN_HOME] = -> {puts 'you pressed home'}
29
- @events[WiiMote::BTN_MINUS] = -> {puts 'you pressed minus'}
30
- @events[WiiMote::BTN_A] = -> {puts 'you pressed a'}
31
- @events[WiiMote::BTN_B] = -> {puts 'you pressed b'}
32
- @events[WiiMote::BTN_1] = -> {puts 'you pressed 1'}
33
- @events[WiiMote::BTN_2] = -> {puts 'you pressed 2'}
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
- if @wiimote.buttons != old_btn then
48
- r = @events[@wiimote.buttons]
49
- (old_btn = 0; r.call; sleep 0.2) if r
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
- @led = val
62
- @wiimote.led = val
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
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: simple_wiimote
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.2
5
+ version: 0.1.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - James Robertson