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.
@@ -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 = Lorraine::Message.new :set_pixel, pixel, (r * 4095).to_i, (g * 4095).to_i, (b * 4095).to_i
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
- say "Opening a connection to the LED monstrosity...", :yellow
47
- c = Lorraine::Connection.new
48
- sleep 5
49
- say "... opened.", :green
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
- pixel, r, g, b = response.split(" ")
56
- puts response
57
- m = Lorraine::Message.new :set_pixel, pixel, (r * 4095).to_i, (g * 4095).to_i, (b * 4095).to_i
58
- c.write_message(m)
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}"
@@ -45,7 +45,7 @@ module Lorraine
45
45
  end
46
46
 
47
47
  def packet
48
- [self.command_id, self.pixel, self.red.to_i, self.green.to_i, self.blue.to_i]
48
+ [self.command_id, self.pixel.to_i, self.red.to_i, self.green.to_i, self.blue.to_i]
49
49
  end
50
50
 
51
51
  def packet=(new_packet)
@@ -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 "Received message: #{m}"
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})
@@ -1,3 +1,3 @@
1
1
  module Lorraine
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: lorraine
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.4
5
+ version: 0.0.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Wil Gieseler