Here's the code for my lightning talk. First my drb session:
=> 1
irb(main):002:0>
The Rails controller:
class BetaBriteController < ApplicationController
def index
if params[:q]
Thread.new(params[:q], params[:c]) { |q,c|
obj = DRbObject.new_with_uri("druby://localhost:9000")
obj.write(q, c || 'red')
}
end
end
end
Finally, the DRb server:
require 'drb'
require 'serialport'
require 'monitor'
require 'rubygems'
require 'betabrite'
class Server < Monitor
def write(string, color)
synchronize do
# Open the serial port
sp = SerialPort.new('/dev/tty.PL2303-151', 9600, 8, 1, SerialPort::NONE)
BetaBrite.new { |bb|
# Set up a string file labeled '1'
bb.add BetaBrite::StringFile.new('1') { |s|
# Add the string to the file
s.write BetaBrite::String.new(string) { |a|
a.set_color color
}
}
# Write to the serial port.
}.write { |text|
sp.write text
}
sleep 1
end
end
end
server = Server.new
DRb.start_service('druby://localhost:9000', server)
DRb.thread.join