lib/wall_e.rb in wall_e-0.0.3 vs lib/wall_e.rb in wall_e-0.0.4
- old
+ new
@@ -6,14 +6,14 @@
# TODO everything in components should be required automagically.
require 'wall_e/components/led'
require 'wall_e/components/servo'
require 'wall_e/components/piezo'
require 'wall_e/components/claw'
+require 'wall_e/components/button'
module WallE
class Assembler
-
attr_reader :board
def self.build(&block)
wall_e = create
@@ -49,42 +49,68 @@
end
# TODO some metaprogramming sauce to reduce the component helper code.
def Led(pin_number)
pin = Pin.new(pin_number, @board)
- Led.new(pin)
+ (leds << Led.new(pin)).last
end
def Servo(pin_number, options = {})
pin = Pin.new(pin_number, @board)
- Servo.new(pin, options)
+ (servos << Servo.new(pin, options)).last
end
def Piezo(pin_number)
pin = Pin.new(pin_number, @board)
- Piezo.new(pin)
+ (piezos << Piezo.new(pin)).last
end
def Claw(claw_pin_number, pan_pin_number)
claw_servo = Servo(claw_pin_number, range: 60..144)
pan_servo = Servo(pan_pin_number)
- Claw.new(claw_servo, pan_servo)
+ (claws << Claw.new(claw_servo, pan_servo)).last
end
+ def Button(pin_number)
+ pin = Pin.new(pin_number, @board)
+ (buttons << Button.new(pin)).last
+ end
+
+ # TODO wrap up these collections in some metaprogramming sauce too.
+ def leds
+ @leds ||= []
+ end
+
+ def servos
+ @servos ||= []
+ end
+
+ def piezos
+ @piezos ||= []
+ end
+
+ def claws
+ @claws ||= []
+ end
+
+ def buttons
+ @buttons ||= []
+ end
+
def delay(seconds)
@board.delay seconds
end
def pause
@running = false
end
def resume
- @running = true
@group.list.each(&:wakeup)
+ @running = true
end
- def turn_off
+ def shut_down
@group.list.each(&:kill)
end
def repeat(&block)
t = Thread.new do
\ No newline at end of file