register artnet driver by default and adjust style a bit

This commit is contained in:
Sebastian Wiedenroth 2016-04-09 18:35:33 +02:00
parent 7c95c4eaec
commit 9a34f3de30
3 changed files with 39 additions and 40 deletions

1
dmx.js
View file

@ -12,6 +12,7 @@ function DMX(options) {
this.registerDriver('null', require('./drivers/null'))
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'))
}
util.inherits(DMX, EventEmitter)

View file

@ -1,70 +1,65 @@
"use strict"
const dgram = require('dgram');
var dgram = require('dgram')
const ARTNET = {
PORT : 6454,
HOST : "127.0.0.1"
}
function EnttecODE(device_id, options) {
var self = this
function EnttecODE(device_id, cb) {
var self = this
self.header = new Buffer([65, 114, 116, 45, 78, 101, 116, 0, 0, 80, 0, 14])
self.sequence = self.physical = new Buffer([0])
self.length = new Buffer([0x02,0x00])
self.header = new Buffer([65, 114, 116, 45, 78, 101, 116, 0, 0, 80, 0, 14]);
self.sequence = self.physical = new Buffer([0]);
self.length = new Buffer([0x02,0x00]);
this.universe = new Buffer(512)
this.universe.fill(0)
cb = cb || function() {}
this.universe = new Buffer(512)
this.universe.fill(0)
self.sleepTime = 24
self.sleepTime = 24
self.timeout
self.dev = dgram.createSocket('udp4');
self.start();
// self.dev.bind(6454, function() {
// });
options = options || {}
self.host = device_id || '127.0.0.1'
self.port = options.port || 6454
self.dev = dgram.createSocket('udp4')
self.start()
}
EnttecODE.prototype.send_universe = function() {
var pkg = Buffer.concat([
this.header,
this.sequence,
this.physical,
this.length,
this.universe
])
var pkg = Buffer.concat([this.header, this.sequence, this.physical,this.length,this.universe]);
this.dev.send(pkg, 0, pkg.length, ARTNET.PORT, ARTNET.HOST, function() {
// Package Sent
});
this.dev.send(pkg, 0, pkg.length, self.port, self.host)
}
EnttecODE.prototype.start = function() {
this.timeout = setInterval(this.send_universe.bind(this), this.sleepTime)
this.timeout = setInterval(this.send_universe.bind(this), this.sleepTime)
}
EnttecODE.prototype.stop = function() {
clearInterval(this.timeout)
clearInterval(this.timeout)
}
EnttecODE.prototype.close = function(cb) {
this.stop()
this.dev.close(cb)
this.stop()
cb(null)
}
EnttecODE.prototype.update = function(u) {
for (var c in u) {
this.universe[c] = u[c]
}
for (var c in u) {
this.universe[c] = u[c]
}
}
EnttecODE.prototype.updateAll = function(v) {
for (var i = 0; i < 512; i++) {
this.universe[i] = v
}
for (var i = 0; i < 512; i++) {
this.universe[i] = v
}
}
EnttecODE.prototype.get = function(c) {
return this.universe[c]
return this.universe[c]
}
module.exports = EnttecODE

View file

@ -62,10 +62,12 @@ Create a new DMX instance. This class is used to tie multiple universes together
Register a new DMX Driver module by its name.
Two Drivers are currently registered by default:
These drivers are currently registered by default:
- null: a development driver that prints the universe to stdout
- enttec-usb-dmx-pro: a driver for devices using a Enttec USB DMX Pro chip like the "DMXKing ultraDMX Micro". This driver requires the ftdi module (<https://github.com/KABA-CCEAC/node-ftdi>)
- 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 driver has not received enough testing and the hardware has known limitations. (If possible better obtain a device with the "pro" chip)
- artnet: driver for EnttecODE
#### dmx.addUniverse(name, driver, device_id)
@ -74,6 +76,7 @@ Two Drivers are currently registered by default:
- <code>device_id</code> - Number or Object
Add a new DMX Universe with a name, driver and an optional device_id used by the driver to identify the device.
For enttec-usb-dmx-pro and enttec-open-usb-dmx device_id is the path the the serial device. For artnet it is the target ip.
#### dmx.update(universe, channels)