Sha256: 0e01e63c8d932ae61246206a4f34cffabf0a5cece41078823eb59114a8ffa517

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

#!/usr/bin/env ruby
require 'rubygems'
$:.unshift File.expand_path '../lib', File.dirname(__FILE__)
require 'arduino_firmata'
require 'args_parser'
require 'timeout'

parser = ArgsParser.parse ARGV, :style => :equal do
  arg :arduino, 'arduino port', :default => ArduinoFirmata.list[0]
  arg :list, 'arduino list'
  arg :version, 'show version', :alias => :v
  arg :help, 'show help', :alias => :h
end

if parser.has_option? :version
  puts "ArduinoFirmata v#{ArduinoFirmata::VERSION}"
  exit
end

if parser.has_option? :list
  ArduinoFirmata.list.each_with_index do |i, index|
    print "#{index == 0 ? '*' : ' '} "
    puts i
  end
  exit
end

if parser.has_option? :help or parser.argv.empty?
  STDERR.puts parser.help
  STDERR.puts
  STDERR.puts "e.g."
  STDERR.puts "  arduino_firmata COMMAND"
  STDERR.puts "  arduino_firmata COMMAND --arduino=/dev/tty.usb-devicename"
  STDERR.puts "  arduino_firmata \"analog_read 1\""
  STDERR.puts "  arduino_firmata \"servo_write 11, 135\" --arduino=/dev/tty.usb-devicename"
  exit 1
end

begin
  arduino = ArduinoFirmata.connect parser[:arduino]
rescue StandardError, Timeout::Error => e
  STDERR.puts e
  exit 1
end

print arduino.instance_eval parser.argv.join(' ')
sleep 1
arduino.close

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
arduino_firmata-0.2.5 bin/arduino_firmata