similarize drivers, needs more testing

This commit is contained in:
Sebastian Wiedenroth 2015-05-15 14:34:24 +02:00
parent 0fd0a626c2
commit 14f33da4dc
3 changed files with 67 additions and 56 deletions

View file

@ -2,77 +2,61 @@
var FTDI = require('ftdi')
function EnttecOpenUsbDMX(locationId, cb) {
var self = this;
function EnttecOpenUsbDMX(device_id, cb) {
var self = this
cb = cb || function() {}
self.universe = Array(513);
self.universe[0] = 0;
self.updateAll(0);
self.sleepTime = 24;
self.timeout;
self.dev = new FTDI.FtdiDevice(locationId)
this.universe = new Buffer(512)
this.universe.fill(0)
self.sleepTime = 24
self.timeout
self.dev = new FTDI.FtdiDevice(device_id)
self.dev.open({
'baudrate': 115200 / 2,
'baudrate': 57600,
'databits': 8,
'stopbits': 2,
'parity': 'none'
}, function(err) {
cb(err, locationId)
cb(err, device_id)
if(!err) {
self.loopUniverse()
self.start()
}
})
}
EnttecOpenUsbDMX.prototype.loopUniverse = function(){
var self = this;
clearTimeout(self.timeout);
self.dev.write(self.universe);
self.timeout = setTimeout(function(){
self.loopUniverse();
}, self.sleepTime)
EnttecOpenUsbDMX.prototype.send_universe = function() {
this.dev.write(this.universe)
}
EnttecOpenUsbDMX.prototype.pause = function(){
var self = this;
EnttecOpenUsbDMX.prototype.start = function() {
this.timeout = setInterval(this.send_universe.bind(this), this.sleepTime)
}
clearTimeout(self.timeout);
EnttecOpenUsbDMX.prototype.stop = function() {
clearInterval(this.timeout)
}
EnttecOpenUsbDMX.prototype.close = function(cb) {
var self = this;
self.pause();
self.dev.close(function(err){
cb(err)
})
this.stop()
this.dev.close(cb)
}
EnttecOpenUsbDMX.prototype.update = function(u) {
var self = this;
for(var c in u) {
self.universe[(c + 1)] = u[c];
this.universe[c] = u[c]
}
}
EnttecOpenUsbDMX.prototype.updateAll = function(v) {
var self = this;
var i = 1;
while(i < self.universe.length){
self.universe[i] = v;
i++;
for(var i = 0; i < 512; i++) {
this.universe[i] = v
}
}
EnttecOpenUsbDMX.prototype.get = function(c) {
var self = this;
return self.universe[(c + 1)];
return this.universe[c]
}
module.exports = EnttecOpenUsbDMX

View file

@ -46,6 +46,13 @@ EnttecUSBDMXPRO.prototype.send_universe = function() {
this.dev.write(msg)
}
EnttecUSBDMXPRO.prototype.start = function() {}
EnttecUSBDMXPRO.prototype.stop = function() {}
EnttecUSBDMXPRO.prototype.close = function(cb) {
this.dev.close(cb)
}
EnttecUSBDMXPRO.prototype.update = function(u) {
for(var c in u) {
this.universe[c] = u[c]
@ -54,7 +61,9 @@ EnttecUSBDMXPRO.prototype.update = function(u) {
}
EnttecUSBDMXPRO.prototype.updateAll = function(v){
// TODO
for(var i = 0; i < 512; i++) {
this.universe[i] = v
}
}
EnttecUSBDMXPRO.prototype.get = function(c) {

View file

@ -5,6 +5,22 @@ function Null(device_id, cb) {
cb = cb || function() {}
this.universe = new Buffer(512)
this.universe.fill(0)
self.start()
}
Null.prototype.start = function() {
var self = this
self.timeout = setInterval(function() {
console.log(self.universe)
}, 1000)
}
Null.prototype.stop = function() {
clearInterval(this.timeout)
}
Null.prototype.close = function(cb) {
cb(null)
}
Null.prototype.update = function(u) {
@ -15,7 +31,9 @@ Null.prototype.update = function(u) {
}
Null.prototype.updateAll = function(v){
// TODO
for(var i = 0; i < 512; i++) {
this.universe[i] = v
}
}
Null.prototype.get = function(c) {