Add BeagleBone-DMX driver

This commit is contained in:
Moritz Hoffmann 2016-11-18 02:46:39 +01:00
parent 9a1ee28ec3
commit 7be968808e
2 changed files with 62 additions and 0 deletions

1
dmx.js
View file

@ -14,6 +14,7 @@ function DMX(options) {
this.registerDriver('enttec-usb-dmx-pro', require('./drivers/enttec-usb-dmx-pro'))
this.registerDriver('enttec-open-usb-dmx', require('./drivers/enttec-open-usb-dmx'))
this.registerDriver('artnet', require('./drivers/artnet'))
this.registerDriver('bbdmx', require('./drivers/bbdmx'))
}
util.inherits(DMX, EventEmitter)

61
drivers/bbdmx.js Normal file
View file

@ -0,0 +1,61 @@
'use strict';
const dgram = require('dgram');
function BBDMX(device_id, options) {
const self = this;
self.options = options || {};
self.universe = new Buffer(512);
self.universe.fill(0);
self.host = device_id || '127.0.0.1';
if (typeof options === 'undefined') {
self.port = 9930;
} else {
self.port = options.port || 9930;
}
self.dev = dgram.createSocket('udp4');
self.sleepTime = 24;
self.start();
}
BBDMX.prototype.send_universe = function() {
let messageBuffer = new Buffer(`${this.universe.length} `);
for (let i = 0; i < this.universe.length; i++) {
const channel = new Buffer(`${this.universe[i]} `);
const length = channel.length + messageBuffer.length;
messageBuffer = Buffer.concat([messageBuffer, channel], length);
}
this.dev.send(messageBuffer, 0, messageBuffer.length, this.port, this.host);
};
BBDMX.prototype.start = function() {
this.timeout = setInterval(this.send_universe.bind(this), this.sleepTime);
};
BBDMX.prototype.stop = function() {
clearInterval(this.timeout);
};
BBDMX.prototype.close = function(cb) {
this.stop();
cb(null);
};
BBDMX.prototype.update = function(u) {
for (let c in u) {
this.universe[c] = u[c];
}
};
BBDMX.prototype.updateAll = function(v) {
for (let i = 0; i < 512; i++) {
this.universe[i] = v;
}
};
BBDMX.prototype.get = function(c) {
return this.universe[c];
};
module.exports = BBDMX;