drop ftdi dependency and replace with "serialport"

This commit is contained in:
Sebastian Wiedenroth 2016-04-09 18:08:19 +02:00
parent cd48f76ef3
commit bd28d30c4b
8 changed files with 38 additions and 33 deletions

View file

@ -5,8 +5,8 @@ var A = DMX.Animation
var dmx = new DMX() var dmx = new DMX()
// var universe = dmx.addUniverse('demo', 'enttec-usb-dmx-pro', 0) // var universe = dmx.addUniverse('demo', 'enttec-usb-dmx-pro', '/dev/cu.usbserial-6AVNHXS8')
// 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 universe = dmx.addUniverse('demo', 'null')
universe.update({0: 1, 1: 0}) universe.update({0: 1, 1: 0})
@ -82,4 +82,4 @@ var y = new A()
.add({9: 255}, 10000) .add({9: 255}, 10000)
x.run(universe, done) x.run(universe, done)
y.run(universe, done) y.run(universe, done)

View file

@ -4,7 +4,7 @@ var DMX = require('./dmx');
var A = DMX.Animation; var A = DMX.Animation;
var dmx = new DMX(); 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 universe = dmx.addUniverse('demo', 'null')
var on = false; var on = false;
@ -18,4 +18,4 @@ setInterval(function(){
universe.updateAll(250); universe.updateAll(250);
console.log("on"); console.log("on");
} }
}, 1000); }, 1000);

View file

@ -43,6 +43,7 @@ module.exports = {
'office': { 'office': {
'output': { 'output': {
// 'driver': 'enttec-usb-dmx-pro', // 'driver': 'enttec-usb-dmx-pro',
// 'device': '/dev/cu.usbserial-6AVNHXS8'
'driver': 'null', 'driver': 'null',
'device': 0 'device': 0
}, },

View file

@ -1,25 +1,22 @@
"use strict" "use strict"
var FTDI = require('ftdi') var SerialPort = require("serialport").SerialPort
function EnttecOpenUsbDMX(device_id, cb) { function EnttecOpenUsbDMX(device_id, options) {
var self = this var self = this
options = options || {}
cb = cb || function() {}
this.universe = new Buffer(512) this.universe = new Buffer(512)
this.universe.fill(0) this.universe.fill(0)
self.sleepTime = 24 self.interval = 23
self.timeout
self.dev = new FTDI.FtdiDevice(device_id) this.dev = new SerialPort(device_id, {
self.dev.open({
'baudrate': 57600, 'baudrate': 57600,
'databits': 8, 'databits': 8,
'stopbits': 2, 'stopbits': 2,
'parity': 'none' 'parity': 'none'
}, function(err) { }, true, function(err) {
cb(err, device_id)
if(!err) { if(!err) {
self.start() self.start()
} }
@ -27,15 +24,24 @@ function EnttecOpenUsbDMX(device_id, cb) {
} }
EnttecOpenUsbDMX.prototype.send_universe = function() { EnttecOpenUsbDMX.prototype.send_universe = function() {
if(!this.dev.isOpen()) {
return
}
this.dev.write(this.universe) this.dev.write(this.universe)
// toggle break
this.dev.set({brk: true}, function(err, r) {
this.dev.set({brk: false})
})
} }
EnttecOpenUsbDMX.prototype.start = function() { 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() { EnttecOpenUsbDMX.prototype.stop = function() {
clearInterval(this.timeout) clearInterval(this.interval)
} }
EnttecOpenUsbDMX.prototype.close = function(cb) { EnttecOpenUsbDMX.prototype.close = function(cb) {

View file

@ -1,6 +1,6 @@
"use strict" "use strict"
var FTDI = require('ftdi') var SerialPort = require("serialport").SerialPort
var ENTTEC_PRO_DMX_STARTCODE = 0x00 var ENTTEC_PRO_DMX_STARTCODE = 0x00
, ENTTEC_PRO_START_OF_MSG = 0x7e , ENTTEC_PRO_START_OF_MSG = 0x7e
@ -9,20 +9,18 @@ var ENTTEC_PRO_DMX_STARTCODE = 0x00
, ENTTEC_PRO_RECV_DMX_PKT = 0x05 , ENTTEC_PRO_RECV_DMX_PKT = 0x05
; ;
function EnttecUSBDMXPRO(device_id, cb) { function EnttecUSBDMXPRO(device_id, options) {
var self = this var self = this
cb = cb || function() {} options = options || {}
this.universe = new Buffer(512) this.universe = new Buffer(512)
this.universe.fill(0) this.universe.fill(0)
this.dev = new FTDI.FtdiDevice(device_id) this.dev = new SerialPort(device_id, {
this.dev.open({
'baudrate': 250000, 'baudrate': 250000,
'databits': 8, 'databits': 8,
'stopbits': 2, 'stopbits': 2,
'parity': 'none' 'parity': 'none'
}, function(err) { }, true, function(err) {
cb(err, device_id)
if(!err) { if(!err) {
self.send_universe() self.send_universe()
} }
@ -30,6 +28,9 @@ function EnttecUSBDMXPRO(device_id, cb) {
} }
EnttecUSBDMXPRO.prototype.send_universe = function() { EnttecUSBDMXPRO.prototype.send_universe = function() {
if(!this.dev.isOpen()) {
return
}
var hdr = Buffer([ var hdr = Buffer([
ENTTEC_PRO_START_OF_MSG, ENTTEC_PRO_START_OF_MSG,
ENTTEC_PRO_SEND_DMX_RQ, ENTTEC_PRO_SEND_DMX_RQ,

View file

@ -1,8 +1,8 @@
"use strict" "use strict"
function Null(device_id, cb) { function Null(device_id, options) {
var self = this var self = this
cb = cb || function() {} options = options || {}
this.universe = new Buffer(512) this.universe = new Buffer(512)
this.universe.fill(0) this.universe.fill(0)
self.start() self.start()

View file

@ -17,11 +17,11 @@
"light control" "light control"
], ],
"dependencies": { "dependencies": {
"ftdi": "1.0.x", "serialport": "2.0.x",
"socket.io": "0.9.x", "socket.io": "0.9.x",
"connect": "2.11.x", "connect": "2.11.x",
"express": "3.4.x", "express": "3.4.x",
"commander": "2.0.x" "commander": "2.0.x"
}, },
"licenses": [ "licenses": [
{ {

View file

@ -4,9 +4,6 @@ DMX-512 controller library for node.js - also includes a Webinterface and HTTP A
## Install ## 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 npm install -g dmx
## Webinterface ## Webinterface