Class: Lorraine::CommandLine

Inherits:
Thor
  • Object
show all
Defined in:
lib/lorraine/command.rb

Instance Method Summary collapse

Instance Method Details

#debugObject



65
66
67
68
69
70
# File 'lib/lorraine/command.rb', line 65

def debug
  c = Lorraine::Message.new :set_pixel, 2, 0, 0, 4095
  j = c.to_json
  puts "json: #{j}"
  puts Lorraine::Message.from_json j
end

#interactiveObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/lorraine/command.rb', line 45

def interactive
  say "Opening a connection to the LED monstrosity...", :yellow
  c = Lorraine::Connection.new
  sleep 5
  say "... opened.", :green
  while true
    response = ask(">> ")
    if response == "exit"
      break
    else
      pixel, r, g, b = response.split(" ")
      puts response
      m = Lorraine::Message.new :set_pixel, pixel, (r * 4095).to_i, (g * 4095).to_i, (b * 4095).to_i
      c.write_message(m)
    end
  end
end

#server(command) ⇒ Object



19
20
21
22
23
24
# File 'lib/lorraine/command.rb', line 19

def server(command)
  puts "command: #{command}, options: #{options}"
  if command.to_sym == :start
    Lorraine::Server.start(options[:port])
  end
end

#set(pixel, r, g, b) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/lorraine/command.rb', line 30

def set(pixel, r, g, b)
  m = Lorraine::Message.new :set_pixel, pixel, (r * 4095).to_i, (g * 4095).to_i, (b * 4095).to_i
  if options[:remote]
    Lorraine::Client.send_message(m, options[:hostname], options[:port])
  else
    c = Lorraine::Connection.new
    puts "Waiting 5 seconds..."
    sleep 5
    c.write_message(m)
  end
end

#testpatternObject



9
10
11
12
13
14
15
# File 'lib/lorraine/command.rb', line 9

def testpattern
  say "nice to meet you", :red
  ask("What is your favorite Neopolitan flavor?", :limited_to => ["strawberry", "chocolate", "vanilla"])

  
  puts "I'm a thor task!"
end