Permalink
Browse files

Add some CLI configuration options and improve readme

  • Loading branch information...
1 parent 9526d4d commit 2b86eb30914da307c57f42a5fd7eb06ac8166144 @vickash vickash committed Feb 26, 2013
Showing with 119 additions and 28 deletions.
  1. +19 −6 README.md
  2. +100 −18 bin/dino
  3. +0 −1 src/du/Dino.cpp
  4. +0 −1 src/du/Dino.h
  5. +0 −1 src/du_ethernet/Dino.cpp
  6. +0 −1 src/du_ethernet/Dino.h
View
@@ -3,23 +3,36 @@
## Get Started In No Time
-Dino was designed to help you start working with your Arduino in minutes.
+Dino lets you start programming your Arduino with Ruby in minutes.
#### Install the Gem
```
gem install dino
```
-#### Upload the Bootstrapper
+#### Prepare the Bootstrapper
+
+Use the included command line tool to create a folder with the Arduino sketch you want to use and optionally configure it.
-* Generate the Arduino files using the included command line tool:
````
-dino generate-sketches
+# If connecting via serial, USB or ser2net, this is all you should need:
+dino generate-sketch serial
+
+# If usng the ethernet shield, you'll want to specify unique MAC and IP addresses:
+dino generate-sketch ethernet --mac XX:XX:XX:XX:XX:XX --ip XXX.XXX.XXX.XXX
+
+# For more options:
+dino help
````
+
+__Note:__ Current Ethernet shields come with a sticker indicating the MAC address you should use with them. For older shields without a dedicated MAC address, inventing a random one should work, but don't use the same one for multiple boards. Valid IP addresses depend on the configuration of your network.
+
+#### Upload The Bootstrapper
+
+* Connect the Arduino to a USB port on your machine, regardless of which sketch you're using.
* Open [the normal Arduino IDE](http://arduino.cc/en/Main/Software)
-* Open the sketch you want to upload in the Arduino IDE. Use `du.ino` if you want to talk to the Arduino via USB or Serial. Use `du_ethernet.ino` for the Ethernet shield.
-* Plug in your Arduino via USB.
+* Open the `.ino` file in the sketch folder you just generated.
* Click the upload button (an arrow).
#### Verify Install
View
118 bin/dino 100644 → 100755
@@ -1,26 +1,108 @@
#!/usr/bin/env ruby
require "pathname"
+require "fileutils"
-if ARGV[0] == "generate-sketches"
- working_dir = Dir.pwd
- src_dir = Pathname.new(__FILE__).realpath.to_s.chomp("/bin/dino") + "/src"
+$options = {}
+$options[:sketch_names] = []
- lib_files = ["Dino.h", "Dino.cpp"].map { |f| File.join src_dir, "lib", f }
- serial_sketch_file = File.join src_dir, "du", "du.ino"
- ethernet_sketch_file = File.join src_dir, "du_ethernet", "du_ethernet.ino"
+def error(message)
+ $stderr.puts "Error: " + message
+ usage
+end
- # Make directories for the sketches.
- serial_sketch_dir = File.join(working_dir, "du")
- ethernet_sketch_dir = File.join(working_dir, "du_ethernet")
- Dir::mkdir serial_sketch_dir
- Dir::mkdir ethernet_sketch_dir
+def usage
+ $stderr.puts "Usage: #{File.basename($0)} COMMAND [command-specific-options]"
+ $stderr.puts
+ $stderr.puts "Commands:"
+ $stderr.puts " generate-sketch"
+ $stderr.puts
+ $stderr.puts " Sketches:"
+ $stderr.puts " serial"
+ $stderr.puts " ethernet"
+ $stderr.puts
+ $stderr.puts " Options:"
+ $stderr.puts " --baud BAUD"
+ $stderr.puts " --mac XX:XX:XX:XX:XX:XX"
+ $stderr.puts " --ip XXX.XXX.XXX.XXX"
+ $stderr.puts " --port PORT"
+ $stderr.puts " --debug"
+ $stderr.puts
+ exit(2)
+end
- # Copy reused library files.
- [serial_sketch_dir, ethernet_sketch_dir].each do |dir|
- FileUtils.cp lib_files, dir
- end
+# Command must be the first argument.
+$options[:command] = ARGV.shift
+usage if $options[:command].match /help/
- # Copy the sketches.
- FileUtils.cp serial_sketch_file, serial_sketch_dir
- FileUtils.cp ethernet_sketch_file, ethernet_sketch_dir
+# Parse the rest loosely.
+loop do
+ case ARGV[0]
+ when 'serial'
+ ARGV.shift; $options[:sketch_names] << "du" unless $options[:sketch_names].include? "du"
+ when 'ethernet'
+ ARGV.shift; $options[:sketch_names] << "du_ethernet" unless $options[:sketch_names].include? "du_ethernet"
+ when '--baud'
+ ARGV.shift; $options[:baud] = ARGV.shift
+ when '--mac'
+ ARGV.shift; $options[:mac] = ARGV.shift
+ when '--ip'
+ ARGV.shift; $options[:ip] = ARGV.shift
+ when '--port'
+ ARGV.shift; $options[:port] = ARGV.shift
+ when '--debug'
+ ARGV.shift; $options[:debug] = true
+ when /^-/
+ error "Invalid argument '#{ARGV[0]}'"
+ else break
+ end
end
+
+error "Invalid command '#{$options[:command]}'" unless $options[:command] == "generate-sketch"
+error "No sketches or invalid sketches specified" if $options[:sketch_names].empty?
+
+$options[:sketch_names].each do |sketch_name|
+ # Define the sources.
+ sketch_dir = sketch_name
+ sketch_file = sketch_name + ".ino"
+ src_dir = Pathname.new(__FILE__).realpath.to_s.chomp("/bin/dino") + "/src"
+ src_header = File.join src_dir, "lib", "Dino.h"
+ src_implementation = File.join src_dir, "lib", "Dino.cpp"
+ src_sketch = File.join src_dir, sketch_dir, sketch_file
+
+ # Read the files.
+ header = File.read(src_header)
+ implementation = File.read(src_implementation)
+ sketch = File.read(src_sketch)
+
+ # Modify them based on the arguments.
+ if $options[:baud]
+ sketch.gsub! "115200", $options[:baud]
+ end
+ if $options[:mac]
+ octets = $options[:mac].split(':')
+ bytes = octets.map { |o| "0x#{o.upcase}" }
+ sketch.gsub! "{ 0xDE, 0xAD, 0xBE, 0x30, 0x31, 0x32 }", bytes.inspect.gsub("[", "{").gsub("]", "}").gsub("\"", "")
+ end
+ if $options[:ip]
+ sketch.gsub! "192,168,0,77", $options[:ip].gsub(".", ",")
+ end
+ if $options[:port]
+ sketch.gsub! "int port = 3466", "int port = #{$options[:port]}"
+ end
+ if $options[:debug]
+ header.gsub! "// #define debug true", "#define debug true"
+ end
+
+ # Define the destinations.
+ working_dir = Dir.pwd
+ dest_dir = File.join working_dir, sketch_dir
+ Dir::mkdir dest_dir
+ dest_header = File.join dest_dir, "Dino.h"
+ dest_implementation = File.join dest_dir, "Dino.cpp"
+ dest_sketch = File.join dest_dir, sketch_file
+
+ # Write the files.
+ File.open(dest_header, 'w') { |f| f.write header }
+ File.open(dest_implementation, 'w') { |f| f.write implementation }
+ File.open(dest_sketch, 'w') { |f| f.write sketch }
+end
View
View
View
View

0 comments on commit 2b86eb3

Please sign in to comment.