Skip to content

Instantly share code, notes, and snippets.

@atduskgreg
Created September 4, 2008 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atduskgreg/8804 to your computer and use it in GitHub Desktop.
Save atduskgreg/8804 to your computer and use it in GitHub Desktop.
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