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('null', require('./drivers/null'))
this.registerDriver('enttec-usb-dmx-pro', require('./drivers/enttec-usb-dmx-pro')) 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('enttec-open-usb-dmx', require('./drivers/enttec-open-usb-dmx'))
this.registerDriver('artnet', require('./drivers/artnet'))
} }
util.inherits(DMX, EventEmitter) util.inherits(DMX, EventEmitter)

View file

@ -1,70 +1,65 @@
"use strict" "use strict"
const dgram = require('dgram'); var dgram = require('dgram')
const ARTNET = { function EnttecODE(device_id, options) {
PORT : 6454, var self = this
HOST : "127.0.0.1"
}
function EnttecODE(device_id, cb) { self.header = new Buffer([65, 114, 116, 45, 78, 101, 116, 0, 0, 80, 0, 14])
var self = this 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]); this.universe = new Buffer(512)
self.sequence = self.physical = new Buffer([0]); this.universe.fill(0)
self.length = new Buffer([0x02,0x00]);
cb = cb || function() {} self.sleepTime = 24
this.universe = new Buffer(512)
this.universe.fill(0)
self.sleepTime = 24 options = options || {}
self.timeout self.host = device_id || '127.0.0.1'
self.port = options.port || 6454
self.dev = dgram.createSocket('udp4'); self.dev = dgram.createSocket('udp4')
self.start(); self.start()
// self.dev.bind(6454, function() {
// });
} }
EnttecODE.prototype.send_universe = function() { 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, self.port, self.host)
this.dev.send(pkg, 0, pkg.length, ARTNET.PORT, ARTNET.HOST, function() {
// Package Sent
});
} }
EnttecODE.prototype.start = function() { 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() { EnttecODE.prototype.stop = function() {
clearInterval(this.timeout) clearInterval(this.timeout)
} }
EnttecODE.prototype.close = function(cb) { EnttecODE.prototype.close = function(cb) {
this.stop() this.stop()
this.dev.close(cb) cb(null)
} }
EnttecODE.prototype.update = function(u) { EnttecODE.prototype.update = function(u) {
for (var c in u) { for (var c in u) {
this.universe[c] = u[c] this.universe[c] = u[c]
} }
} }
EnttecODE.prototype.updateAll = function(v) { EnttecODE.prototype.updateAll = function(v) {
for (var i = 0; i < 512; i++) { for (var i = 0; i < 512; i++) {
this.universe[i] = v this.universe[i] = v
} }
} }
EnttecODE.prototype.get = function(c) { EnttecODE.prototype.get = function(c) {
return this.universe[c] return this.universe[c]
} }
module.exports = EnttecODE 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. 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 - 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) #### dmx.addUniverse(name, driver, device_id)
@ -74,6 +76,7 @@ Two Drivers are currently registered by default:
- <code>device_id</code> - Number or Object - <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. 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) #### dmx.update(universe, channels)