Skip to content

Instantly share code, notes, and snippets.

@eric-wood
Created July 9, 2014 02:57
Show Gist options
  • Select an option

  • Save eric-wood/e338823526dfe3423ae5 to your computer and use it in GitHub Desktop.

Select an option

Save eric-wood/e338823526dfe3423ae5 to your computer and use it in GitHub Desktop.
@@events = {
distance: [],
angle: []
}
def register_event(name, &block)
@@events[name] << &block
return block
end
def bump(&block)
@@register_event(:bump_or_whatever, block)
end
loop do
read, write = IO.select([roomba],[roomba])
if read
# read sensor data
# sensor data is a hash of event names to values
events = get_sensor_list(@@events.keys)
events.each do |name,value|
@@events[name].each do |event|
event.call(value)
end
end
elsif write
# meh
end
end
Roomba.new('/asdf/') do
bump do
puts "hey, knock that off!"
end
forward
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment