Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial commit

  • Loading branch information...
commit 2a1594646ecad7199f0cf18c7425ec442ead5feb 0 parents
@whomwah authored
8 README
@@ -0,0 +1,8 @@
+Light Controller
+================
+
+A simple HTTP proxy for controlling the spotlights at work. You can do things like
+
+http://lights.local/all/red
+http://lights.local/2/green
+http://lights.local/all/rgb100-200-255
71 app.rb
@@ -0,0 +1,71 @@
+require 'rubygems'
+require 'open-uri'
+require 'hpricot'
+require 'cgi'
+
+configure do
+ LIGHTS_PROXY = 'http://54.5.5.5'
+end
+
+helpers do
+ class LC
+ LIGHTS = [1,2]
+
+ def self.set_lights(options=nil)
+ colour = options[:colour] if options.is_a?(Hash) && options.has_key?(:colour)
+ lights = options[:lights] if options.is_a?(Hash) && options.has_key?(:lights)
+ result = []
+ lights.each do |light|
+ l = Light.new(colour,light)
+ result << l.display
+ end
+ return result.join
+ end
+ end
+
+ class Light
+ COLOURS = {
+ :blue => [0,0,255],
+ :red => [255,0,0],
+ :green => [0,255,0],
+ }
+
+ def initialize(colour,light)
+ @colour = colour
+ @light = light
+ end
+
+ def display
+ "<p>Setting the color to <em style='#{self.to_css}'>#{@colour}</em> for light <em>#{@light}</em></p>"
+ end
+
+ def to_css
+ # color: rgb(51, 51, 51);
+ if COLOURS.has_key?(@colour.to_sym)
+ "color:rgb(#{COLOURS[@colour.to_sym].join(',')});"
+ else
+ c = @colour.gsub('rgb','').gsub('-',',')
+ "color:rgb(#{c});"
+ end
+
+ end
+ end
+end
+
+# /all/red
+get %r{/(1|2|all)+/(rgb\d{0,3}-\d{0,3}-\d{0,3}|red|blue|green|random)+$} do
+ lights = [params['captures'].first]
+ lights = LC::LIGHTS if lights.include?('all')
+ colour = params['captures'][1]
+ halt 404, 'Oh dear! I understand what you\'re saying' unless lights && colour
+ LC.set_lights(
+ :lights => lights,
+ :colour => colour
+ )
+end
+
+# /(1|2|all)+/(red|blue|green|random)+/for-seconds/(\d{2})+/(flashing|strobing)?
+
+get '/' do
+ erb :index
+end
11 config.ru
@@ -0,0 +1,11 @@
+require 'rubygems'
+require 'sinatra'
+
+root_dir = File.dirname(__FILE__)
+
+set :environment, :development
+set :root, root_dir
+set :app_file, File.join(root_dir, 'app.rb')
+disable :run
+
+run Sinatra::Application
BIN  public/test.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
0  tmp/restart.txt
No changes.
20 views/index.erb
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
+<head profile="http://gmpg.org/xfn/11">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<head>
+<title>7th floor Henry Wood House spotlights controller</title>
+</head>
+<body>
+<h1>HWH 7th floor spotlight proxy</h1>
+<p>This makes playing with the spotlights a sych. Hopefully the urls give a clue.</p>
+<ul>
+<li><code><a href="">http://lights/both/red</a></code></li>
+<li><code><a href="">http://lights/both/green</a></code></li>
+<li><code><a href="">http://lights/both/blue</a></code></li>
+<li><code><a href="">http://lights/1/red</a></code></li>
+<li><code><a href="">http://lights/2/blue</a></code></li>
+<li><code><a href="">http://lights/both/off</a></code></li>
+</ul>
+</body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.