#!/usr/bin/env ruby $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) #require 'pry' #require 'faye' require 'rubygems' require 'optparse' require 'subduino' require 'subduino/os' Debug = false op = OptionParser.new { |op| op.on('-d', '--debug') { |d| Debug = true } op.on('-b', '--bauds=BAUDS', Integer) { |b| Subduino::Opts[:bauds] = b } op.on('-p', '--port=/dev/port') { |p| Subduino::Opts[:port] = p } # op.on('-e env') { |val| set :environment, val.to_sym } # op.on('-s server') { |val| set :server, val } op.parse!(ARGV) } # Cubduino.write("hahah") # puts Cubduino.read if ARGV.empty? || ARGV.join =~ /yml/ LastRun = {:all => 0} # client = Faye::Client.new('http://localhost:8000/faye') EM.run do if Debug puts "Starting on #{OS}" puts "--------------------- #{Time.now}" end Subduino.start do |read| print read if Debug if LastRun[:all] < (Time.now.to_i - Subduino::Opts[:log_interval]) LastRun[:all] = Time.now.to_i # client.publish('/stats', 'data' => read) Subduino::Store.add_csv_to_store(read, true) else Subduino::Store.add_csv_to_store(read) end end end elsif ARGV.join =~ /send/ txt = ARGV[1..-1].join puts "Writing #{txt}" Subduino::ArdPS.write(txt) else require "subduino/scaffold/generator" dir = ARGV[0] puts "Subduing dir #{dir}" `mkdir #{dir}` unless File.exists?(dir) Subduino::Generator.copy_files(dir) end