2012-09-08 12:43:04 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<title>DMX Lichtschalter</title>
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
2012-09-17 17:00:24 +00:00
|
|
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
2013-11-17 16:45:53 +00:00
|
|
|
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
|
2012-09-08 12:43:04 +00:00
|
|
|
<style>
|
2012-09-17 17:00:24 +00:00
|
|
|
body {
|
|
|
|
background: #222;
|
|
|
|
color: #eee;
|
|
|
|
}
|
2017-07-30 14:46:39 +00:00
|
|
|
h1 {
|
|
|
|
clear: both;
|
|
|
|
}
|
2012-09-08 12:43:04 +00:00
|
|
|
input[type=range] {
|
|
|
|
-webkit-appearance: slider-vertical;
|
2017-07-30 16:06:15 +00:00
|
|
|
height: 100px;
|
2012-09-08 12:43:04 +00:00
|
|
|
width: 60px;
|
2012-09-17 17:00:24 +00:00
|
|
|
margin-bottom: 2em;
|
2017-07-30 16:06:15 +00:00
|
|
|
margin-top: 3em;
|
2012-09-17 17:00:24 +00:00
|
|
|
}
|
|
|
|
|
2013-11-17 00:41:27 +00:00
|
|
|
input[type=range]:before {
|
2012-09-17 17:00:24 +00:00
|
|
|
content: attr(value);
|
|
|
|
color: #eee;
|
|
|
|
font-family: monospace;
|
|
|
|
text-align: center;
|
|
|
|
width: 60px;
|
|
|
|
display: block;
|
|
|
|
color: #fff;
|
2013-11-17 00:41:27 +00:00
|
|
|
position: absolute;
|
2017-07-30 16:06:15 +00:00
|
|
|
top: 2em;
|
2012-09-08 12:43:04 +00:00
|
|
|
}
|
|
|
|
.device {
|
|
|
|
clear: both;
|
|
|
|
padding-top: 1em;
|
|
|
|
}
|
|
|
|
.channel {
|
2017-07-30 16:06:15 +00:00
|
|
|
position: relative;
|
2012-09-08 12:43:04 +00:00
|
|
|
text-align: center;
|
|
|
|
float: left;
|
|
|
|
}
|
|
|
|
|
2012-09-17 17:00:24 +00:00
|
|
|
.btn {
|
|
|
|
margin-bottom: 1em;
|
|
|
|
}
|
2012-09-08 12:43:04 +00:00
|
|
|
</style>
|
2012-09-17 17:00:24 +00:00
|
|
|
<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>
|
2013-11-17 16:45:53 +00:00
|
|
|
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
|
2012-09-08 12:43:04 +00:00
|
|
|
<script src="/socket.io/socket.io.js"></script>
|
|
|
|
<script>
|
|
|
|
function get_html_id(universe, channel) {
|
|
|
|
return 'channel_' + universe + '_' + channel;
|
|
|
|
}
|
2012-09-17 17:00:24 +00:00
|
|
|
|
2018-07-02 02:28:12 +00:00
|
|
|
function rgb_to_array(str) {
|
|
|
|
m = str.match(/^#([0-9a-f]{6})$/i)[1];
|
|
|
|
if(m) {
|
|
|
|
return [
|
|
|
|
parseInt(m.substr(0,2),16),
|
|
|
|
parseInt(m.substr(2,2),16),
|
|
|
|
parseInt(m.substr(4,2),16)
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function decimalToHex(d, padding) {
|
|
|
|
var hex = Number(d).toString(16);
|
|
|
|
padding = typeof (padding) === "undefined" || padding === null ? padding = 2 : padding;
|
|
|
|
while (hex.length < padding) {
|
|
|
|
hex = "0" + hex;
|
|
|
|
}
|
|
|
|
return hex;
|
|
|
|
}
|
|
|
|
|
|
|
|
function array_to_rgb(arr) {
|
|
|
|
return '#'+decimalToHex(arr[0])+decimalToHex(arr[1])+decimalToHex(arr[2]);
|
|
|
|
}
|
|
|
|
|
2018-01-10 20:28:44 +00:00
|
|
|
var socket = io();
|
2012-09-08 12:43:04 +00:00
|
|
|
socket.on('init', function (msg) {
|
2012-09-17 17:00:24 +00:00
|
|
|
$('#presets').empty();
|
|
|
|
$('#sliders').empty();
|
2012-09-08 12:43:04 +00:00
|
|
|
setup = msg.setup
|
|
|
|
devices = msg.devices
|
2012-09-17 17:00:24 +00:00
|
|
|
|
|
|
|
/* 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 */
|
2012-09-08 12:43:04 +00:00
|
|
|
for(var universe in setup.universes) {
|
2012-09-17 17:00:24 +00:00
|
|
|
var html = "<div><h1>" + universe + "</h1>";
|
2012-09-08 12:43:04 +00:00
|
|
|
for(var device in setup.universes[universe].devices) {
|
|
|
|
var dev = setup.universes[universe].devices[device];
|
|
|
|
html += '<div class="device">'
|
|
|
|
for(var channel in devices[dev.type].channels) {
|
|
|
|
var channel_id = dev.address + Number(channel)
|
|
|
|
var html_id = get_html_id(universe, channel_id);
|
|
|
|
html += '<div class="channel">'
|
|
|
|
html += '<label for="' + html_id + '">' + devices[dev.type].channels[channel] + '</label>';
|
2017-07-30 16:06:15 +00:00
|
|
|
html += '<input id="' + html_id + '" type="range" min="0" value="0" max="255" orient="vertical">'
|
2012-09-08 12:43:04 +00:00
|
|
|
html += '</div>'
|
|
|
|
}
|
2018-07-02 02:28:12 +00:00
|
|
|
if(devices[dev.type].channels.includes('red') && devices[dev.type].channels.includes('blue') && devices[dev.type].channels.includes('green')) {
|
|
|
|
var html_id = get_html_id(universe, dev.address);
|
|
|
|
html += '<input id="picker_'+html_id+'" type="color" data-red="'+devices[dev.type].channels.indexOf('red');
|
|
|
|
html += '" data-green="'+devices[dev.type].channels.indexOf('green')+'" data-blue="'+devices[dev.type].channels.indexOf('blue')+'"/>';
|
|
|
|
}
|
2012-09-08 12:43:04 +00:00
|
|
|
html += '</div>'
|
|
|
|
}
|
|
|
|
html += "</div>";
|
2012-09-17 17:00:24 +00:00
|
|
|
$(html).hide().appendTo('#sliders').fadeIn();
|
2012-09-08 12:43:04 +00:00
|
|
|
}
|
|
|
|
$("input").live("change", function(e) {
|
|
|
|
var i = e.target.id.split('_');
|
2018-07-02 02:28:12 +00:00
|
|
|
if(i[0] === 'picker') {
|
|
|
|
var u = {};
|
|
|
|
var tar = $(e.target);
|
|
|
|
var value = rgb_to_array(tar.val());
|
|
|
|
u[Number(i[3])+Number(tar.data('red'))] = value[0];
|
|
|
|
u[Number(i[3])+Number(tar.data('green'))] = value[1];
|
|
|
|
u[Number(i[3])+Number(tar.data('blue'))] = value[2];
|
|
|
|
socket.emit('update', i[2], u);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var u = {};
|
|
|
|
u[i[2]] = e.target.value;
|
|
|
|
socket.emit('update', i[1], u);
|
|
|
|
}
|
2012-09-08 12:43:04 +00:00
|
|
|
});
|
|
|
|
socket.emit('request_refresh');
|
|
|
|
});
|
|
|
|
socket.on('update', function (universe, update) {
|
|
|
|
for(var k in update) {
|
2012-09-17 17:00:24 +00:00
|
|
|
$('#' + get_html_id(universe, k)).attr('value', update[k]);
|
2012-09-08 12:43:04 +00:00
|
|
|
}
|
2018-07-02 02:28:12 +00:00
|
|
|
$("[id^=picker_channel_"+universe+"]").each(function(index, value){
|
|
|
|
var self = $(this);
|
|
|
|
var id = self.attr('id').split('_');
|
|
|
|
var obj = self.data();
|
|
|
|
var arr = Object.keys(obj).map(function(key){return obj[key];});
|
|
|
|
var _id = Number(id[3]);
|
|
|
|
var min = _id;
|
|
|
|
var max = min;
|
|
|
|
min += Math.min.apply( null, arr );
|
|
|
|
max += Math.max.apply( null, arr );
|
|
|
|
for(var k in update) {
|
|
|
|
if(k >= min && k <= max) {
|
|
|
|
var values = rgb_to_array(self.val());
|
|
|
|
var address = k - _id;
|
|
|
|
if(address === Number(self.data('red'))) {
|
|
|
|
values[0] = update[k];
|
|
|
|
}
|
|
|
|
else if(address === Number(self.data('green'))) {
|
|
|
|
values[1] = update[k];
|
|
|
|
}
|
|
|
|
else if(address === Number(self.data('blue'))) {
|
|
|
|
values[2] = update[k];
|
|
|
|
}
|
|
|
|
self.val(array_to_rgb(values));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2012-09-08 12:43:04 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body>
|
2012-09-17 17:00:24 +00:00
|
|
|
<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>
|
2013-11-17 00:41:27 +00:00
|
|
|
<!--<li><a href="#scripts" data-toggle="tab">Scripts</a></li>-->
|
2012-09-17 17:00:24 +00:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
2012-09-08 12:43:04 +00:00
|
|
|
|
2012-09-17 17:00:24 +00:00
|
|
|
<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>
|
2012-09-08 12:43:04 +00:00
|
|
|
</div>
|
|
|
|
</body>
|
2018-07-02 02:28:12 +00:00
|
|
|
</html>
|