-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsphero_saddle.rb
89 lines (72 loc) · 2.17 KB
/
sphero_saddle.rb
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
require 'sphero'
require 'erb'
require 'listen'
puts "Connecting to Sphero..."
# class Sphero
# def initialize(connection) ; end
# def roll(*params)
# puts "Rolling with #{params.inspect}"
# end
# def color(*args)
# puts "Changing Color"
# end
# def stop
# puts "Stopping"
# end
# end
sphero = Sphero.new ENV['sphero'] || ARGV[0] || "/dev/tty.Sphero-GRR-RN-SPP"
puts "Connected to Sphero"
def random_color
color = Sphero::COLORS.keys.sample
puts "\n\tPicked Color: #{color}"
color
end
def sphero_template
@sphero_template ||= ERB.new %{
.----------------.
| .--------------. |
| | ____ | |
| | .' `. | |
| | / .--. \\ | | <%= @message %>
| | | | | | | |
| | \\ `--' / | |
| | `.____.' | |
| | | |
| '--------------' |
'----------------'
}
end
def say(message)
@message = message
puts sphero_template.result
end
puts %{
.----------------. .----------------. .----------------. .----------------.
| .--------------. || .--------------. || .--------------. || .--------------. |
| | ______ | || | _____ | || | __ | || | ____ ____ | |
| | |_ __ \\ | || | |_ _| | || | / \\ | || | |_ _||_ _| | |
| | | |__) | | || | | | | || | / /\\ \\ | || | \\ \\ / / | |
| | | ___/ | || | | | _ | || | / ____ \\ | || | \\ \\/ / | |
| | _| |_ | || | _| |__/ | | || | _/ / \\ \\_ | || | _| |_ | |
| | |_____| | || | |________| | || ||____| |____|| || | |______| | |
| | | || | | || | | || | | |
| '--------------' || '--------------' || '--------------' || '--------------' |
'----------------' '----------------' '----------------' '----------------'
}
Thread.abort_on_exception = true
Thread.new do
listener = Listen.to(".")
listener.change do |modified,added,removed|
if modified.first == "sphero.rb"
begin
eval File.read(modified.first)
say "Sphero is ALL DONE!"
sphero.stop
rescue Exception => exception
say "Uh Oh! Sphero Go BOOM! #{exception}"
end
end
end
listener.start
end
sleep