public
Description: A DSL for building drink recipes to control the Barduino bar monkey
Homepage:
Clone URL: git://github.com/mwilliams/barduino-tender.git
barduino-tender / barduino-tender.rb
100755 56 lines (47 sloc) 1.163 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'ftools'
begin
  Kernel::require "serialport"
rescue
  puts "ERROR: requires ruby-serialport, available as a ruby gem"
  exit
end
 
def usage
  puts "You must specify a drink."
  exit(1)
end
 
class Numeric
  def ounces(ingredient)
    Drink.dispense(ingredient, self)
  end
  alias :ounce :ounces
end
 
class Drink
  @ingredients = {"vodka" => 1, "orange_juice" => 2}
  baud_rate = 9600
  data_bits = 8
  port_str = "/dev/ttyUSB0" #may be different for you
  parity = SerialPort::NONE
  stop_bits = 1
  @sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
  
  def drink(name, &block)
    puts "#{name}"
    block.call
  end
 
  def serve_in(glass)
    puts "Please use a #{glass} or one similar to it."
  end
 
  def ingredients(&block)
    block.call
  end
 
  def self.dispense(ingredient, amount)
    puts "Currently pouring #{amount} ounces of #{ingredient} from pump #{@ingredients[ingredient.to_s]}"
    amount.times do
      @sp.putc @ingredients[ingredient.to_s].to_s
      sleep 3
    end
  end
end
 
usage unless ARGV[0]
f = File.dirname(__FILE__) + "/#{ARGV[0]}"
drink = Drink.new
drink.instance_eval(File.new(f).read, f)