lorraine 0.0.5 → 0.0.6
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 +35 -27
- data/lib/lorraine/connection.rb +5 -41
- data/lib/lorraine/message.rb +1 -1
- data/lib/lorraine/network_connection.rb +22 -0
- data/lib/lorraine/serial_connection.rb +56 -0
- data/lib/lorraine/server.rb +23 -8
- data/lib/lorraine/version.rb +1 -1
- data/lib/lorraine.rb +2 -0
- data/web/index.html +15 -0
- data/web/lorraine.css +0 -0
- data/web/lorraine.js +55 -0
- data/web/vendor/jscolor/arrow.gif +0 -0
- data/web/vendor/jscolor/cross.gif +0 -0
- data/web/vendor/jscolor/demo.html +12 -0
- data/web/vendor/jscolor/hs.png +0 -0
- data/web/vendor/jscolor/hv.png +0 -0
- data/web/vendor/jscolor/jscolor.js +953 -0
- metadata +12 -1
data/lib/lorraine/command.rb
CHANGED
@@ -15,7 +15,7 @@ module Lorraine
|
|
15
15
|
end
|
16
16
|
|
17
17
|
desc "server <command>", "install one of the available apps"
|
18
|
-
method_option :port, type: :numeric, aliases: "-p", desc: "Port this server will be at.", default:
|
18
|
+
method_option :port, type: :numeric, aliases: "-p", desc: "Port this server will be at.", default: 3010
|
19
19
|
def server(command)
|
20
20
|
puts "command: #{command}, options: #{options}"
|
21
21
|
if command.to_sym == :start
|
@@ -26,47 +26,39 @@ module Lorraine
|
|
26
26
|
desc "set <pixel> <r> <g> <b>", "light up a pixel. rgb values from 0.0 - 1.0"
|
27
27
|
method_option :remote, type: :boolean, aliases: "-r", desc: "Set the pixel over the network.", default: false
|
28
28
|
method_option :hostname, type: :string, aliases: "-h", desc: "Network hostname.", default: "localhost"
|
29
|
-
method_option :port, type: :numeric, aliases: "-h", desc: "Network port.", default:
|
29
|
+
method_option :port, type: :numeric, aliases: "-h", desc: "Network port.", default: 3010
|
30
30
|
def set(pixel, r, g, b)
|
31
|
+
c = open_connection(options)
|
31
32
|
m = message_from_console_array [pixel, r, g, b]
|
32
|
-
|
33
|
-
|
34
|
-
else
|
35
|
-
c = Lorraine::Connection.new
|
36
|
-
puts "Waiting 5 seconds..."
|
37
|
-
sleep 5
|
38
|
-
c.write_message(m)
|
39
|
-
c.write_message Lorraine::Message.new(:refresh)
|
40
|
-
end
|
33
|
+
c.write_message m
|
34
|
+
c.write_message Lorraine::Message.new(:refresh)
|
41
35
|
end
|
42
36
|
|
43
37
|
map "i" => :interactive
|
44
38
|
desc "interactive", "Interact directly with the connection"
|
45
39
|
method_option :remote, type: :boolean, aliases: "-r", desc: "Interact over the network.", default: false
|
46
40
|
method_option :hostname, type: :string, aliases: "-h", desc: "Network hostname.", default: "localhost"
|
47
|
-
method_option :port, type: :numeric, aliases: "-h", desc: "Network port.", default:
|
41
|
+
method_option :port, type: :numeric, aliases: "-h", desc: "Network port.", default: 3010
|
48
42
|
def interactive
|
49
|
-
c =
|
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
|
43
|
+
c = open_connection(options)
|
58
44
|
while true
|
59
45
|
response = ask(">> ")
|
60
46
|
if response == "exit"
|
61
47
|
break
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
Lorraine::Client.send_message(m, options[:hostname], options[:port])
|
48
|
+
elsif response.include?("effect")
|
49
|
+
if response.include?("off")
|
50
|
+
c.write_message Lorraine::Message.new(:effect, 0)
|
66
51
|
else
|
67
|
-
c.write_message
|
68
|
-
c.write_message Lorraine::Message.new(:refresh)
|
52
|
+
c.write_message Lorraine::Message.new(:effect, response.split(" ")[1].to_i)
|
69
53
|
end
|
54
|
+
elsif response == "defcon"
|
55
|
+
defcon = Lorraine::Image.new(5, 1)
|
56
|
+
defcon.rgb_pixels = [[1, 0, 0], [1, 0.2, 0], [1, 1, 0], [0, 0, 1], [0, 1, 0]]
|
57
|
+
c.display_image defcon
|
58
|
+
else
|
59
|
+
m = message_from_console_array(response.split(" "))
|
60
|
+
c.write_message m
|
61
|
+
c.write_message Lorraine::Message.new(:refresh)
|
70
62
|
end
|
71
63
|
end
|
72
64
|
end
|
@@ -81,6 +73,22 @@ module Lorraine
|
|
81
73
|
end
|
82
74
|
|
83
75
|
private
|
76
|
+
|
77
|
+
def open_connection(options)
|
78
|
+
c = nil
|
79
|
+
if options[:remote]
|
80
|
+
say "Opening a connection through the matrix...", :green
|
81
|
+
c = Lorraine::NetworkConnection.new
|
82
|
+
c.port = options[:port]
|
83
|
+
c.hostname = options[:hostname]
|
84
|
+
else
|
85
|
+
say "Opening a connection to the LED monstrosity...", :yellow
|
86
|
+
c = Lorraine::SerialConnection.new
|
87
|
+
sleep 5
|
88
|
+
say "... and now it's open!", :green
|
89
|
+
end
|
90
|
+
c
|
91
|
+
end
|
84
92
|
|
85
93
|
def message_from_console_array(arr)
|
86
94
|
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
|
data/lib/lorraine/connection.rb
CHANGED
@@ -2,41 +2,11 @@ module Lorraine
|
|
2
2
|
|
3
3
|
class Connection
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
attr_accessor :port
|
8
|
-
|
9
|
-
def initialize(port = Lorraine::Connection.first_available_port)
|
10
|
-
|
11
|
-
#simplest ruby program to read from arduino serial,
|
12
|
-
#using the SerialPort gem
|
13
|
-
#(http://rubygems.org/gems/serialport)
|
14
|
-
|
15
|
-
|
16
|
-
#params for serial port
|
17
|
-
port_str = port # may be different for you
|
18
|
-
baud_rate = 115200
|
19
|
-
# data_bits = 8
|
20
|
-
# stop_bits = 1
|
21
|
-
# parity = SerialPort::NONE
|
22
|
-
|
23
|
-
self.port = SerialPort.new port_str, baud_rate#, data_bits, stop_bits, parity
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.first_available_port
|
28
|
-
p = Dir.glob("/dev/tty.usb*").first
|
29
|
-
raise "No available ports." unless p
|
30
|
-
p
|
5
|
+
def initialize
|
31
6
|
end
|
32
|
-
|
33
|
-
def write_binary_string(binary_string)
|
34
|
-
self.port.write binary_string
|
35
|
-
end
|
36
|
-
|
7
|
+
|
37
8
|
def write_message(msg)
|
38
|
-
puts "Writing message
|
39
|
-
write_binary_string msg.to_binary
|
9
|
+
puts "Writing message unimplemented."
|
40
10
|
end
|
41
11
|
|
42
12
|
def display_pixels(pixel_array)
|
@@ -66,16 +36,10 @@ module Lorraine
|
|
66
36
|
end
|
67
37
|
end
|
68
38
|
|
69
|
-
def read_line
|
70
|
-
m = self.port.gets
|
71
|
-
puts "Lorraine::Connection Message: #{m}"
|
72
|
-
m
|
73
|
-
end
|
74
|
-
|
75
39
|
def sever!
|
76
|
-
|
40
|
+
|
77
41
|
end
|
78
|
-
|
42
|
+
|
79
43
|
end
|
80
44
|
|
81
45
|
end
|
data/lib/lorraine/message.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Lorraine
|
2
|
+
|
3
|
+
class NetworkConnection < Lorraine::Connection
|
4
|
+
|
5
|
+
attr_writer :hostname
|
6
|
+
def hostname
|
7
|
+
@hostname || "localhost"
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_writer :port
|
11
|
+
def port
|
12
|
+
@port || "3010"
|
13
|
+
end
|
14
|
+
|
15
|
+
def write_message(msg)
|
16
|
+
Lorraine::Client.send_message(msg, self.hostname, self.port)
|
17
|
+
puts "Writing network message: #{msg}"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Lorraine
|
2
|
+
|
3
|
+
class SerialConnection < Lorraine::Connection
|
4
|
+
|
5
|
+
require "serialport"
|
6
|
+
|
7
|
+
attr_accessor :port
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
super
|
11
|
+
|
12
|
+
#simplest ruby program to read from arduino serial,
|
13
|
+
#using the SerialPort gem
|
14
|
+
#(http://rubygems.org/gems/serialport)
|
15
|
+
|
16
|
+
|
17
|
+
#params for serial port
|
18
|
+
# port_str = port # may be different for you
|
19
|
+
baud_rate = 115200
|
20
|
+
# data_bits = 8
|
21
|
+
# stop_bits = 1
|
22
|
+
# parity = SerialPort::NONE
|
23
|
+
|
24
|
+
self.port = SerialPort.new Lorraine::SerialConnection.first_available_port, baud_rate#, data_bits, stop_bits, parity
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.first_available_port
|
29
|
+
p = Dir.glob("/dev/tty.usb*").first
|
30
|
+
raise "No available ports." unless p
|
31
|
+
p
|
32
|
+
end
|
33
|
+
|
34
|
+
def write_binary_string(binary_string)
|
35
|
+
self.port.write binary_string
|
36
|
+
end
|
37
|
+
|
38
|
+
def write_message(msg)
|
39
|
+
puts "Writing serial message: #{msg}"
|
40
|
+
write_binary_string msg.to_binary
|
41
|
+
end
|
42
|
+
|
43
|
+
def read_line
|
44
|
+
m = self.port.gets
|
45
|
+
puts "Lorraine::SerialConnection Message: #{m}"
|
46
|
+
m
|
47
|
+
end
|
48
|
+
|
49
|
+
def sever!
|
50
|
+
super
|
51
|
+
self.port.close
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
data/lib/lorraine/server.rb
CHANGED
@@ -6,17 +6,32 @@ module Lorraine
|
|
6
6
|
require 'thin'
|
7
7
|
|
8
8
|
def self.start(port)
|
9
|
-
|
9
|
+
begin
|
10
|
+
serial_connection = Lorraine::SerialConnection.new
|
11
|
+
rescue
|
12
|
+
"Failed to start serial connection."
|
13
|
+
end
|
10
14
|
Thin::Server.start('0.0.0.0', port) do
|
15
|
+
|
16
|
+
map "/admin" do
|
17
|
+
files = File.expand_path(File.join(__FILE__, "..", "..", "..", "web"))
|
18
|
+
puts "serving files from #{files}"
|
19
|
+
run Rack::File.new(files)
|
20
|
+
end
|
21
|
+
|
11
22
|
Faye::WebSocket.load_adapter('thin')
|
12
23
|
faye_server = Faye::RackAdapter.new(:mount => '/faye', :timeout => 45)
|
13
24
|
faye_server.bind(:publish) do |client_id, channel, data|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
25
|
+
begin
|
26
|
+
# Process incoming things
|
27
|
+
puts "Received message data: #{data}"
|
28
|
+
m = Lorraine::Message.from_packet(data)
|
29
|
+
puts "Interpereted as: #{m}"
|
30
|
+
serial_connection.write_message(m)
|
31
|
+
# serial_connection.write_message Lorraine::Message.new(:refresh)
|
32
|
+
rescue
|
33
|
+
puts "Failed to read data."
|
34
|
+
end
|
20
35
|
end
|
21
36
|
run faye_server
|
22
37
|
end
|
@@ -29,7 +44,7 @@ module Lorraine
|
|
29
44
|
require 'json'
|
30
45
|
require 'httpclient'
|
31
46
|
|
32
|
-
def self.send_message(message, address = "localhost", port = "
|
47
|
+
def self.send_message(message, address = "localhost", port = "3010")
|
33
48
|
|
34
49
|
faye_json = {channel: "/illuminate", data: message.packet}.to_json
|
35
50
|
|
data/lib/lorraine/version.rb
CHANGED
data/lib/lorraine.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require "lorraine/version"
|
2
2
|
require "lorraine/message"
|
3
3
|
require "lorraine/connection"
|
4
|
+
require "lorraine/serial_connection"
|
5
|
+
require "lorraine/network_connection"
|
4
6
|
require "lorraine/image"
|
5
7
|
require "lorraine/server"
|
6
8
|
require_relative "../vendor/colorist/colorist"
|
data/web/index.html
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Lorraine - on the nets</title>
|
5
|
+
<link href="lorraine.css" media="screen" rel="stylesheet" type="text/css" />
|
6
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
|
7
|
+
<script src="/faye.js" type="text/javascript"></script>
|
8
|
+
<script src="lorraine.js" type="text/javascript"></script>
|
9
|
+
<script src="vendor/jscolor/jscolor.js" type="text/javascript"></script>
|
10
|
+
</head>
|
11
|
+
<body>
|
12
|
+
<h1>Hey Howdy Hey</h1>
|
13
|
+
Color: <input class="color {onImmediateChange:'colorChanged(this);'}" value="66ff00">
|
14
|
+
</body>
|
15
|
+
</html>
|
data/web/lorraine.css
ADDED
File without changes
|
data/web/lorraine.js
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
$(function(){
|
2
|
+
|
3
|
+
// Find the host
|
4
|
+
//var pathArray = window.location.pathname.split( '/' );
|
5
|
+
var host = getBaseURL() //pathArray[0]; // + "/";
|
6
|
+
|
7
|
+
// alert(host);
|
8
|
+
|
9
|
+
window.faye_client = new Faye.Client(host + "faye");
|
10
|
+
|
11
|
+
window.faye_client.subscribe('/messages', function(message) {
|
12
|
+
alert('Got a message: ' + message.text);
|
13
|
+
});
|
14
|
+
|
15
|
+
});
|
16
|
+
|
17
|
+
function illuminatePixel(pixel, r, g, b) {
|
18
|
+
window.faye_client.publish('/illuminate', [1, pixel, r * 4095, g * 4095, b * 4095]);
|
19
|
+
}
|
20
|
+
|
21
|
+
function illuminateAll(r, g, b) {
|
22
|
+
illuminatePixel(0, r, g, b);
|
23
|
+
illuminatePixel(1, r, g, b);
|
24
|
+
illuminatePixel(2, r, g, b);
|
25
|
+
illuminatePixel(3, r, g, b);
|
26
|
+
illuminatePixel(4, r, g, b);
|
27
|
+
}
|
28
|
+
|
29
|
+
|
30
|
+
function colorChanged(color) {
|
31
|
+
illuminateAll(color.rgb[0], color.rgb[1], color.rgb[2])
|
32
|
+
}
|
33
|
+
|
34
|
+
|
35
|
+
function getBaseURL() {
|
36
|
+
var url = location.href; // entire url including querystring - also: window.location.href;
|
37
|
+
var baseURL = url.substring(0, url.indexOf('/', 14));
|
38
|
+
|
39
|
+
|
40
|
+
if (baseURL.indexOf('http://localhost') != -1) {
|
41
|
+
// Base Url for localhost
|
42
|
+
var url = location.href; // window.location.href;
|
43
|
+
var pathname = location.pathname; // window.location.pathname;
|
44
|
+
var index1 = url.indexOf(pathname);
|
45
|
+
var index2 = url.indexOf("/", index1 + 1);
|
46
|
+
var baseLocalUrl = url.substr(0, index2);
|
47
|
+
|
48
|
+
return baseLocalUrl + "/";
|
49
|
+
}
|
50
|
+
else {
|
51
|
+
// Root Url for domain name
|
52
|
+
return baseURL + "/";
|
53
|
+
}
|
54
|
+
|
55
|
+
}
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|