hybridgroup-sphero 1.1.5 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sphero.rb +17 -3
- data/test/test_sphero.rb +6 -5
- metadata +2 -2
data/lib/sphero.rb
CHANGED
@@ -4,7 +4,7 @@ require 'sphero/response'
|
|
4
4
|
require 'thread'
|
5
5
|
|
6
6
|
class Sphero
|
7
|
-
VERSION = '1.1.
|
7
|
+
VERSION = '1.1.6'
|
8
8
|
|
9
9
|
FORWARD = 0
|
10
10
|
RIGHT = 90
|
@@ -14,8 +14,15 @@ class Sphero
|
|
14
14
|
class << self
|
15
15
|
def start(dev, &block)
|
16
16
|
sphero = self.new dev
|
17
|
-
|
18
|
-
|
17
|
+
if (block_given?)
|
18
|
+
begin
|
19
|
+
sphero.instance_eval(&block)
|
20
|
+
ensure
|
21
|
+
sphero.close
|
22
|
+
end
|
23
|
+
return nil
|
24
|
+
end
|
25
|
+
return sphero
|
19
26
|
rescue Errno::EBUSY
|
20
27
|
retry
|
21
28
|
end
|
@@ -28,6 +35,12 @@ class Sphero
|
|
28
35
|
@lock = Mutex.new
|
29
36
|
end
|
30
37
|
|
38
|
+
def close
|
39
|
+
@lock.synchronize do
|
40
|
+
@sp.close
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
31
44
|
def ping
|
32
45
|
write Request::Ping.new(@seq)
|
33
46
|
end
|
@@ -107,6 +120,7 @@ class Sphero
|
|
107
120
|
false
|
108
121
|
end
|
109
122
|
end
|
123
|
+
|
110
124
|
def initialize_serialport dev
|
111
125
|
@sp = SerialPort.new dev, 115200, 8, 1, SerialPort::NONE
|
112
126
|
if is_windows?
|
data/test/test_sphero.rb
CHANGED
@@ -13,12 +13,13 @@ class TestSphero < MiniTest::Unit::TestCase
|
|
13
13
|
assert_kind_of Sphero, Sphero.start('someport')
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
def test_start_sphero_executes_block
|
17
|
+
Sphero.any_instance.expects(:ping)
|
18
|
+
Sphero.any_instance.expects(:close)
|
18
19
|
Sphero.start('someport') do
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
ping
|
21
|
+
end
|
22
|
+
end
|
22
23
|
|
23
24
|
def test_ping
|
24
25
|
Sphero::Request::Ping.expects(:new).with(@seq)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hybridgroup-sphero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hybridgroup-serialport
|