Created
July 9, 2014 02:57
-
-
Save eric-wood/e338823526dfe3423ae5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @@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