support for presets

This commit is contained in:
Sebastian Wiedenroth 2012-09-17 19:00:24 +02:00
parent 39ed74ddc0
commit 95323c5ce1
2 changed files with 102 additions and 12 deletions

View file

@ -4,12 +4,29 @@
<meta charset="utf-8">
<title>DMX Lichtschalter</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes" />
<link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="/static/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet">
<style>
body {
background: #222;
color: #eee;
}
input[type=range] {
-webkit-appearance: slider-vertical;
height: 200px;
width: 60px;
margin-bottom: 2em;
}
input[type=range]:after {
content: attr(value);
color: #eee;
font-family: monospace;
text-align: center;
width: 60px;
display: block;
color: #fff;
}
.device {
clear: both;
@ -20,22 +37,56 @@
float: left;
}
.btn {
margin-bottom: 1em;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script>
<script src="/static/bootstrap/js/bootstrap.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
function get_html_id(universe, channel) {
return 'channel_' + universe + '_' + channel;
}
var socket = io.connect('http://localhost');
var socket = io.connect();
socket.on('init', function (msg) {
$('.container').empty();
$('#presets').empty();
$('#sliders').empty();
setup = msg.setup
devices = msg.devices
/* preset buttons */
for(var preset in setup.presets) {
var html = '<button class="span2 btn btn-info">' + setup.presets[preset].label + '</button>';
var e = $(html)
e.hide().appendTo('#presets').fadeIn();
e.click(function(values) { return function() {
for(var universe in values) {
socket.emit('update', universe, values[universe]);
}
};}(setup.presets[preset].values));
console.log(html);
}
/* blackout button */
var blackout = $('<button class="span2 btn btn-danger">Black Out</button>');
blackout.hide().appendTo('#presets').fadeIn();
blackout.click(function() {
for(var universe in setup.universes) {
var u = {};
for(var i = 0; i < 255; i++) {
u[i] = 0;
}
socket.emit('update', universe, u);
}
});
/* sliders */
for(var universe in setup.universes) {
html = "<div><h1>" + universe + "</h1>";
var html = "<div><h1>" + universe + "</h1>";
for(var device in setup.universes[universe].devices) {
var dev = setup.universes[universe].devices[device];
html += '<div class="device">'
@ -44,13 +95,13 @@
var html_id = get_html_id(universe, channel_id);
html += '<div class="channel">'
html += '<label for="' + html_id + '">' + devices[dev.type].channels[channel] + '</label>';
html += '<input id="' + html_id + '" type="range" min="0" max="255">'
html += '<input id="' + html_id + '" type="range" min="0" value="0" max="255">'
html += '</div>'
}
html += '</div>'
}
html += "</div>";
$(html).hide().appendTo('.container').fadeIn();
$(html).hide().appendTo('#sliders').fadeIn();
}
$("input").live("change", function(e) {
var i = e.target.id.split('_');
@ -61,18 +112,37 @@
socket.emit('request_refresh');
});
socket.on('update', function (universe, update) {
console.log(update)
for(var k in update) {
$('#' + get_html_id(universe, k)).val(update[k]);
console.log(get_html_id(universe, k))
$('#' + get_html_id(universe, k)).attr('value', update[k]);
}
});
</script>
</head>
<body>
<div class="container">
<div class="navbar navbar-inverse">
<div class="navbar-inner">
<ul class="nav" id="myTab">
<li class="active"><a href="#home" data-toggle="tab">Home</a></li>
<li><a href="#sliders" data-toggle="tab">Sliders</a></li>
<li><a href="#scripts" data-toggle="tab">Scripts</a></li>
</ul>
</div>
</div>
<div class="container-fluid">
<div class="tab-content">
<div id="home" class="tab-pane active">
<div class="row-fluid" id="presets">
</div>
</div>
<div id="sliders" class="tab-pane">
</div>
<div id="scripts" class="tab-pane">
</div>
</div>
</div>
</body>
</html>

View file

@ -1,4 +1,24 @@
exports.setup = {
presets: [
{
label: 'White',
values: {
'office': { 0:16, 1:255, 2:0, 3:255, 4: 255, 5:255, 15:16, 16:255, 17:0, 18:255, 19: 255, 20:255 }
}
},
{
label: 'Natural',
values: {
'office': { 0:16, 1:255, 2:0, 3:255, 4: 190, 5:140, 15:16, 16:255, 17:0, 18:255, 19: 190, 20:140 }
}
},
{
label: 'Worklight',
values: {
'office': { 0:16, 1:130, 2:0, 3:255, 4: 165, 5:0, 15: 1, 16:255, 17:0, 18:255, 19: 190, 20:140, 21:0, 22: 0, 23:0, 24:255, 25: 190, 26:140 }
}
}
],
universes: {
'office': {
'output': {