2012-12-28 22:17:47 +00:00
|
|
|
var express = require('express');
|
|
|
|
var app = express();
|
|
|
|
var server = require('http').createServer(app), io = require('socket.io').listen(server);
|
|
|
|
var osc = require('node-osc');
|
2013-01-10 01:18:25 +00:00
|
|
|
var oscMap = require('./oscMap.json');
|
2012-12-28 22:17:47 +00:00
|
|
|
|
2013-01-10 01:18:25 +00:00
|
|
|
var host = process.argv.length > 2 ? process.argv[2] : '192.168.8.101';
|
|
|
|
var port = process.argv.length > 3 ? process.argv[3] : '9000';
|
2012-12-28 22:17:47 +00:00
|
|
|
var oscSender = new osc.Client(host, port);
|
2013-01-10 01:18:25 +00:00
|
|
|
var oscReceiver = new osc.Server(3333, '0.0.0.0');
|
|
|
|
|
|
|
|
var artnetclient = require('./node_modules/artnet/lib/artnet_client');
|
|
|
|
var dmxClient = artnetclient.createClient("192.168.8.255", 6454);
|
|
|
|
|
2012-12-28 22:17:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
var states = [];
|
2013-01-10 01:18:25 +00:00
|
|
|
var dmxData = new Array(512);
|
|
|
|
for(var i=0; i<512;i++) {
|
|
|
|
dmxData[i] = 0;
|
|
|
|
}
|
2012-12-28 22:17:47 +00:00
|
|
|
|
2013-01-10 01:18:25 +00:00
|
|
|
server.listen(8081);
|
2012-12-28 22:17:47 +00:00
|
|
|
app.use(express.static('bootstrap'));
|
|
|
|
|
|
|
|
app.get('/', function (req, res) {
|
2013-01-10 01:18:25 +00:00
|
|
|
res.sendfile(__dirname + '/index.html');
|
2012-12-28 22:17:47 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
io.sockets.on('connection', function (socket) {
|
|
|
|
|
2012-12-28 23:10:43 +00:00
|
|
|
var address = socket.handshake.address;
|
|
|
|
console.log("New connection from " + address.address + ":" + address.port);
|
|
|
|
|
2013-01-10 01:18:25 +00:00
|
|
|
socket.on('oscmessage', function (data) {
|
2012-12-28 22:17:47 +00:00
|
|
|
|
|
|
|
var chan = data.chan;
|
|
|
|
var value = data.val;
|
|
|
|
|
|
|
|
// hier noch nicht einkommentieren, das sendet das sofort ins hackcenter
|
|
|
|
//oscSender.send(chan, value);
|
2013-01-10 01:18:25 +00:00
|
|
|
handleMessage(new Array(chan, value))
|
|
|
|
//console.log(address, chan, value);
|
2012-12-28 22:17:47 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-01-10 01:18:25 +00:00
|
|
|
oscReceiver.on("message", function (msg, rinfo) {
|
|
|
|
handleMessage(msg)
|
|
|
|
});
|
|
|
|
|
|
|
|
function handleMessage(msg) {
|
|
|
|
console.log("Message:");
|
|
|
|
console.log(msg);
|
|
|
|
var chan = msg[0],
|
|
|
|
value = msg[1];
|
|
|
|
|
|
|
|
if(chan == null) return;
|
|
|
|
// sync states array with value
|
|
|
|
if(value == null) {
|
|
|
|
if(states[chan] == null) {
|
|
|
|
states[chan] = 1
|
|
|
|
} else if(states[chan] == 1) {
|
|
|
|
states[chan] = 0;
|
|
|
|
} else if(states[chan] == 0) {
|
|
|
|
states[chan] = 1;
|
|
|
|
}
|
|
|
|
value = states[chan];
|
|
|
|
} else {
|
|
|
|
states[chan] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get mapped dmx channel
|
|
|
|
dmxData[oscMap[chan]] = value*255;
|
|
|
|
dmxClient.send(dmxData);
|
|
|
|
// update osc devices to show the current state
|
|
|
|
// to be done in extra function (with whole states array?)
|
|
|
|
oscSender.send(chan, value);
|
|
|
|
|
|
|
|
}
|