smalrubot 0.0.6 → 0.0.7
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.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/README.md +3 -0
- data/Rakefile +1 -1
- data/lib/smalrubot/version.rb +1 -1
- data/spec/lib/board_spec.rb +17 -17
- data/spec/lib/components/base_component_spec.rb +7 -7
- data/spec/lib/components/led_spec.rb +6 -6
- data/spec/lib/components/servo_spec.rb +8 -8
- data/spec/lib/tx_rx/serial_spec.rb +20 -20
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cdb763c4d819bb8d2297f51690ae9e41c7cdeb2a
|
|
4
|
+
data.tar.gz: 33645921dc4d5795b923f001542dfad6f733a0c2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dd4d9ed9afd631bdf07b4ef43f89dfa7efc2160465002e52972ce1b9c4639df40a4993337f46f145e72cda9f725753f4344e1d3473a128af36bae418c83bf8e0
|
|
7
|
+
data.tar.gz: 24d8d1339cb310987f715a981016025042b0c9b8913a65f50f7a0344f53d6a5fd771928c0391e125fdef278a62652b1f644f103dfb98405bb6727efe3ee782dd
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# smalrubot
|
|
2
2
|
|
|
3
|
+
[](https://badge.fury.io/rb/smalrubot)
|
|
4
|
+
[](https://travis-ci.org/smalruby/smalrubot)
|
|
5
|
+
|
|
3
6
|
The smalrubot is a library and an Arduino sketch for Smalruby.
|
|
4
7
|
|
|
5
8
|
This is a part of the Smalruby ([http://smalruby.jp](http://smalruby.jp)) Project.
|
data/Rakefile
CHANGED
|
@@ -21,7 +21,7 @@ task :release do
|
|
|
21
21
|
File.open('lib/smalrubot/version.rb', 'r+') do |f|
|
|
22
22
|
lines = []
|
|
23
23
|
while line = f.gets
|
|
24
|
-
line = "#{$1}
|
|
24
|
+
line = "#{$1}'#{next_version}'\n" if /(\s*VERSION =\s*)/.match(line)
|
|
25
25
|
lines << line
|
|
26
26
|
end
|
|
27
27
|
f.rewind
|
data/lib/smalrubot/version.rb
CHANGED
data/spec/lib/board_spec.rb
CHANGED
|
@@ -16,7 +16,7 @@ module Smalrubot
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
it 'should initiate the handshake' do
|
|
19
|
-
io_mock.
|
|
19
|
+
expect(io_mock).to receive(:handshake)
|
|
20
20
|
subject
|
|
21
21
|
end
|
|
22
22
|
end
|
|
@@ -25,77 +25,77 @@ module Smalrubot
|
|
|
25
25
|
it 'should return true if the write succeeds' do
|
|
26
26
|
@io = nil
|
|
27
27
|
board = Board.new(io_mock(write: true))
|
|
28
|
-
board.write('message').
|
|
28
|
+
expect(board.write('message')).to eq(true)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
it 'should wrap the message in a ! and a . by default' do
|
|
32
|
-
io_mock.
|
|
32
|
+
expect(io_mock).to receive(:write).with('!hello.')
|
|
33
33
|
subject.write('hello')
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it 'should not wrap the message if no_wrap is set to true' do
|
|
37
37
|
board = Board.new(io_mock)
|
|
38
|
-
io_mock.
|
|
38
|
+
expect(io_mock).to receive(:write).with('hello')
|
|
39
39
|
board.write('hello', no_wrap: true)
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
describe '#digital_write' do
|
|
44
44
|
it 'should append a append a write to the pin and value' do
|
|
45
|
-
io_mock.
|
|
45
|
+
expect(io_mock).to receive(:write).with('!0101003.')
|
|
46
46
|
subject.digital_write(01, 003)
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
describe '#digital_read' do
|
|
51
51
|
it 'should tell the board to read once from the given pin' do
|
|
52
|
-
io_mock.
|
|
53
|
-
io_mock.
|
|
52
|
+
expect(io_mock).to receive(:write).with('!0213000.')
|
|
53
|
+
expect(io_mock).to receive(:read).with(1).and_return(['13', Smalrubot::Board::HIGH.to_s])
|
|
54
54
|
expect(subject.digital_read(13)).to eq(Smalrubot::Board::HIGH)
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
describe '#analog_write' do
|
|
59
59
|
it 'should append a append a write to the pin and value' do
|
|
60
|
-
io_mock.
|
|
60
|
+
expect(io_mock).to receive(:write).with('!0301003.')
|
|
61
61
|
subject.analog_write(01, 003)
|
|
62
62
|
end
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
describe '#analog_read' do
|
|
66
66
|
it 'should tell the board to read once from the given pin' do
|
|
67
|
-
io_mock.
|
|
68
|
-
io_mock.
|
|
67
|
+
expect(io_mock).to receive(:write).with('!0413000.')
|
|
68
|
+
expect(io_mock).to receive(:read).with(1).once.and_return(['13', '256'])
|
|
69
69
|
expect(subject.analog_read(13)).to eq(256)
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
describe '#set_pin_mode' do
|
|
74
74
|
it 'should send a value of 0 if the pin mode is set to out' do
|
|
75
|
-
io_mock.
|
|
75
|
+
expect(io_mock).to receive(:write).with('!0013000.')
|
|
76
76
|
subject.set_pin_mode(13, :out)
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
it 'should send a value of 1 if the pin mode is set to in' do
|
|
80
|
-
io_mock.
|
|
80
|
+
expect(io_mock).to receive(:write).with('!0013001.')
|
|
81
81
|
subject.set_pin_mode(13, :in)
|
|
82
82
|
end
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
describe '#handshake' do
|
|
86
86
|
it 'should tell the board to reset to defaults' do
|
|
87
|
-
io_mock.
|
|
87
|
+
expect(io_mock).to receive(:handshake)
|
|
88
88
|
subject.handshake
|
|
89
89
|
end
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
describe '#normalize_pin' do
|
|
93
93
|
it 'should normalize numbers so they are two digits' do
|
|
94
|
-
subject.normalize_pin(1).
|
|
94
|
+
expect(subject.normalize_pin(1)).to eq('01')
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
it 'should not normalize numbers that are already two digits' do
|
|
98
|
-
subject.normalize_pin(10).
|
|
98
|
+
expect(subject.normalize_pin(10)).to eq('10')
|
|
99
99
|
end
|
|
100
100
|
|
|
101
101
|
it 'should raise if a number larger than two digits are given' do
|
|
@@ -105,11 +105,11 @@ module Smalrubot
|
|
|
105
105
|
|
|
106
106
|
describe '#normalize_value' do
|
|
107
107
|
it 'should normalize numbers so they are three digits' do
|
|
108
|
-
subject.normalize_value(1).
|
|
108
|
+
expect(subject.normalize_value(1)).to eq('001')
|
|
109
109
|
end
|
|
110
110
|
|
|
111
111
|
it 'should not normalize numbers that are already three digits' do
|
|
112
|
-
subject.normalize_value(10).
|
|
112
|
+
expect(subject.normalize_value(10)).to eq('010')
|
|
113
113
|
end
|
|
114
114
|
|
|
115
115
|
it 'should raise if a number larger than three digits are given' do
|
|
@@ -10,8 +10,8 @@ module Smalrubot
|
|
|
10
10
|
board = "a board"
|
|
11
11
|
component = BaseComponent.new(pin: pin, board: board)
|
|
12
12
|
|
|
13
|
-
component.pin.
|
|
14
|
-
component.board.
|
|
13
|
+
expect(component.pin).to eq(pin)
|
|
14
|
+
expect(component.board).to eq(board)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
it 'should assign pins' do
|
|
@@ -19,19 +19,19 @@ module Smalrubot
|
|
|
19
19
|
board = "a board"
|
|
20
20
|
component = BaseComponent.new(pins: pins, board: board)
|
|
21
21
|
|
|
22
|
-
component.pins.
|
|
22
|
+
expect(component.pins).to eq(pins)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
it 'should require a pin or pins' do
|
|
26
26
|
expect {
|
|
27
27
|
BaseComponent.new(board: 'some board')
|
|
28
|
-
}.to raise_exception
|
|
28
|
+
}.to raise_exception(RuntimeError)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
it 'should require a board' do
|
|
32
32
|
expect {
|
|
33
33
|
BaseComponent.new(pin: 'some pin')
|
|
34
|
-
}.to raise_exception
|
|
34
|
+
}.to raise_exception(RuntimeError)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
context "when subclassed #after_initialize should be executed" do
|
|
@@ -54,8 +54,8 @@ module Smalrubot
|
|
|
54
54
|
|
|
55
55
|
it "should call #after_initialize with options" do
|
|
56
56
|
component = SpecComponent.new(options)
|
|
57
|
-
component.
|
|
58
|
-
component.options.
|
|
57
|
+
expect(component).to be_sucessfully_initialized
|
|
58
|
+
expect(component.options).to eq(options)
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
end
|
|
@@ -9,22 +9,22 @@ module Smalrubot
|
|
|
9
9
|
it 'should raise if it does not receive a pin' do
|
|
10
10
|
expect {
|
|
11
11
|
Led.new(board: board)
|
|
12
|
-
}.to raise_exception
|
|
12
|
+
}.to raise_exception(RuntimeError)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
it 'should raise if it does not receive a board' do
|
|
16
16
|
expect {
|
|
17
17
|
Led.new(pins: {})
|
|
18
|
-
}.to raise_exception
|
|
18
|
+
}.to raise_exception(RuntimeError)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
it 'should set the pin to out' do
|
|
22
|
-
board.
|
|
22
|
+
expect(board).to receive(:set_pin_mode).with(13, :out, nil)
|
|
23
23
|
Led.new(pin: 13, board: board)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
it 'should set the pin to low' do
|
|
27
|
-
board.
|
|
27
|
+
expect(board).to receive(:digital_write).with(13, Board::LOW)
|
|
28
28
|
Led.new(pin: 13, board: board)
|
|
29
29
|
end
|
|
30
30
|
end
|
|
@@ -32,7 +32,7 @@ module Smalrubot
|
|
|
32
32
|
describe '#on' do
|
|
33
33
|
it 'should send a high to the board with the pin' do
|
|
34
34
|
@led = Led.new(pin: 13, board: board)
|
|
35
|
-
board.
|
|
35
|
+
expect(board).to receive(:digital_write).with(13, Board::HIGH)
|
|
36
36
|
@led.on
|
|
37
37
|
end
|
|
38
38
|
end
|
|
@@ -40,7 +40,7 @@ module Smalrubot
|
|
|
40
40
|
describe '#off' do
|
|
41
41
|
it 'should send a high to the board with the pin' do
|
|
42
42
|
@led = Led.new(pin: 13, board: board)
|
|
43
|
-
board.
|
|
43
|
+
expect(board).to receive(:digital_write).with(13, Board::LOW)
|
|
44
44
|
@led.off
|
|
45
45
|
end
|
|
46
46
|
end
|
|
@@ -9,23 +9,23 @@ module Smalrubot
|
|
|
9
9
|
it 'should raise if it does not receive a pin' do
|
|
10
10
|
expect {
|
|
11
11
|
Servo.new(board: board)
|
|
12
|
-
}.to raise_exception
|
|
12
|
+
}.to raise_exception(RuntimeError)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
it 'should raise if it does not receive a board' do
|
|
16
16
|
expect {
|
|
17
17
|
Servo.new(pin: 13)
|
|
18
|
-
}.to raise_exception
|
|
18
|
+
}.to raise_exception(RuntimeError)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
it 'should set the pins to out' do
|
|
22
|
-
board.
|
|
22
|
+
expect(board).to receive(:set_pin_mode).with(13, :out, nil)
|
|
23
23
|
Servo.new(pin: 13, board: board)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
it 'should set the inital position to 0' do
|
|
27
27
|
servo = Servo.new(pin: 13, board: board)
|
|
28
|
-
servo.instance_variable_get(:@position).
|
|
28
|
+
expect(servo.instance_variable_get(:@position)).to eq(0)
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
|
|
@@ -34,21 +34,21 @@ module Smalrubot
|
|
|
34
34
|
|
|
35
35
|
it 'should set the position of the Servo' do
|
|
36
36
|
servo.position = 90
|
|
37
|
-
servo.instance_variable_get(:@position).
|
|
37
|
+
expect(servo.instance_variable_get(:@position)).to eq(90)
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
it 'should let you write up to 180' do
|
|
41
41
|
servo.position = 180
|
|
42
|
-
servo.instance_variable_get(:@position).
|
|
42
|
+
expect(servo.instance_variable_get(:@position)).to eq(180)
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
it 'should modulate when position > 180' do
|
|
46
46
|
servo.position = 190
|
|
47
|
-
servo.instance_variable_get(:@position).
|
|
47
|
+
expect(servo.instance_variable_get(:@position)).to eq(10)
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
it 'should write the new position to the board' do
|
|
51
|
-
board.
|
|
51
|
+
expect(board).to receive(:servo_write).with(13, 10)
|
|
52
52
|
servo.position = 190
|
|
53
53
|
end
|
|
54
54
|
end
|
|
@@ -6,13 +6,13 @@ module Smalrubot
|
|
|
6
6
|
|
|
7
7
|
describe '#initialize' do
|
|
8
8
|
it 'should set first_write to true' do
|
|
9
|
-
TxRx::Serial.new.instance_variable_get(:@first_write).
|
|
9
|
+
expect(TxRx::Serial.new.instance_variable_get(:@first_write)).to eq(true)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
it 'should set the device and buad if specified' do
|
|
13
13
|
txrx = TxRx::Serial.new({device: "/dev/ttyACM0", baud: 9600})
|
|
14
|
-
txrx.instance_variable_get(:@baud).
|
|
15
|
-
txrx.instance_variable_get(:@device).
|
|
14
|
+
expect(txrx.instance_variable_get(:@baud)).to eq(9600)
|
|
15
|
+
expect(txrx.instance_variable_get(:@device)).to eq("/dev/ttyACM0")
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
|
|
@@ -24,56 +24,56 @@ module Smalrubot
|
|
|
24
24
|
subject.instance_variable_set('@tty_devices', ["COM1", "COM2", "COM3"])
|
|
25
25
|
|
|
26
26
|
# COM2 is chosen as available for this test.
|
|
27
|
-
::Serial.
|
|
28
|
-
::Serial.
|
|
29
|
-
::Serial.
|
|
27
|
+
expect(::Serial).to receive(:new).with("COM1", TxRx::Serial::BAUD).and_raise
|
|
28
|
+
expect(::Serial).to receive(:new).with("COM2", TxRx::Serial::BAUD).and_return(mock_serial = double)
|
|
29
|
+
expect(::Serial).not_to receive(:new).with("COM3", TxRx::Serial::BAUD)
|
|
30
30
|
|
|
31
|
-
subject.io.
|
|
31
|
+
expect(subject.io).to eq(mock_serial)
|
|
32
32
|
Constants.redefine(:RUBY_PLATFORM, original_platform, :on => Object)
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
context "on unix" do
|
|
37
37
|
it 'should instantiate a new ::Serial for the first available tty device' do
|
|
38
|
-
subject.
|
|
38
|
+
expect(subject).to receive(:tty_devices).and_return(['/dev/ttyACM0', '/dev/tty.usbmodem1'])
|
|
39
39
|
|
|
40
40
|
# /dev/ttyACM0 is chosen as available for this test.
|
|
41
|
-
::Serial.
|
|
42
|
-
::Serial.
|
|
41
|
+
expect(::Serial).to receive(:new).with('/dev/ttyACM0', TxRx::Serial::BAUD).and_return(mock_serial = double)
|
|
42
|
+
expect(::Serial).not_to receive(:new).with('/dev/tty.usbmodem1', TxRx::Serial::BAUD)
|
|
43
43
|
|
|
44
|
-
subject.io.
|
|
44
|
+
expect(subject.io).to eq(mock_serial)
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
it 'should connect to the specified device at the specified baud rate' do
|
|
49
|
-
subject.
|
|
50
|
-
::Serial.
|
|
49
|
+
expect(subject).to receive(:tty_devices).and_return(["/dev/ttyACM0"])
|
|
50
|
+
expect(::Serial).to receive(:new).with('/dev/ttyACM0', 9600).and_return(mock_serial = double)
|
|
51
51
|
|
|
52
52
|
subject.instance_variable_set(:@device, "/dev/ttyACM0")
|
|
53
53
|
subject.instance_variable_set(:@baud, 9600)
|
|
54
54
|
|
|
55
|
-
subject.io.
|
|
55
|
+
expect(subject.io).to eq(mock_serial)
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
it 'should use the existing io instance if set' do
|
|
59
|
-
subject.
|
|
60
|
-
::Serial.
|
|
59
|
+
expect(subject).to receive(:tty_devices).once.and_return(['/dev/tty.ACM0', '/dev/tty.usbmodem1'])
|
|
60
|
+
allow(::Serial).to receive(:new).and_return(mock_serial = double)
|
|
61
61
|
|
|
62
62
|
3.times { subject.io }
|
|
63
|
-
subject.io.
|
|
63
|
+
expect(subject.io).to eq(mock_serial)
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
it 'should raise a BoardNotFound exception if there is no board connected' do
|
|
67
|
-
::Serial.
|
|
67
|
+
allow(::Serial).to receive(:new).and_raise
|
|
68
68
|
expect { subject.io }.to raise_exception BoardNotFound
|
|
69
69
|
end
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
describe '#write' do
|
|
73
73
|
it 'should write to the device' do
|
|
74
|
-
subject.
|
|
74
|
+
allow(subject).to receive(:io).and_return(mock_serial = double)
|
|
75
75
|
msg = 'a message'
|
|
76
|
-
mock_serial.
|
|
76
|
+
expect(mock_serial).to receive(:write).with(msg).and_return(msg.length)
|
|
77
77
|
subject.write('a message')
|
|
78
78
|
end
|
|
79
79
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: smalrubot
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kouji Takao
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2017-01-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rubyserial
|
|
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
131
131
|
version: '0'
|
|
132
132
|
requirements: []
|
|
133
133
|
rubyforge_project:
|
|
134
|
-
rubygems_version: 2.
|
|
134
|
+
rubygems_version: 2.5.2
|
|
135
135
|
signing_key:
|
|
136
136
|
specification_version: 4
|
|
137
137
|
summary: A library and an Arduino sketch for Smalruby.
|