lego-nxt 0.2.0 → 0.3.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.
- checksums.yaml +5 -5
- data/README.md +16 -12
- data/Rakefile +9 -12
- data/lib/lego_nxt.rb +36 -0
- data/lib/nxt/commands/base.rb +56 -7
- data/lib/nxt/commands/input.rb +30 -12
- data/lib/nxt/commands/low_speed.rb +47 -0
- data/lib/nxt/commands/output.rb +9 -7
- data/lib/nxt/commands/program.rb +3 -0
- data/lib/nxt/commands/sound.rb +3 -0
- data/lib/nxt/commands/tone.rb +3 -0
- data/lib/nxt/connector/input/base.rb +9 -0
- data/lib/nxt/{connectors → connector}/input/color.rb +3 -0
- data/lib/nxt/{connectors → connector}/input/touch.rb +3 -0
- data/lib/nxt/connector/input/ultrasonic.rb +66 -0
- data/lib/nxt/connector/output/base.rb +9 -0
- data/lib/nxt/connector/output/motor.rb +117 -0
- data/lib/nxt/exceptions.rb +3 -1
- data/lib/nxt/interface/base.rb +18 -0
- data/lib/nxt/{interfaces → interface}/serial_port.rb +13 -10
- data/lib/nxt/{interfaces → interface}/usb.rb +10 -9
- data/lib/nxt/nxt_brick.rb +51 -45
- data/lib/nxt/patches/module.rb +5 -2
- data/lib/nxt/patches/string.rb +6 -17
- data/lib/nxt/protocols/i2c.rb +118 -0
- data/lib/nxt/utils/accessors.rb +8 -7
- data/lib/nxt/utils/assertions.rb +24 -0
- data/spec/matchers.rb +2 -0
- data/spec/nxt/connector/output/motor_spec.rb +52 -0
- data/spec/nxt/interface/serial_port_spec.rb +119 -0
- data/spec/nxt/nxt_brick_spec.rb +189 -120
- data/spec/spec_helper.rb +10 -1
- metadata +193 -59
- data/lib/nxt.rb +0 -27
- data/lib/nxt/connectors/input/ultrasonic.rb +0 -11
- data/lib/nxt/connectors/output/motor.rb +0 -116
- data/lib/nxt/interfaces/base.rb +0 -26
- data/spec/nxt/interfaces/serial_port_spec.rb +0 -73
data/lib/nxt/interfaces/base.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module NXT
|
2
|
-
module Interface
|
3
|
-
class Base
|
4
|
-
def send_and_receive(msg, response_required = true)
|
5
|
-
unless response_required
|
6
|
-
msg[0] = msg[0] | 0x80
|
7
|
-
end
|
8
|
-
|
9
|
-
self.send(msg)
|
10
|
-
|
11
|
-
if response_required
|
12
|
-
response = self.receive
|
13
|
-
response
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def send
|
18
|
-
raise InterfaceNotImplemented.new('The #send method must be implemented.')
|
19
|
-
end
|
20
|
-
|
21
|
-
def receive
|
22
|
-
raise InterfaceNotImplemented.new('The #receive method must be implemented.')
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe NXT::Interface::SerialPort do
|
4
|
-
before do
|
5
|
-
@device = '/dev/zero'
|
6
|
-
@bad_device = 'hello world'
|
7
|
-
end
|
8
|
-
|
9
|
-
subject do
|
10
|
-
NXT::Interface::SerialPort.new(@device)
|
11
|
-
end
|
12
|
-
|
13
|
-
describe 'constants' do
|
14
|
-
it 'should have a BAUD_RATE constant' do
|
15
|
-
should have_constant(:BAUD_RATE)
|
16
|
-
should have_constant(:DATA_BITS)
|
17
|
-
should have_constant(:STOP_BITS)
|
18
|
-
should have_constant(:PARITY)
|
19
|
-
should have_constant(:READ_TIMEOUT)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe 'accessors' do
|
24
|
-
it 'should have read/write accessor for @dev' do
|
25
|
-
should respond_to(:dev)
|
26
|
-
should respond_to(:dev=)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe '#initialize' do
|
31
|
-
it 'should set the device to the incomming argument' do
|
32
|
-
subject.dev.should equal(@device)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should raise an exception when trying to connect to invalid dev files' do
|
36
|
-
expect do
|
37
|
-
serial_port = subject.class.new(@bad_device)
|
38
|
-
end.to raise_exception(InvalidDeviceError)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '#connect' do
|
43
|
-
it 'should raise an exception when the SerialPort connection failed' do
|
44
|
-
expect do
|
45
|
-
subject.connect
|
46
|
-
end.to raise_exception(SerialPortConnectionError, 'The #{@device} device is not a valid SerialPort')
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'should raise an exception when the SerialPort connection is nil' do
|
50
|
-
::SerialPort.should_receive(:new).and_return(nil)
|
51
|
-
expect do
|
52
|
-
subject.connect
|
53
|
-
end.to raise_exception(SerialPortConnectionError, "Could not establish a SerialPort connection to #{@device}")
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'should set the flow control and read timeout when the connection is established' do
|
57
|
-
serial_port_stub = stub()
|
58
|
-
serial_port_stub.should_receive(:flow_control=).with(::SerialPort::HARD).once
|
59
|
-
serial_port_stub.should_receive(:read_timeout=).with(subject.class::READ_TIMEOUT).once
|
60
|
-
::SerialPort.should_receive(:new).and_return(serial_port_stub)
|
61
|
-
|
62
|
-
subject.connect
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe '#send' do
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
describe '#receive' do
|
71
|
-
|
72
|
-
end
|
73
|
-
end
|