Created
September 4, 2008 16:38
-
-
Save atduskgreg/8804 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
module HardwareBase | |
def self.register_device_type mod, sym | |
@@device_registrations ||= {} | |
@@device_registrations[sym] = mod | |
end | |
end | |
module Servo | |
include HardwareBase | |
HardwareBase.register_device_type self, :servo | |
def output_pin_setup(num,opts) | |
puts "setting up output pins for servo" | |
end | |
end | |
module I2C | |
include HardwareBase | |
HardwareBase.register_device_type self, :i2c | |
def output_pin_setup(num,opts) | |
puts "setting up output pins for i2c" | |
end | |
end | |
class ArduinoSketch | |
include HardwareBase | |
def initialize | |
puts @@device_registrations.inspect | |
end | |
def output_pin num, opts={} | |
ArduinoSketch.send(:include, @@device_registrations[opts[:device]]) | |
output_pin_setup num, opts | |
end | |
end | |
as = ArduinoSketch.new#.device_registrations.inspect | |
as.output_pin 7, :as => :servo, :device => :servo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment