lib/arduino_firmata/main.rb in arduino_firmata-0.0.5 vs lib/arduino_firmata/main.rb in arduino_firmata-0.0.6
- old
+ new
@@ -2,16 +2,23 @@
def self.list
Dir.entries('/dev').grep(/tty\.?usb/i).map{|fname| "/dev/#{fname}"}
end
- def self.connect(serial_name=nil, params={})
+ def self.connect(serial_name=nil, params={}, &block)
serial_name = self.list[0] unless serial_name
Params.default.each do |k,v|
params[k] = v unless params[k]
end
- Arduino.new serial_name, params
+ arduino = Arduino.new serial_name, params
+
+ unless block_given?
+ return arduino
+ else
+ arduino.instance_eval &block
+ arduino.close
+ end
end
end