Permalink
Browse files

OSX AND WINDOWS SUPPORT: instructions for use to follow on the wiki and

blog.
  • Loading branch information...
1 parent 3eff99d commit 2856baacdb2b4e98a8437af45d998c6ea045295b @evanfarrar committed Jan 23, 2009
Showing with 118 additions and 0 deletions.
  1. +85 −0 lib/sensors/network_sensor.rb
  2. +1 −0 lib/setup.rb
  3. +32 −0 serproxy.cfg
@@ -0,0 +1,85 @@
+#Arduino: a sensor written for the arduino open source hardware.
+class Sensor
+ attr_accessor :queue
+ def initialize(filename=nil)
+ @f = TCPSocket.new("127.0.0.1", 5331)
+ end
+
+ def start
+ @t.kill if @t
+ Thread.abort_on_exception = true
+ @t = Thread.new do
+ @f.putc 'g'
+ Thread.current["racers"] = [[],[],[],[]]
+ Thread.current["finish_times"] = []
+ @f.flush
+ while true do
+ l = c = ''
+ until c == "\000"
+ begin
+ c = @f.read_nonblock(1)
+ print c
+ l << c
+ rescue
+ puts "waiting..."
+ end
+ end
+ l.gsub!(/\000/,'')
+ if l=~/:/
+ if l =~ /1:/
+ Thread.current["racers"][0] = [1] * l.gsub(/1: /,'').to_i
+ end
+ if l =~ /2:/
+ Thread.current["racers"][1] = [2] * l.gsub(/2: /,'').to_i
+ end
+ if l =~ /3:/
+ Thread.current["racers"][2] = [3] * l.gsub(/3: /,'').to_i
+ end
+ if l =~ /4:/
+ Thread.current["racers"][3] = [4] * l.gsub(/4: /,'').to_i
+ end
+ if l =~ /1f:/
+ Thread.current["finish_times"][0] = l.gsub(/1f: /,'').to_i
+ end
+ if l =~ /2f:/
+ Thread.current["finish_times"][1] = l.gsub(/2f: /,'').to_i
+ end
+ if l =~ /3f:/
+ Thread.current["finish_times"][2] = l.gsub(/3f: /,'').to_i
+ end
+ if l =~ /4f:/
+ Thread.current["finish_times"][3] = l.gsub(/4f: /,'').to_i
+ end
+ if l =~ /t:/
+ Thread.current["time"] = l.gsub(/t: /,'').to_i
+ end
+ end
+ puts l
+ end
+ end
+ self
+ end
+
+ def finish_times
+ @t['finish_times'] || []
+ end
+
+ def values
+ {:red => @t["red"], :blue => @t["blue"],
+ :red_finish => @t["red_finish"], :blue_finish => @t["blue_finish"]}
+ end
+
+ def racers
+ @t['racers'] || [[],[],[],[]]
+ end
+
+ def time
+ @t['time'] || 0
+ end
+
+ def stop
+ @f.puts 's'
+ @f.flush
+ @t.kill
+ end
+end
View
@@ -1,4 +1,5 @@
require 'yaml'
+require 'socket'
require 'lib/race_data'
begin
View
@@ -0,0 +1,32 @@
+# Config file for serproxy
+# See serproxy's README file for documentation
+
+# Transform newlines coming from the serial port into nils
+# true (e.g. if using Flash) or false
+newlines_to_nils=true
+
+# Comm ports used
+comm_ports=1
+serial_device1=/dev/ttyUSB0
+
+# Default settings
+comm_baud=115200
+comm_databits=8
+comm_stopbits=1
+comm_parity=none
+
+# Idle time out in seconds
+timeout=300
+
+# Port 1 settings (ttyS0)
+net_port1=5331
+
+# Port 2 settings (ttyS1)
+net_port2=5332
+
+# Port 3 settings (ttyS2)
+net_port3=5333
+
+# Port 4 settings (ttyS3)
+net_port4=5334
+

0 comments on commit 2856baa

Please sign in to comment.