lorraine 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/lorraine/command.rb +26 -9
- data/lib/lorraine/message.rb +1 -1
- data/lib/lorraine/server.rb +5 -1
- data/lib/lorraine/version.rb +1 -1
- metadata +1 -1
data/lib/lorraine/command.rb
CHANGED
@@ -28,7 +28,7 @@ module Lorraine
|
|
28
28
|
method_option :hostname, type: :string, aliases: "-h", desc: "Network hostname.", default: "localhost"
|
29
29
|
method_option :port, type: :numeric, aliases: "-h", desc: "Network port.", default: 1964
|
30
30
|
def set(pixel, r, g, b)
|
31
|
-
m =
|
31
|
+
m = message_from_console_array [pixel, r, g, b]
|
32
32
|
if options[:remote]
|
33
33
|
Lorraine::Client.send_message(m, options[:hostname], options[:port])
|
34
34
|
else
|
@@ -36,26 +36,37 @@ module Lorraine
|
|
36
36
|
puts "Waiting 5 seconds..."
|
37
37
|
sleep 5
|
38
38
|
c.write_message(m)
|
39
|
+
c.write_message Lorraine::Message.new(:refresh)
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
42
43
|
map "i" => :interactive
|
43
44
|
desc "interactive", "Interact directly with the connection"
|
44
45
|
method_option :remote, type: :boolean, aliases: "-r", desc: "Interact over the network.", default: false
|
46
|
+
method_option :hostname, type: :string, aliases: "-h", desc: "Network hostname.", default: "localhost"
|
47
|
+
method_option :port, type: :numeric, aliases: "-h", desc: "Network port.", default: 1964
|
45
48
|
def interactive
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
49
|
+
c = nil
|
50
|
+
if options[:remote]
|
51
|
+
say "Let's do this through the ether...", :blue
|
52
|
+
else
|
53
|
+
say "Opening a connection to the LED monstrosity...", :yellow
|
54
|
+
c = Lorraine::Connection.new
|
55
|
+
sleep 5
|
56
|
+
say "... opened.", :green
|
57
|
+
end
|
50
58
|
while true
|
51
59
|
response = ask(">> ")
|
52
60
|
if response == "exit"
|
53
61
|
break
|
54
62
|
else
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
63
|
+
m = message_from_console_array(response.split(" "))
|
64
|
+
if options[:remote]
|
65
|
+
Lorraine::Client.send_message(m, options[:hostname], options[:port])
|
66
|
+
else
|
67
|
+
c.write_message m
|
68
|
+
c.write_message Lorraine::Message.new(:refresh)
|
69
|
+
end
|
59
70
|
end
|
60
71
|
end
|
61
72
|
end
|
@@ -69,6 +80,12 @@ module Lorraine
|
|
69
80
|
puts Lorraine::Message.from_json j
|
70
81
|
end
|
71
82
|
|
83
|
+
private
|
84
|
+
|
85
|
+
def message_from_console_array(arr)
|
86
|
+
Lorraine::Message.new :set_pixel, arr[0].to_i, (arr[1].to_f * 4095).to_i, (arr[2].to_f * 4095).to_i, (arr[3].to_f * 4095).to_i
|
87
|
+
end
|
88
|
+
|
72
89
|
#
|
73
90
|
# def self.testpattern
|
74
91
|
# # puts "command: #{command}"
|
data/lib/lorraine/message.rb
CHANGED
data/lib/lorraine/server.rb
CHANGED
@@ -12,9 +12,11 @@ module Lorraine
|
|
12
12
|
faye_server = Faye::RackAdapter.new(:mount => '/faye', :timeout => 45)
|
13
13
|
faye_server.bind(:publish) do |client_id, channel, data|
|
14
14
|
# Process incoming things
|
15
|
+
puts "Received message data: #{data}"
|
15
16
|
m = Lorraine::Message.from_packet(data)
|
16
|
-
puts "
|
17
|
+
puts "Interpereted as: #{m}"
|
17
18
|
serial_connection.write_message(m)
|
19
|
+
serial_connection.write_message Lorraine::Message.new(:refresh)
|
18
20
|
end
|
19
21
|
run faye_server
|
20
22
|
end
|
@@ -30,6 +32,8 @@ module Lorraine
|
|
30
32
|
def self.send_message(message, address = "localhost", port = "1964")
|
31
33
|
|
32
34
|
faye_json = {channel: "/illuminate", data: message.packet}.to_json
|
35
|
+
|
36
|
+
puts "sending json: #{faye_json}"
|
33
37
|
|
34
38
|
client = HTTPClient.new
|
35
39
|
puts client.post("http://#{address}:#{port}/faye", {message: faye_json})
|
data/lib/lorraine/version.rb
CHANGED