dino 0.8 → 0.9
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.
- data/.travis.yml +5 -0
- data/README.md +5 -0
- data/Rakefile +8 -0
- data/examples/button/button.rb +2 -2
- data/examples/ir_receiver.rb +1 -1
- data/examples/led/led.png +0 -0
- data/examples/led/led.rb +1 -1
- data/examples/potentiometer.rb +1 -1
- data/examples/rgb_led.rb +1 -1
- data/examples/sensor.rb +1 -1
- data/examples/servo.rb +2 -2
- data/examples/stepper/stepper.png +0 -0
- data/examples/{stepper.rb → stepper/stepper.rb} +1 -1
- data/lib/dino.rb +2 -12
- data/lib/dino/board_not_found.rb +3 -0
- data/lib/dino/components.rb +12 -0
- data/lib/dino/components/base_component.rb +10 -0
- data/lib/dino/components/button.rb +1 -3
- data/lib/dino/components/ir_receiver.rb +1 -3
- data/lib/dino/components/led.rb +2 -4
- data/lib/dino/components/rgb_led.rb +1 -3
- data/lib/dino/components/sensor.rb +1 -3
- data/lib/dino/components/servo.rb +1 -3
- data/lib/dino/components/stepper.rb +1 -3
- data/lib/dino/tx_rx.rb +19 -10
- data/lib/dino/version.rb +1 -1
- data/spec/lib/board_not_found_spec.rb +8 -0
- data/spec/lib/components/base_component_spec.rb +29 -0
- data/spec/lib/tx_rx_spec.rb +28 -5
- metadata +10 -3
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# Welcome to Dino
|
2
|
+
[](http://travis-ci.org/austinbv/dino)
|
2
3
|
|
3
4
|
## Get started in no time
|
4
5
|
Dino was designed to help you start working with your Arduino in minutes.
|
5
6
|
|
7
|
+
> * `gem install dino`
|
6
8
|
> * Burn the file `src/du.ino` to your Arduino
|
7
9
|
> ** You can do this in the [Arduino IDE](http://www.arduino.cc/en/Main/software)
|
8
10
|
> * Plug in your Arduino and wire the led like in `examples/led/led.png`
|
@@ -12,3 +14,6 @@ By now you should be blinking away
|
|
12
14
|
|
13
15
|
|
14
16
|
Take a look in the example directory for more information
|
17
|
+
|
18
|
+
|
19
|
+
I gave a [talk on this library at RubyConf](http://confreaks.com/videos/1294-rubyconf2012-arduino-the-ruby-way), you can see the slides here: [Arudino The Ruby Way](https://speakerdeck.com/austinbv/arduino-the-ruby-way)
|
data/Rakefile
CHANGED
data/examples/button/button.rb
CHANGED
@@ -4,10 +4,10 @@
|
|
4
4
|
# sleep or in someway keep running or your program
|
5
5
|
# will exit before any callbacks can be called
|
6
6
|
#
|
7
|
-
require '
|
7
|
+
require File.expand_path('../../../lib/dino', __FILE__)
|
8
8
|
|
9
9
|
board = Dino::Board.new(Dino::TxRx.new)
|
10
|
-
button = Dino::Components::Button.new(pin:
|
10
|
+
button = Dino::Components::Button.new(pin: 13, board: board)
|
11
11
|
|
12
12
|
button_down = Proc.new do
|
13
13
|
puts "button down"
|
data/examples/ir_receiver.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# sleep or in someway keep running or your program
|
5
5
|
# will exit before any callbacks can be called
|
6
6
|
#
|
7
|
-
require '
|
7
|
+
require File.expand_path('../../lib/dino', __FILE__)
|
8
8
|
|
9
9
|
board = Dino::Board.new(Dino::TxRx.new)
|
10
10
|
ir = Dino::Components::IrReceiver.new(pin: 2, board: board)
|
Binary file
|
data/examples/led/led.rb
CHANGED
data/examples/potentiometer.rb
CHANGED
data/examples/rgb_led.rb
CHANGED
data/examples/sensor.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# sleep or in someway keep running or your program
|
5
5
|
# will exit before any callbacks can be called
|
6
6
|
#
|
7
|
-
require '
|
7
|
+
require File.expand_path('../../lib/dino', __FILE__)
|
8
8
|
|
9
9
|
board = Dino::Board.new(Dino::TxRx.new)
|
10
10
|
sensor = Dino::Components::Sensor.new(pin: 'A0', board: board)
|
data/examples/servo.rb
CHANGED
@@ -4,8 +4,8 @@
|
|
4
4
|
# sleep or in someway keep running or your program
|
5
5
|
# will exit before any callbacks can be called
|
6
6
|
#
|
7
|
-
|
8
|
-
require '
|
7
|
+
|
8
|
+
require File.expand_path('../../lib/dino', __FILE__)
|
9
9
|
|
10
10
|
board = Dino::Board.new(Dino::TxRx.new)
|
11
11
|
servo = Dino::Components::Servo.new(pin: 9, board: board)
|
Binary file
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# This is a simple example to move a stepper motor using the sparkfun easydriver shield: https://www.sparkfun.com/products/10267?
|
3
3
|
#
|
4
4
|
|
5
|
-
require '
|
5
|
+
require File.expand_path('../../../lib/dino', __FILE__)
|
6
6
|
|
7
7
|
board = Dino::Board.new(Dino::TxRx.new)
|
8
8
|
stepper = Dino::Components::Stepper.new(board: board, pins: { step: 10, direction: 8 })
|
data/lib/dino.rb
CHANGED
@@ -1,15 +1,5 @@
|
|
1
|
+
require 'dino/board_not_found'
|
1
2
|
require 'dino/version'
|
2
3
|
require 'dino/tx_rx'
|
3
4
|
require 'dino/board'
|
4
|
-
|
5
|
-
require 'dino/components/base_component'
|
6
|
-
require 'dino/components/led'
|
7
|
-
require 'dino/components/button'
|
8
|
-
require 'dino/components/sensor'
|
9
|
-
require 'dino/components/rgb_led'
|
10
|
-
require 'dino/components/servo'
|
11
|
-
require 'dino/components/stepper'
|
12
|
-
require 'dino/components/ir_receiver'
|
13
|
-
|
14
|
-
module Dino
|
15
|
-
end
|
5
|
+
require 'dino/components'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Dino
|
2
|
+
module Components
|
3
|
+
require 'dino/components/base_component'
|
4
|
+
autoload :Led, 'dino/components/led'
|
5
|
+
autoload :Button, 'dino/components/button'
|
6
|
+
autoload :Sensor, 'dino/components/sensor'
|
7
|
+
autoload :RgbLed, 'dino/components/rgb_led'
|
8
|
+
autoload :Servo, 'dino/components/servo'
|
9
|
+
autoload :Stepper, 'dino/components/stepper'
|
10
|
+
autoload :IrReceiver, 'dino/components/ir_receiver'
|
11
|
+
end
|
12
|
+
end
|
@@ -9,8 +9,18 @@ module Dino
|
|
9
9
|
self.board = options[:board]
|
10
10
|
|
11
11
|
raise 'board and pin or pins are required for a component' if self.board.nil? || self.pin.nil?
|
12
|
+
after_initialize(options)
|
12
13
|
end
|
13
14
|
|
15
|
+
#
|
16
|
+
# As BaseComponent does a lot of work for you with regarding to setting up, it is
|
17
|
+
# best not to override #initialize and instead define an #after_initialize method
|
18
|
+
# within your subclass.
|
19
|
+
#
|
20
|
+
# @note This method should be implemented in the BaseComponent subclass.
|
21
|
+
#
|
22
|
+
def after_initialize(options={}) ; end
|
23
|
+
|
14
24
|
protected
|
15
25
|
|
16
26
|
attr_writer :pin, :board
|
data/lib/dino/components/led.rb
CHANGED
@@ -2,9 +2,7 @@ module Dino
|
|
2
2
|
module Components
|
3
3
|
class RgbLed < BaseComponent
|
4
4
|
# options = {board: my_board, pins: {red: red_pin, green: green_pin, blue: blue_pin}
|
5
|
-
def
|
6
|
-
super(options)
|
7
|
-
|
5
|
+
def after_initialize(options={})
|
8
6
|
raise 'missing pins[:red] pin' unless self.pins[:red]
|
9
7
|
raise 'missing pins[:green] pin' unless self.pins[:green]
|
10
8
|
raise 'missing pins[:blue] pin' unless self.pins[:blue]
|
@@ -2,9 +2,7 @@ module Dino
|
|
2
2
|
module Components
|
3
3
|
class Stepper < BaseComponent
|
4
4
|
|
5
|
-
def
|
6
|
-
super(options)
|
7
|
-
|
5
|
+
def after_initialize(options={})
|
8
6
|
raise 'missing pins[:step] pin' unless self.pins[:step]
|
9
7
|
raise 'missing pins[:direction] pin' unless self.pins[:direction]
|
10
8
|
|
data/lib/dino/tx_rx.rb
CHANGED
@@ -12,14 +12,8 @@ module Dino
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def io
|
15
|
-
@io ||=
|
16
|
-
|
17
|
-
begin
|
18
|
-
SerialPort.new("/dev/#{device}", BAUD)
|
19
|
-
rescue
|
20
|
-
nil
|
21
|
-
end
|
22
|
-
end.compact.first
|
15
|
+
raise BoardNotFound unless @io ||= find_arduino
|
16
|
+
@io
|
23
17
|
end
|
24
18
|
|
25
19
|
def io=(device)
|
@@ -52,7 +46,22 @@ module Dino
|
|
52
46
|
private
|
53
47
|
|
54
48
|
def tty_devices
|
55
|
-
|
49
|
+
if RUBY_PLATFORM.include?("mswin") || RUBY_PLATFORM.include?("mingw")
|
50
|
+
["COM1", "COM2", "COM3", "COM4"]
|
51
|
+
else
|
52
|
+
`ls /dev`.split("\n").grep(/usb|ACM/).map{|d| "/dev/#{d}"}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def find_arduino
|
57
|
+
tty_devices.map do |device|
|
58
|
+
next if device.match /^cu/
|
59
|
+
begin
|
60
|
+
SerialPort.new(device, BAUD)
|
61
|
+
rescue
|
62
|
+
nil
|
63
|
+
end
|
64
|
+
end.compact.first
|
56
65
|
end
|
57
66
|
end
|
58
|
-
end
|
67
|
+
end
|
data/lib/dino/version.rb
CHANGED
@@ -2,7 +2,9 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Dino
|
4
4
|
module Components
|
5
|
+
|
5
6
|
describe BaseComponent do
|
7
|
+
|
6
8
|
it 'should initialize with board and pin' do
|
7
9
|
pin = "a pin"
|
8
10
|
board = "a board"
|
@@ -31,6 +33,33 @@ module Dino
|
|
31
33
|
BaseComponent.new(pin: 'some pin')
|
32
34
|
}.to raise_exception
|
33
35
|
end
|
36
|
+
|
37
|
+
context "when subclassed #after_initialize should be executed" do
|
38
|
+
|
39
|
+
class SpecComponent < BaseComponent
|
40
|
+
|
41
|
+
def sucessfully_initialized? ; @success ; end
|
42
|
+
|
43
|
+
def options ; @options ; end
|
44
|
+
|
45
|
+
def after_initialize(options={})
|
46
|
+
@success = true
|
47
|
+
@options = options
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
let(:options) { { pin: pin, board: board } }
|
52
|
+
let(:pin) { "a pin" }
|
53
|
+
let(:board) { "a board" }
|
54
|
+
|
55
|
+
it "should call #after_initialize with options" do
|
56
|
+
component = SpecComponent.new(options)
|
57
|
+
component.should be_sucessfully_initialized
|
58
|
+
component.options.should eq options
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
34
63
|
end
|
35
64
|
end
|
36
65
|
end
|
data/spec/lib/tx_rx_spec.rb
CHANGED
@@ -11,12 +11,30 @@ module Dino
|
|
11
11
|
end
|
12
12
|
|
13
13
|
describe '#io' do
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
context "on windows" do
|
15
|
+
it 'should instantiate a new SerialPort for each usb tty device found' do
|
16
|
+
original_platform = RUBY_PLATFORM
|
17
|
+
RUBY_PLATFORM = "mswin"
|
18
|
+
subject.should_receive(:tty_devices).and_return(["COM1", "COM2", "COM3", "COM4"])
|
19
|
+
SerialPort.should_receive(:new).with('COM1', TxRx::BAUD).and_return(mock_serial = mock)
|
20
|
+
SerialPort.should_receive(:new).with('COM2', TxRx::BAUD).and_return(mock)
|
21
|
+
SerialPort.should_receive(:new).with('COM3', TxRx::BAUD).and_return(mock)
|
22
|
+
SerialPort.should_receive(:new).with('COM4', TxRx::BAUD).and_return(mock)
|
18
23
|
|
19
|
-
|
24
|
+
subject.io.should == mock_serial
|
25
|
+
RUBY_PLATFORM = original_platform
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "on unix" do
|
30
|
+
it 'should instantiate a new SerialPort for each usb tty device found' do
|
31
|
+
subject.should_receive(:tty_devices).and_return(['/dev/tty1.usb', '/dev/tty1.usb', '/dev/tty.ACM0'])
|
32
|
+
SerialPort.should_receive(:new).with('/dev/tty1.usb', TxRx::BAUD).and_return(mock_serial = mock)
|
33
|
+
SerialPort.should_receive(:new).with('/dev/tty1.usb', TxRx::BAUD).and_return(mock)
|
34
|
+
SerialPort.should_receive(:new).with('/dev/tty.ACM0', TxRx::BAUD).and_return(mock)
|
35
|
+
|
36
|
+
subject.io.should == mock_serial
|
37
|
+
end
|
20
38
|
end
|
21
39
|
|
22
40
|
it 'should use the existing io instance if set' do
|
@@ -26,6 +44,11 @@ module Dino
|
|
26
44
|
subject.io = '/dev/tty1.usb'
|
27
45
|
subject.io.should == mock_serial
|
28
46
|
end
|
47
|
+
|
48
|
+
it 'should raise a BoardNotFound exception if there is no board connected' do
|
49
|
+
SerialPort.stub(:new).and_raise
|
50
|
+
expect { subject.io }.to raise_exception BoardNotFound
|
51
|
+
end
|
29
52
|
end
|
30
53
|
|
31
54
|
describe '#io=' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dino
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.9'
|
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: 2012-11-
|
12
|
+
date: 2012-11-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: serialport
|
@@ -37,6 +37,7 @@ extra_rdoc_files: []
|
|
37
37
|
files:
|
38
38
|
- .gitignore
|
39
39
|
- .rvmrc
|
40
|
+
- .travis.yml
|
40
41
|
- Gemfile
|
41
42
|
- LICENSE
|
42
43
|
- README.md
|
@@ -45,14 +46,18 @@ files:
|
|
45
46
|
- examples/button/button.png
|
46
47
|
- examples/button/button.rb
|
47
48
|
- examples/ir_receiver.rb
|
49
|
+
- examples/led/led.png
|
48
50
|
- examples/led/led.rb
|
49
51
|
- examples/potentiometer.rb
|
50
52
|
- examples/rgb_led.rb
|
51
53
|
- examples/sensor.rb
|
52
54
|
- examples/servo.rb
|
53
|
-
- examples/stepper.
|
55
|
+
- examples/stepper/stepper.png
|
56
|
+
- examples/stepper/stepper.rb
|
54
57
|
- lib/dino.rb
|
55
58
|
- lib/dino/board.rb
|
59
|
+
- lib/dino/board_not_found.rb
|
60
|
+
- lib/dino/components.rb
|
56
61
|
- lib/dino/components/base_component.rb
|
57
62
|
- lib/dino/components/button.rb
|
58
63
|
- lib/dino/components/ir_receiver.rb
|
@@ -63,6 +68,7 @@ files:
|
|
63
68
|
- lib/dino/components/stepper.rb
|
64
69
|
- lib/dino/tx_rx.rb
|
65
70
|
- lib/dino/version.rb
|
71
|
+
- spec/lib/board_not_found_spec.rb
|
66
72
|
- spec/lib/board_spec.rb
|
67
73
|
- spec/lib/components/base_component_spec.rb
|
68
74
|
- spec/lib/components/button_spec.rb
|
@@ -99,6 +105,7 @@ signing_key:
|
|
99
105
|
specification_version: 3
|
100
106
|
summary: Control your arduino through a serial port
|
101
107
|
test_files:
|
108
|
+
- spec/lib/board_not_found_spec.rb
|
102
109
|
- spec/lib/board_spec.rb
|
103
110
|
- spec/lib/components/base_component_spec.rb
|
104
111
|
- spec/lib/components/button_spec.rb
|