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 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)
y.run(universe, done)

View file

@ -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);
}, 1000);

View file

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

View file

@ -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) {

View file

@ -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,

View file

@ -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()

View file

@ -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": [
{

View file

@ -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