make bbdmx driver more backwards compatible, adjust style and add it to the readme
This commit is contained in:
parent
faed129329
commit
25adc11f17
2 changed files with 35 additions and 34 deletions
|
@ -1,57 +1,57 @@
|
||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
const dgram = require('dgram');
|
var dgram = require('dgram')
|
||||||
|
|
||||||
function BBDMX(device_id, options) {
|
function BBDMX(device_id, options) {
|
||||||
const self = this;
|
var self = this
|
||||||
self.options = options || {};
|
self.options = options || {}
|
||||||
self.universe = new Buffer(512);
|
self.universe = new Buffer(512)
|
||||||
self.universe.fill(0);
|
self.universe.fill(0)
|
||||||
self.host = device_id || '127.0.0.1';
|
self.host = device_id || '127.0.0.1'
|
||||||
self.port = self.options.port || 9930;
|
self.port = self.options.port || 9930
|
||||||
self.dev = dgram.createSocket('udp4');
|
self.dev = dgram.createSocket('udp4')
|
||||||
self.sleepTime = 24;
|
self.sleepTime = 24
|
||||||
self.start();
|
self.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
BBDMX.prototype.send_universe = function() {
|
BBDMX.prototype.send_universe = function() {
|
||||||
let messageBuffer = new Buffer(this.universe.length.toString());
|
var channel
|
||||||
|
var messageBuffer = new Buffer(this.universe.length.toString())
|
||||||
|
|
||||||
for (let i = 0; i < this.universe.length; i++) {
|
for (var i = 0; i < this.universe.length; i++) {
|
||||||
const channel = new Buffer(' ' + this.universe[i]);
|
channel = new Buffer(' ' + this.universe[i])
|
||||||
const length = channel.length + messageBuffer.length;
|
messageBuffer = Buffer.concat([messageBuffer, channel])
|
||||||
messageBuffer = Buffer.concat([messageBuffer, channel], length);
|
|
||||||
}
|
}
|
||||||
this.dev.send(messageBuffer, 0, messageBuffer.length, this.port, this.host);
|
this.dev.send(messageBuffer, 0, messageBuffer.length, this.port, this.host)
|
||||||
};
|
}
|
||||||
|
|
||||||
BBDMX.prototype.start = function() {
|
BBDMX.prototype.start = function() {
|
||||||
this.timeout = setInterval(this.send_universe.bind(this), this.sleepTime);
|
this.timeout = setInterval(this.send_universe.bind(this), this.sleepTime)
|
||||||
};
|
}
|
||||||
|
|
||||||
BBDMX.prototype.stop = function() {
|
BBDMX.prototype.stop = function() {
|
||||||
clearInterval(this.timeout);
|
clearInterval(this.timeout)
|
||||||
};
|
}
|
||||||
|
|
||||||
BBDMX.prototype.close = function(cb) {
|
BBDMX.prototype.close = function(cb) {
|
||||||
this.stop();
|
this.stop()
|
||||||
cb(null);
|
cb(null)
|
||||||
};
|
};
|
||||||
|
|
||||||
BBDMX.prototype.update = function(u) {
|
BBDMX.prototype.update = function(u) {
|
||||||
for (let c in u) {
|
for (var c in u) {
|
||||||
this.universe[c] = u[c];
|
this.universe[c] = u[c]
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
BBDMX.prototype.updateAll = function(v) {
|
BBDMX.prototype.updateAll = function(v) {
|
||||||
for (let i = 0; i < 512; i++) {
|
for (var i = 0; i < 512; i++) {
|
||||||
this.universe[i] = v;
|
this.universe[i] = v
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
BBDMX.prototype.get = function(c) {
|
BBDMX.prototype.get = function(c) {
|
||||||
return this.universe[c];
|
return this.universe[c]
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports = BBDMX;
|
module.exports = BBDMX
|
||||||
|
|
|
@ -65,10 +65,11 @@ Register a new DMX Driver module by its name.
|
||||||
These drivers are currently registered by default:
|
These drivers are currently registered by default:
|
||||||
|
|
||||||
- null: a development driver that prints the universe to stdout
|
- null: a development driver that prints the universe to stdout
|
||||||
|
- artnet: driver for EnttecODE
|
||||||
|
- bbdmx: driver for [BeagleBone-DMX](https://github.com/boxysean/beaglebone-DMX)
|
||||||
- dmx4all: driver for DMX4ALL devices like the "NanoDMX USB Interface"
|
- dmx4all: driver for DMX4ALL devices like the "NanoDMX USB Interface"
|
||||||
- enttec-usb-dmx-pro: a driver for devices using a Enttec USB DMX Pro chip like the "DMXKing ultraDMX Micro".
|
- enttec-usb-dmx-pro: a driver for devices using a Enttec USB DMX Pro chip like the "DMXKing ultraDMX Micro".
|
||||||
- enttec-open-usb-dmx: driver for "Enttec Open DMX USB". This device is NOT recommended, there are known hardware limitations and this driver is not very stable. (If possible better obtain a device with the "pro" chip)
|
- enttec-open-usb-dmx: driver for "Enttec Open DMX USB". This device is NOT recommended, there are known hardware limitations and this driver is not very stable. (If possible better obtain a device with the "pro" chip)
|
||||||
- artnet: driver for EnttecODE
|
|
||||||
|
|
||||||
#### dmx.addUniverse(name, driver, device_id)
|
#### dmx.addUniverse(name, driver, device_id)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue