From ae6c017ff934c8a730c87d506631d310f39199c7 Mon Sep 17 00:00:00 2001 From: Sebastian Wiedenroth Date: Sat, 12 Nov 2016 17:31:45 +0100 Subject: [PATCH] add DMX4ALL (NanoDMX USB) driver --- dmx.js | 1 + drivers/dmx4all.js | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 drivers/dmx4all.js diff --git a/dmx.js b/dmx.js index 2430e84..921e17e 100644 --- a/dmx.js +++ b/dmx.js @@ -10,6 +10,7 @@ function DMX(options) { this.devices = options.devices || require('./devices') this.registerDriver('null', require('./drivers/null')) + this.registerDriver('dmx4all', require('./drivers/dmx4all')) 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')) diff --git a/drivers/dmx4all.js b/drivers/dmx4all.js new file mode 100644 index 0000000..25ab6a2 --- /dev/null +++ b/drivers/dmx4all.js @@ -0,0 +1,65 @@ +"use strict" + +var SerialPort = require("serialport") + +function DMX4ALL(device_id, options) { + var self = this + options = options || {} + this.universe = new Buffer(512) + this.universe.fill(0) + + this.dev = new SerialPort(device_id, { + 'baudrate': 38400, + 'databits': 8, + 'stopbits': 1, + 'parity': 'none' + }, function(err) { + if(!err) { + self.send_universe() + } + }) + this.dev.on('data', function(data) { + //process.stdout.write(data.toString('ascii')) + }) +} + +DMX4ALL.prototype.send_universe = function() { + if(!this.dev.isOpen()) { + return + } + + var msg = Buffer(this.universe.length * 3) + for(var i = 0; i < this.universe.length; i++) { + msg[i * 3 + 0] = (i < 256) ? 0xE2 : 0xE3 + msg[i * 3 + 1] = i + msg[i * 3 + 2] = this.universe[i] + } + this.dev.write(msg) +} + +DMX4ALL.prototype.start = function() {} +DMX4ALL.prototype.stop = function() {} + +DMX4ALL.prototype.close = function(cb) { + this.dev.close(cb) +} + +DMX4ALL.prototype.update = function(u) { + for(var c in u) { + this.universe[c] = u[c] + } + this.send_universe() +} + +DMX4ALL.prototype.updateAll = function(v){ + for(var i = 0; i < 512; i++) { + this.universe[i] = v + } + this.send_universe() +} + +DMX4ALL.prototype.get = function(c) { + return this.universe[c] +} + +module.exports = DMX4ALL \ No newline at end of file