basic web interface

This commit is contained in:
Sebastian Wiedenroth 2012-09-08 14:43:04 +02:00
parent 633c125d51
commit 39ed74ddc0
15 changed files with 9154 additions and 38 deletions

57
dmx.js
View file

@ -1,36 +1,25 @@
var drv = require('./drivers/enttec-usb-dmx-pro.js'); var events = require('events')
universe = new drv.init(0); , web = require('./web.js')
universe.update({0: 1, 1: 0}) , setup = require('./setup.js').setup
, devices = require('./devices.js').devices
;
function done() {console.log('DONE')}
var A = require('./anim.js').Anim; var dmx = new events.EventEmitter();
var x = new A(universe)
.add({1: 255, 6: 110, 7: 255, 8: 10}, 1200) dmx.setup = setup;
.delay(1000) dmx.devices = devices;
.add({1: 0}, 600) dmx.drivers = {};
.add({1: 255}, 600)
.add({5: 255, 6: 128}, 1000)
.add({1: 0}, 100) dmx.update = function(universe, update) {
.add({1: 255}, 100) dmx.drivers[universe].update(update);
.add({1: 0}, 200) dmx.emit('update', universe, update);
.add({1: 255}, 200) }
.add({1: 0}, 100)
.add({1: 255}, 100) for(var universe in setup.universes) {
.add({1: 0}) dmx.drivers[universe] = require('./drivers/' + setup.universes[universe].output.driver + '.js').init(setup.universes[universe].output.device);
.delay(50) }
.add({1: 255})
.delay(50)
.add({1: 0}) web.init(dmx);
.delay(50)
.add({1: 255})
.delay(50)
.add({1: 0})
.delay(50)
.add({1: 255})
.delay(50)
.add({1: 0})
.run(done);
var y = new A(universe)
.add({9: 255}, 10000)
.run(done);

View file

@ -24,7 +24,7 @@ exports.init = function(dev_id) {
universe, universe,
Buffer([ENTTEC_PRO_END_OF_MSG]) Buffer([ENTTEC_PRO_END_OF_MSG])
]) ])
console.log(msg) //console.log(msg)
dev.write(msg) dev.write(msg)
dev.write(msg) dev.write(msg)
} }

View file

@ -3,11 +3,17 @@ exports.init = function(dev_id) {
universe.fill(0) universe.fill(0)
this.update = function(u) { this.update = function(u) {
console.log(u); for(var k in u) {
universe[k] = u[k]
}
} }
this.get = function(k) { this.get = function(k) {
return universe[k]; return universe[k];
} }
setInterval(function() {
console.log(universe);
}, 1000);
return this; return this;
} }

78
index.html Normal file
View file

@ -0,0 +1,78 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>DMX Lichtschalter</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<style>
input[type=range] {
-webkit-appearance: slider-vertical;
height: 200px;
width: 60px;
}
.device {
clear: both;
padding-top: 1em;
}
.channel {
text-align: center;
float: left;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.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');
socket.on('init', function (msg) {
$('.container').empty();
setup = msg.setup
devices = msg.devices
for(var universe in setup.universes) {
html = "<div><h1>" + universe + "</h1>";
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>';
html += '<input id="' + html_id + '" type="range" min="0" max="255">'
html += '</div>'
}
html += '</div>'
}
html += "</div>";
$(html).hide().appendTo('.container').fadeIn();
}
$("input").live("change", function(e) {
var i = e.target.id.split('_');
var u = {};
u[i[2]] = e.target.value;
socket.emit('update', i[1], u);
});
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))
}
});
</script>
</head>
<body>
<div class="container">
</div>
</body>
</html>

View file

@ -8,11 +8,11 @@ exports.setup = {
'devices': [ 'devices': [
{ {
'type': 'eurolite-led-bar', 'type': 'eurolite-led-bar',
'address': 1 'address': 0
}, },
{ {
'type': 'eurolite-led-bar', 'type': 'eurolite-led-bar',
'address': 13 'address': 15
} }
] ]
} }

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

5774
static/bootstrap/css/bootstrap.css vendored Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

2027
static/bootstrap/js/bootstrap.js vendored Normal file

