From bd28d30c4b1f0fe7742c6b8819664d40f512def9 Mon Sep 17 00:00:00 2001 From: Sebastian Wiedenroth Date: Sat, 9 Apr 2016 18:08:19 +0200 Subject: [PATCH] drop ftdi dependency and replace with "serialport" --- demo.js | 6 +++--- demo_simple.js | 4 ++-- dmx-web-example.conf | 1 + drivers/enttec-open-usb-dmx.js | 28 +++++++++++++++++----------- drivers/enttec-usb-dmx-pro.js | 15 ++++++++------- drivers/null.js | 4 ++-- package.json | 10 +++++----- readme.md | 3 --- 8 files changed, 38 insertions(+), 33 deletions(-) diff --git a/demo.js b/demo.js index a8826e1..64d62d9 100644 --- a/demo.js +++ b/demo.js @@ -5,8 +5,8 @@ var A = DMX.Animation var dmx = new DMX() -// var universe = dmx.addUniverse('demo', 'enttec-usb-dmx-pro', 0) -// var universe = dmx.addUniverse('demo', 'enttec-open-usb-dmx', 0) +// var universe = dmx.addUniverse('demo', 'enttec-usb-dmx-pro', '/dev/cu.usbserial-6AVNHXS8') +// var universe = dmx.addUniverse('demo', 'enttec-open-usb-dmx', '/dev/cu.usbserial-6AVNHXS8') var universe = dmx.addUniverse('demo', 'null') universe.update({0: 1, 1: 0}) @@ -82,4 +82,4 @@ var y = new A() .add({9: 255}, 10000) x.run(universe, done) -y.run(universe, done) \ No newline at end of file +y.run(universe, done) diff --git a/demo_simple.js b/demo_simple.js index 4a31edd..3c345f7 100644 --- a/demo_simple.js +++ b/demo_simple.js @@ -4,7 +4,7 @@ var DMX = require('./dmx'); var A = DMX.Animation; var dmx = new DMX(); -// var universe = dmx.addUniverse('demo', 'enttec-open-usb-dmx', 0) +// var universe = dmx.addUniverse('demo', 'enttec-open-usb-dmx', '/dev/cu.usbserial-6AVNHXS8') var universe = dmx.addUniverse('demo', 'null') var on = false; @@ -18,4 +18,4 @@ setInterval(function(){ universe.updateAll(250); console.log("on"); } -}, 1000); \ No newline at end of file +}, 1000); diff --git a/dmx-web-example.conf b/dmx-web-example.conf index 35ff63f..f470862 100644 --- a/dmx-web-example.conf +++ b/dmx-web-example.conf @@ -43,6 +43,7 @@ module.exports = { 'office': { 'output': { // 'driver': 'enttec-usb-dmx-pro', + // 'device': '/dev/cu.usbserial-6AVNHXS8' 'driver': 'null', 'device': 0 }, diff --git a/drivers/enttec-open-usb-dmx.js b/drivers/enttec-open-usb-dmx.js index 40d24e8..eef2fd7 100644 --- a/drivers/enttec-open-usb-dmx.js +++ b/drivers/enttec-open-usb-dmx.js @@ -1,25 +1,22 @@ "use strict" -var FTDI = require('ftdi') +var SerialPort = require("serialport").SerialPort -function EnttecOpenUsbDMX(device_id, cb) { +function EnttecOpenUsbDMX(device_id, options) { var self = this + options = options || {} - cb = cb || function() {} this.universe = new Buffer(512) this.universe.fill(0) - self.sleepTime = 24 - self.timeout + self.interval = 23 - self.dev = new FTDI.FtdiDevice(device_id) - self.dev.open({ + this.dev = new SerialPort(device_id, { 'baudrate': 57600, 'databits': 8, 'stopbits': 2, 'parity': 'none' - }, function(err) { - cb(err, device_id) + }, true, function(err) { if(!err) { self.start() } @@ -27,15 +24,24 @@ function EnttecOpenUsbDMX(device_id, cb) { } EnttecOpenUsbDMX.prototype.send_universe = function() { + if(!this.dev.isOpen()) { + return + } + this.dev.write(this.universe) + + // toggle break + this.dev.set({brk: true}, function(err, r) { + this.dev.set({brk: false}) + }) } EnttecOpenUsbDMX.prototype.start = function() { - this.timeout = setInterval(this.send_universe.bind(this), this.sleepTime) + this.interval = setInterval(this.send_universe.bind(this), this.sleepTime) } EnttecOpenUsbDMX.prototype.stop = function() { - clearInterval(this.timeout) + clearInterval(this.interval) } EnttecOpenUsbDMX.prototype.close = function(cb) { diff --git a/drivers/enttec-usb-dmx-pro.js b/drivers/enttec-usb-dmx-pro.js index 0d8a160..2dabcf9 100644 --- a/drivers/enttec-usb-dmx-pro.js +++ b/drivers/enttec-usb-dmx-pro.js @@ -1,6 +1,6 @@ "use strict" -var FTDI = require('ftdi') +var SerialPort = require("serialport").SerialPort var ENTTEC_PRO_DMX_STARTCODE = 0x00 , ENTTEC_PRO_START_OF_MSG = 0x7e @@ -9,20 +9,18 @@ var ENTTEC_PRO_DMX_STARTCODE = 0x00 , ENTTEC_PRO_RECV_DMX_PKT = 0x05 ; -function EnttecUSBDMXPRO(device_id, cb) { +function EnttecUSBDMXPRO(device_id, options) { var self = this - cb = cb || function() {} + options = options || {} this.universe = new Buffer(512) this.universe.fill(0) - this.dev = new FTDI.FtdiDevice(device_id) - this.dev.open({ + this.dev = new SerialPort(device_id, { 'baudrate': 250000, 'databits': 8, 'stopbits': 2, 'parity': 'none' - }, function(err) { - cb(err, device_id) + }, true, function(err) { if(!err) { self.send_universe() } @@ -30,6 +28,9 @@ function EnttecUSBDMXPRO(device_id, cb) { } EnttecUSBDMXPRO.prototype.send_universe = function() { + if(!this.dev.isOpen()) { + return + } var hdr = Buffer([ ENTTEC_PRO_START_OF_MSG, ENTTEC_PRO_SEND_DMX_RQ, diff --git a/drivers/null.js b/drivers/null.js index 4b3c2ba..9165f01 100644 --- a/drivers/null.js +++ b/drivers/null.js @@ -1,8 +1,8 @@ "use strict" -function Null(device_id, cb) { +function Null(device_id, options) { var self = this - cb = cb || function() {} + options = options || {} this.universe = new Buffer(512) this.universe.fill(0) self.start() diff --git a/package.json b/package.json index 43b5afa..354a665 100644 --- a/package.json +++ b/package.json @@ -17,11 +17,11 @@ "light control" ], "dependencies": { - "ftdi": "1.0.x", - "socket.io": "0.9.x", - "connect": "2.11.x", - "express": "3.4.x", - "commander": "2.0.x" + "serialport": "2.0.x", + "socket.io": "0.9.x", + "connect": "2.11.x", + "express": "3.4.x", + "commander": "2.0.x" }, "licenses": [ { diff --git a/readme.md b/readme.md index 69ed66d..fd7e76f 100644 --- a/readme.md +++ b/readme.md @@ -4,9 +4,6 @@ DMX-512 controller library for node.js - also includes a Webinterface and HTTP A ## Install - # ftdi module requires ftd2xx headers provided by libftdxx1 - # install info here: https://github.com/KABA-CCEAC/node-ftdi#prerequisites - # install script here: https://github.com/KABA-CCEAC/node-ftdi/blob/master/install.sh npm install -g dmx ## Webinterface