Browse files

Device should be part of options. Change TxRx::USBSerial to TxRx::Ser…

…ial. Update examples.
  • Loading branch information...
1 parent 215043d commit baba33fcb228eb2e1fee060b0482ba2d9cea67d9 @vickash vickash committed Mar 1, 2013
View
2 examples/button/button.rb
@@ -7,7 +7,7 @@
require 'bundler/setup'
require 'dino'
-board = Dino::Board.new(Dino::TxRx.new)
+board = Dino::Board.new(Dino::TxRx::Serial.new)
button = Dino::Components::Button.new(pin: 13, board: board)
button.down do
View
2 examples/ir_receiver/ir_receiver.rb
@@ -7,7 +7,7 @@
require 'bundler/setup'
require 'dino'
-board = Dino::Board.new(Dino::TxRx.new)
+board = Dino::Board.new(Dino::TxRx::Serial.new)
ir = Dino::Components::IrReceiver.new(pin: 2, board: board)
led = Dino::Components::Led.new(pin: 13, board: board)
View
2 examples/led/led.rb
@@ -5,7 +5,7 @@
require 'bundler/setup'
require 'dino'
-board = Dino::Board.new(Dino::TxRx.new)
+board = Dino::Board.new(Dino::TxRx::Serial.new)
led = Dino::Components::Led.new(pin: 13, board: board)
[:on, :off].cycle do |switch|
View
2 examples/potentiometer/potentiometer.rb
@@ -7,7 +7,7 @@
require 'bundler/setup'
require 'dino'
-board = Dino::Board.new(Dino::TxRx.new)
+board = Dino::Board.new(Dino::TxRx::Serial.new)
led = Dino::Components::Led.new(pin: 13, board: board)
potentiometer = Dino::Components::Sensor.new(pin: 'A0', board: board)
View
2 examples/rgb_led/rgb_led.rb
@@ -5,7 +5,7 @@
require 'bundler/setup'
require 'dino'
-board = Dino::Board.new(Dino::TxRx.new)
+board = Dino::Board.new(Dino::TxRx::Serial.new)
led = Dino::Components::RgbLed.new(pins: {red: 11, green: 10, blue: 9}, board: board)
potentiometer = Dino::Components::Sensor.new(pin: 'A0', board: board)
View
2 examples/sensor/sensor.rb
@@ -7,7 +7,7 @@
require 'bundler/setup'
require 'dino'
-board = Dino::Board.new(Dino::TxRx.new)
+board = Dino::Board.new(Dino::TxRx::Serial.new)
sensor = Dino::Components::Sensor.new(pin: 'A0', board: board)
sensor.when_data_received do |data|
View
2 examples/servo/servo.rb
@@ -4,7 +4,7 @@
require 'bundler/setup'
require 'dino'
-board = Dino::Board.new(Dino::TxRx.new)
+board = Dino::Board.new(Dino::TxRx::Serial.new)
servo = Dino::Components::Servo.new(pin: 9, board: board)
loop do
View
2 examples/stepper/stepper.rb
@@ -4,7 +4,7 @@
require 'bundler/setup'
require 'dino'
-board = Dino::Board.new(Dino::TxRx.new)
+board = Dino::Board.new(Dino::TxRx::Serial.new)
stepper = Dino::Components::Stepper.new(board: board, pins: { step: 10, direction: 8 })
1600.times do
View
6 lib/dino/tx_rx.rb
@@ -1,11 +1,11 @@
module Dino
module TxRx
require 'dino/tx_rx/base'
- require 'dino/tx_rx/usb_serial'
+ require 'dino/tx_rx/serial'
require 'dino/tx_rx/tcp'
- def self.new(device = nil)
- self::USBSerial.new(device)
+ def self.new(options={})
+ self::Serial.new(options)
end
end
end
View
6 lib/dino/tx_rx/usb_serial.rb → lib/dino/tx_rx/serial.rb
@@ -2,11 +2,11 @@
module Dino
module TxRx
- class USBSerial < Base
+ class Serial < Base
BAUD = 115200
- def initialize(device = nil, options={})
- @device = device
+ def initialize(options={})
+ @device = options[:device]
@baud = options[:baud] || BAUD
@first_write = true
end
View
16 spec/lib/tx_rx/usb_serial_spec.rb
@@ -1,13 +1,15 @@
require 'spec_helper'
module Dino
- describe TxRx::USBSerial do
+ describe TxRx::Serial do
it { should be }
describe '#initialize' do
it 'should set first_write to false' do
- TxRx::USBSerial.new.instance_variable_get(:@first_write).should == true
+ TxRx::Serial.new.instance_variable_get(:@first_write).should == true
end
+ it 'should connect to the specified device'
+ it 'should connect at the specified baud rate'
end
describe '#io' do
@@ -18,9 +20,9 @@ module Dino
subject.should_receive(:tty_devices).and_return(["COM1", "COM2", "COM3"])
# COM2 is chosen as available for this test.
- SerialPort.should_receive(:new).with("COM1", TxRx::USBSerial::BAUD).and_raise
- SerialPort.should_receive(:new).with("COM2", TxRx::USBSerial::BAUD).and_return(mock_serial = mock)
- SerialPort.should_not_receive(:new).with("COM3", TxRx::USBSerial::BAUD)
+ SerialPort.should_receive(:new).with("COM1", TxRx::Serial::BAUD).and_raise
+ SerialPort.should_receive(:new).with("COM2", TxRx::Serial::BAUD).and_return(mock_serial = mock)
+ SerialPort.should_not_receive(:new).with("COM3", TxRx::Serial::BAUD)
subject.io.should == mock_serial
Constants.redefine(:RUBY_PLATFORM, original_platform, :on => Object)
@@ -32,8 +34,8 @@ module Dino
subject.should_receive(:tty_devices).and_return(['/dev/ttyACM0', '/dev/tty.usbmodem1'])
# /dev/ttyACM0 is chosen as available for this test.
- SerialPort.should_receive(:new).with('/dev/ttyACM0', TxRx::USBSerial::BAUD).and_return(mock_serial = mock)
- SerialPort.should_not_receive(:new).with('/dev/tty.usbmodem1', TxRx::USBSerial::BAUD)
+ SerialPort.should_receive(:new).with('/dev/ttyACM0', TxRx::Serial::BAUD).and_return(mock_serial = mock)
+ SerialPort.should_not_receive(:new).with('/dev/tty.usbmodem1', TxRx::Serial::BAUD)
subject.io.should == mock_serial
end

0 comments on commit baba33f

Please sign in to comment.