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

View file

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

View file

@ -5,6 +5,22 @@ function Null(device_id, cb) {
cb = cb || function() {} cb = cb || function() {}
this.universe = new Buffer(512) this.universe = new Buffer(512)
this.universe.fill(0) 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) { Null.prototype.update = function(u) {
@ -15,7 +31,9 @@ Null.prototype.update = function(u) {
} }
Null.prototype.updateAll = function(v){ Null.prototype.updateAll = function(v){
// TODO for(var i = 0; i < 512; i++) {
this.universe[i] = v
}
} }
Null.prototype.get = function(c) { Null.prototype.get = function(c) {