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.
Files changed (38) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +16 -12
  3. data/Rakefile +9 -12
  4. data/lib/lego_nxt.rb +36 -0
  5. data/lib/nxt/commands/base.rb +56 -7
  6. data/lib/nxt/commands/input.rb +30 -12
  7. data/lib/nxt/commands/low_speed.rb +47 -0
  8. data/lib/nxt/commands/output.rb +9 -7
  9. data/lib/nxt/commands/program.rb +3 -0
  10. data/lib/nxt/commands/sound.rb +3 -0
  11. data/lib/nxt/commands/tone.rb +3 -0
  12. data/lib/nxt/connector/input/base.rb +9 -0
  13. data/lib/nxt/{connectors → connector}/input/color.rb +3 -0
  14. data/lib/nxt/{connectors → connector}/input/touch.rb +3 -0
  15. data/lib/nxt/connector/input/ultrasonic.rb +66 -0
  16. data/lib/nxt/connector/output/base.rb +9 -0
  17. data/lib/nxt/connector/output/motor.rb +117 -0
  18. data/lib/nxt/exceptions.rb +3 -1
  19. data/lib/nxt/interface/base.rb +18 -0
  20. data/lib/nxt/{interfaces → interface}/serial_port.rb +13 -10
  21. data/lib/nxt/{interfaces → interface}/usb.rb +10 -9
  22. data/lib/nxt/nxt_brick.rb +51 -45
  23. data/lib/nxt/patches/module.rb +5 -2
  24. data/lib/nxt/patches/string.rb +6 -17
  25. data/lib/nxt/protocols/i2c.rb +118 -0
  26. data/lib/nxt/utils/accessors.rb +8 -7
  27. data/lib/nxt/utils/assertions.rb +24 -0
  28. data/spec/matchers.rb +2 -0
  29. data/spec/nxt/connector/output/motor_spec.rb +52 -0
  30. data/spec/nxt/interface/serial_port_spec.rb +119 -0
  31. data/spec/nxt/nxt_brick_spec.rb +189 -120
  32. data/spec/spec_helper.rb +10 -1
  33. metadata +193 -59
  34. data/lib/nxt.rb +0 -27
  35. data/lib/nxt/connectors/input/ultrasonic.rb +0 -11
  36. data/lib/nxt/connectors/output/motor.rb +0 -116
  37. data/lib/nxt/interfaces/base.rb +0 -26
  38. data/spec/nxt/interfaces/serial_port_spec.rb +0 -73
@@ -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