File diff suppressed because it is too large Load diff

6
static/bootstrap/js/bootstrap.min.js vendored Normal file

File diff suppressed because one or more lines are too long

78
test.js Normal file
View file

@ -0,0 +1,78 @@
var drv = require('./drivers/enttec-usb-dmx-pro.js');
universe = new drv.init(0);
universe.update({0: 1, 1: 0})
universe.update({15: 1, 16: 255})
universe.update({1: 255, 3: 120, 4: 230, 5: 30, 6: 110, 7: 255, 8: 10, 9: 255, 10: 255, 11: 0})
function done() {console.log('DONE')}
var A = require('./anim.js').Anim;
function green_water(universe, channels, duration) {
var colors = [
[160, 230, 20],
[255, 255, 0],
[110, 255, 10]
]
for(c in channels) {
var r = Math.floor((Math.random()*colors.length))
u = {}
for(var i = 0; i < 3; i++) {
u[channels[c] + i] = colors[r][i];
}
new A(universe).add(u, duration).run()
}
setTimeout(function() {green_water(universe, channels, duration);}, duration * 2);
}
function warp(universe, channel, min, max, duration) {
var a = {}, b = {};
a[channel] = min;
b[channel] = max;
new A(universe).add(a, duration).add(b, duration).run(function() {
warp(universe, channel, min, max, duration);
})
}
warp(universe, 1, 200, 220, 360);
warp(universe, 1+15, 200, 255, 240);
green_water(universe, [3, 6, 9], 4000);
green_water(universe, [3+15, 6+15, 9+15], 4000);
return;
var x = new A(universe)
.add({1: 255, 6: 110, 7: 255, 8: 10}, 1200)
.delay(1000)
.add({1: 0}, 600)
.add({1: 255}, 600)
.add({5: 255, 6: 128}, 1000)
.add({1: 0}, 100)
.add({1: 255}, 100)
.add({1: 0}, 200)
.add({1: 255}, 200)
.add({1: 0}, 100)
.add({1: 255}, 100)
.add({1: 0})
.delay(50)
.add({1: 255})
.delay(50)
.add({1: 0})
.delay(50)
.add({1: 255})
.delay(50)
.add({1: 0})
.delay(50)
.add({1: 255})
.delay(50)
.add({2: 255}, 6000)
.delay(200)
.add({2: 0});
var y = new A(universe)
.add({9: 255}, 10000);
x.run(done);
y.run(done);

82
web.js Normal file
View file

@ -0,0 +1,82 @@
var http = require('http'),
path = require('path'),
io = require('socket.io'),
fs = require('fs')
;
exports.init = function(dmx) {
function handler (request, response) {
var reqBody = '';
request.on("data", function (chunk) {
reqBody += chunk;
});
request.on("end", function () {
var filePath = '.' + request.url;
if (filePath == './')
filePath = './index.html';
var extname = path.extname(filePath);
var contentType = 'text/html';
switch (extname) {
case '.js': contentType = 'text/javascript'; break;
case '.css': contentType = 'text/css'; break;
}
fs.exists(filePath, function(exists) {
if(!exists) {
console.log('404: ' + request.url)
response.writeHead(404);
response.end();
return;
}
fs.readFile(filePath, function(error, content) {
if (error) {
console.log('500: ' + request.url)
response.writeHead(500);
response.end();
return;
}
response.writeHead(200, { 'Content-Type': contentType });
response.end(content, 'utf-8');
});
});
});
}
var app = http.createServer(handler)
app.listen(8080, '::');
io.listen(app).sockets.on('connection', function (socket) {
socket.emit('init', {'devices': dmx.devices, 'setup': dmx.setup});
socket.on('request_refresh', function() {
for(var universe in dmx.setup.universes) {
u = {}
for(var i = 0; i < 256; i++) {
u[i] = dmx.drivers[universe].get(i);
}
console.log('sending update...')
console.log(u)
socket.emit('update', universe, u);
}
});
dmx.on('update', function(universe, update){
socket.emit('update', universe, update);
});
socket.on('update', function(universe, update) {
dmx.update(universe, update);
});
});
}