Browse files

subduino

  • Loading branch information...
1 parent bff2140 commit 687465a32adab5a5188ec134b679814c0c0bfe9f @nofxx committed Aug 19, 2010
Showing with 177 additions and 3 deletions.
  1. +5 −0 .document
  2. +23 −1 .gitignore
  3. +20 −0 LICENSE
  4. +45 −0 Rakefile
  5. +1 −0 VERSION
  6. 0 duino/bin/duino → bin/subduino
  7. +0 −1 duino/.gitignore
  8. +1 −1 duino/VERSION
  9. +65 −0 lib/subduino.rb
  10. +1 −0 spec/spec.opts
  11. +9 −0 spec/spec_helper.rb
  12. +7 −0 spec/subduino_spec.rb
View
5 .document
@@ -0,0 +1,5 @@
+README.rdoc
+lib/**/*.rb
+bin/*
+features/**/*.feature
+LICENSE
View
24 .gitignore
@@ -1,3 +1,25 @@
+## MAC OS
+.DS_Store
+
+## TEXTMATE
+*.tmproj
+tmtags
+
+## EMACS
+*~
+\#*
+.\#*
+
+## VIM
+*.swp
+
+## PROJECT::GENERAL
+coverage
+rdoc
+pkg
+
+## PROJECT::SPECIFIC
*.log
+*.gem
*.rdb
-*.cache
+*.cache
View
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2009 Marcos Piccinini
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
45 Rakefile
@@ -0,0 +1,45 @@
+require 'rubygems'
+require 'rake'
+
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gem|
+ gem.name = "subduino"
+ gem.summary = %Q{TODO: one-line summary of your gem}
+ gem.description = %Q{TODO: longer description of your gem}
+ gem.email = "x@nofxx.com"
+ gem.homepage = "http://github.com/nofxx/subduino"
+ gem.authors = ["Marcos Piccinini"]
+ gem.add_development_dependency "rspec", ">= 1.2.9"
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
+ end
+ Jeweler::GemcutterTasks.new
+rescue LoadError
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
+end
+
+require 'spec/rake/spectask'
+Spec::Rake::SpecTask.new(:spec) do |spec|
+ spec.libs << 'lib' << 'spec'
+ spec.spec_files = FileList['spec/**/*_spec.rb']
+end
+
+Spec::Rake::SpecTask.new(:rcov) do |spec|
+ spec.libs << 'lib' << 'spec'
+ spec.pattern = 'spec/**/*_spec.rb'
+ spec.rcov = true
+end
+
+task :spec => :check_dependencies
+
+task :default => :spec
+
+require 'rake/rdoctask'
+Rake::RDocTask.new do |rdoc|
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
+
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = "subduino #{version}"
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
View
1 VERSION
@@ -0,0 +1 @@
+0.0.1
View
0 duino/bin/duino → bin/subduino
File renamed without changes.
View
1 duino/.gitignore
@@ -1 +0,0 @@
-*.gem
View
2 duino/VERSION
@@ -1 +1 @@
-0.0.1
+0.1.0
View
65 lib/subduino.rb
@@ -0,0 +1,65 @@
+#
+#
+# Arduino PubSub Hub
+#
+#
+#
+require 'serialport'
+require 'stringio'
+require 'readline'
+require 'logger'
+require 'redis'
+
+LOG = Logger.new("out.log")
+BAUDS = 115200
+#BAUDS = 9600
+DATA_BITS = 8
+DATA_STOP = 1
+parity = SerialPort::NONE
+Thread.current.abort_on_exception = false
+
+def halt!
+ puts "Closing daemon..."
+ @redis.quit
+ @sp.close
+ puts "OK"
+ exit 0
+end
+trap(:TERM) { halt! }
+trap(:INT) { halt! }
+
+def log(txt, type="info")
+ LOG.send(type, txt)
+end
+
+@qi, @qo = Queue.new, Queue.new
+@redis = Redis.new(:timeout => 0)
+@sp = SerialPort.new("/dev/ttyUSB0", BAUDS) #, DATA_BITS, DATA_STOP, parity)
+# @sp.read_timeout = 10;# @sp.write_timeout = 10
+
+log "[USB] Starting USB Connect..." + @sp.get_modem_params.map { |k,v| "#{k}: #{v}" }.join(" ")
+log "[USB] Read Timeout #{@sp.read_timeout}" # {@sp.write_timeout}"
+
+
+class Arduino
+
+ def initialize
+ port_str = "/dev/tty.usbserial-A6004bX6" #may be different for you
+ baud_rate = 9600
+ data_bits = 8
+ stop_bits = 1
+ parity = SerialPort::NONE
+
+ @sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
+ end
+
+ def send_to_arduino(string)
+ string.to_s.chomp.split("").each do |char|
+ @sp.putc char
+ end
+ end
+
+ def close_connection
+ @sp.close
+ end
+end
View
1 spec/spec.opts
@@ -0,0 +1 @@
+--color
View
9 spec/spec_helper.rb
@@ -0,0 +1,9 @@
+$LOAD_PATH.unshift(File.dirname(__FILE__))
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
+require 'subduino'
+require 'spec'
+require 'spec/autorun'
+
+Spec::Runner.configure do |config|
+
+end
View
7 spec/subduino_spec.rb
@@ -0,0 +1,7 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+
+describe "Subduino" do
+ it "fails" do
+ fail "hey buddy, you should probably rename this file and start specing for real"
+ end
+end

0 comments on commit 687465a

Please sign in to comment.