hybridgroup-sphero 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +9 -1
- data/Manifest.txt +1 -0
- data/README.markdown +24 -0
- data/Rakefile +1 -0
- data/lib/sphero.rb +15 -47
- data/test/test_sphero.rb +76 -6
- data/test/test_sphero_request.rb +14 -0
- metadata +35 -13
data/CHANGELOG.rdoc
CHANGED
@@ -10,4 +10,12 @@
|
|
10
10
|
|
11
11
|
* Works with Ruby 1.9.2 for us regular folks
|
12
12
|
* Sphero.start method to endlessly retry when connecting
|
13
|
-
* I think heading might work again, not too sure
|
13
|
+
* I think heading might work again, not too sure
|
14
|
+
|
15
|
+
=== 1.1.0 / 2013-01-04
|
16
|
+
|
17
|
+
* 3 enhancements
|
18
|
+
|
19
|
+
* Pass a block to Sphero.start for DSL-awesomeness
|
20
|
+
* Use Sphero#keep_going as a nicer alias for Ruby's sleep command
|
21
|
+
* Add some additional test coverage
|
data/Manifest.txt
CHANGED
data/README.markdown
CHANGED
@@ -13,6 +13,29 @@ provided by the bluetooth connection.
|
|
13
13
|
|
14
14
|
## SYNOPSIS:
|
15
15
|
|
16
|
+
You can easily start your Sphero and send it commands like this:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
Sphero.start "/dev/tty.Sphero-PRG-RN-SPP" do
|
20
|
+
ping
|
21
|
+
|
22
|
+
# Roll 0 degrees, speed 125
|
23
|
+
roll(125, 0)
|
24
|
+
|
25
|
+
# Turn 360 degrees, 30 degrees at a time
|
26
|
+
0.step(360, 30) { |h|
|
27
|
+
h = 0 if h == 360
|
28
|
+
|
29
|
+
# Set the heading to h degrees
|
30
|
+
heading = h
|
31
|
+
keep_going 1
|
32
|
+
}
|
33
|
+
keep_going 1
|
34
|
+
stop
|
35
|
+
```
|
36
|
+
|
37
|
+
Here is a another way to do the same thing via just normal method calls:
|
38
|
+
|
16
39
|
```ruby
|
17
40
|
s = Sphero.new "/dev/tty.Sphero-PRG-RN-SPP"
|
18
41
|
s.ping
|
@@ -45,6 +68,7 @@ s.stop
|
|
45
68
|
(The MIT License)
|
46
69
|
|
47
70
|
Copyright (c) 2012 Aaron Patterson
|
71
|
+
Additional Copyright (c) 2012-2013 The Hybrid Group
|
48
72
|
|
49
73
|
Permission is hereby granted, free of charge, to any person obtaining
|
50
74
|
a copy of this software and associated documentation files (the
|
data/Rakefile
CHANGED
data/lib/sphero.rb
CHANGED
@@ -4,18 +4,20 @@ require 'sphero/response'
|
|
4
4
|
require 'thread'
|
5
5
|
|
6
6
|
class Sphero
|
7
|
-
VERSION = '1.0
|
7
|
+
VERSION = '1.1.0'
|
8
8
|
|
9
9
|
class << self
|
10
|
-
def start(dev)
|
11
|
-
self.new dev
|
10
|
+
def start(dev, &block)
|
11
|
+
sphero = self.new dev
|
12
|
+
sphero.instance_eval(&block) if block_given?
|
13
|
+
sphero
|
12
14
|
rescue Errno::EBUSY
|
13
15
|
retry
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
19
|
def initialize dev
|
18
|
-
|
20
|
+
initialize_serialport
|
19
21
|
@dev = 0x00
|
20
22
|
@seq = 0x00
|
21
23
|
@lock = Mutex.new
|
@@ -85,7 +87,16 @@ class Sphero
|
|
85
87
|
write Request::SetRotationRate.new(@seq, h)
|
86
88
|
end
|
87
89
|
|
90
|
+
# just a nicer alias for Ruby's own sleep
|
91
|
+
def keep_going(duration)
|
92
|
+
sleep duration
|
93
|
+
end
|
94
|
+
|
88
95
|
private
|
96
|
+
|
97
|
+
def initialize_serialport
|
98
|
+
@sp = SerialPort.new dev, 115200, 8, 1, SerialPort::NONE
|
99
|
+
end
|
89
100
|
|
90
101
|
def write packet
|
91
102
|
header = nil
|
@@ -109,46 +120,3 @@ class Sphero
|
|
109
120
|
end
|
110
121
|
end
|
111
122
|
|
112
|
-
if $0 == __FILE__
|
113
|
-
begin
|
114
|
-
s = Sphero.new "/dev/tty.Sphero-BRR-RN-SPP"
|
115
|
-
rescue Errno::EBUSY
|
116
|
-
retry
|
117
|
-
end
|
118
|
-
|
119
|
-
10.times {
|
120
|
-
p s.ping
|
121
|
-
}
|
122
|
-
|
123
|
-
trap(:INT) {
|
124
|
-
s.stop
|
125
|
-
exit!
|
126
|
-
}
|
127
|
-
|
128
|
-
#s.roll 100, 0
|
129
|
-
|
130
|
-
p s.user_led
|
131
|
-
exit
|
132
|
-
loop do
|
133
|
-
[0, 180].each do |dir|
|
134
|
-
s.heading = dir
|
135
|
-
sleep 10
|
136
|
-
end
|
137
|
-
|
138
|
-
#[
|
139
|
-
# [0, 0, 0xFF],
|
140
|
-
# [0xFF, 0, 0],
|
141
|
-
# [0, 0xFF, 0],
|
142
|
-
#].each do |color|
|
143
|
-
# s.rgb(*color)
|
144
|
-
# sleep 5
|
145
|
-
#end
|
146
|
-
end
|
147
|
-
|
148
|
-
#36.times {
|
149
|
-
# i = 10
|
150
|
-
# p :step => i
|
151
|
-
# s.heading = i
|
152
|
-
# sleep 0.5
|
153
|
-
#}
|
154
|
-
end
|
data/test/test_sphero.rb
CHANGED
@@ -1,14 +1,84 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
2
|
require 'sphero'
|
3
|
+
require 'mocha/setup'
|
3
4
|
|
4
5
|
class TestSphero < MiniTest::Unit::TestCase
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
def setup
|
7
|
+
Sphero.any_instance.stubs(:initialize_serialport)
|
8
|
+
@sphero = Sphero.new 'port123'
|
9
|
+
@seq = 0x00
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_start_returns_new_sphero
|
13
|
+
assert_kind_of Sphero, Sphero.start('someport')
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_ping
|
17
|
+
Sphero::Request::Ping.expects(:new).with(@seq)
|
18
|
+
@sphero.expects(:write)
|
19
|
+
@sphero.ping
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_version
|
23
|
+
Sphero::Request::GetVersioning.expects(:new).with(@seq)
|
24
|
+
@sphero.expects(:write)
|
25
|
+
@sphero.version
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_bluetooth_info
|
29
|
+
Sphero::Request::GetBluetoothInfo.expects(:new).with(@seq)
|
30
|
+
@sphero.expects(:write)
|
31
|
+
@sphero.bluetooth_info
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_auto_reconnect=
|
35
|
+
@time_s = "10"
|
36
|
+
Sphero::Request::SetAutoReconnect.expects(:new).with(@seq, @time_s)
|
37
|
+
@sphero.expects(:write)
|
38
|
+
@sphero.auto_reconnect = @time_s
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_auto_reconnect
|
42
|
+
@time_s = "10"
|
43
|
+
packet = mock 'packet'
|
44
|
+
packet.stubs(:time).returns(@time_s)
|
45
|
+
|
46
|
+
Sphero::Request::GetAutoReconnect.expects(:new).with(@seq)
|
47
|
+
@sphero.expects(:write).returns(packet)
|
48
|
+
assert_equal @sphero.auto_reconnect, @time_s
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_disable_auto_reconnect
|
52
|
+
Sphero::Request::SetAutoReconnect.expects(:new).with(@seq, 0, 0x00)
|
53
|
+
@sphero.expects(:write)
|
54
|
+
@sphero.disable_auto_reconnect
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_power_state
|
58
|
+
Sphero::Request::GetPowerState.expects(:new).with(@seq)
|
59
|
+
@sphero.expects(:write)
|
60
|
+
@sphero.power_state
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_sleep
|
64
|
+
wakeup = 1
|
65
|
+
macro = 2
|
66
|
+
Sphero::Request::Sleep.expects(:new).with(@seq, wakeup, macro)
|
67
|
+
@sphero.expects(:write)
|
68
|
+
@sphero.sleep wakeup, macro
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_roll
|
72
|
+
speed = 1
|
73
|
+
heading = 2
|
74
|
+
state = 1
|
75
|
+
Sphero::Request::Roll.expects(:new).with(@seq, speed, heading, state)
|
76
|
+
@sphero.expects(:write)
|
77
|
+
@sphero.roll speed, heading, true
|
8
78
|
end
|
9
79
|
|
10
|
-
def
|
11
|
-
|
12
|
-
|
80
|
+
def test_stop
|
81
|
+
@sphero.expects(:roll).with(0, 0)
|
82
|
+
@sphero.stop
|
13
83
|
end
|
14
84
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'sphero'
|
3
|
+
|
4
|
+
class TestSpheroRequest < MiniTest::Unit::TestCase
|
5
|
+
def test_ping_checksum
|
6
|
+
ping = Sphero::Request::Ping.new 0
|
7
|
+
assert_equal "\xFF\xFF\x00\x01\x00\x01\xFD", ping.to_str
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_sleep_dlen
|
11
|
+
sleep = Sphero::Request::Sleep.new 0, 0, 0
|
12
|
+
assert_equal 0x04, sleep.dlen
|
13
|
+
end
|
14
|
+
end
|
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.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: serialport
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,21 +21,31 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: minitest
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ~>
|
31
36
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
37
|
+
version: '3.3'
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.3'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: rdoc
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ~>
|
@@ -43,18 +53,28 @@ dependencies:
|
|
43
53
|
version: '3.10'
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.10'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: hoe
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ~>
|
53
68
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3.
|
69
|
+
version: '3.4'
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '3.4'
|
58
78
|
description: ! 'A ruby gem for controlling your Sphero ball. Sends commands over
|
59
79
|
the TTY
|
60
80
|
|
@@ -79,6 +99,7 @@ files:
|
|
79
99
|
- lib/sphero/request.rb
|
80
100
|
- lib/sphero/response.rb
|
81
101
|
- test/test_sphero.rb
|
102
|
+
- test/test_sphero_request.rb
|
82
103
|
- .gemtest
|
83
104
|
homepage: http://github.com/tenderlove/sphero
|
84
105
|
licenses: []
|
@@ -102,9 +123,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
123
|
version: '0'
|
103
124
|
requirements: []
|
104
125
|
rubyforge_project: hybridgroup-sphero
|
105
|
-
rubygems_version: 1.8.
|
126
|
+
rubygems_version: 1.8.24
|
106
127
|
signing_key:
|
107
128
|
specification_version: 3
|
108
129
|
summary: A ruby gem for controlling your Sphero ball
|
109
130
|
test_files:
|
110
131
|
- test/test_sphero.rb
|
132
|
+
- test/test_sphero_request.rb
|