forked from blechdom/node-red-contrib-dmxusbpro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdmxusbpro.js
32 lines (30 loc) · 1.09 KB
/
dmxusbpro.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module.exports = function(RED) {
"use strict";
var DMX = require('./dmxusbpro_driver.js');
function DMXout(n) {
RED.nodes.createNode(this,n);
var node = this;
this.port = n.port || "COM3";
this.DMX_offset = n.DMX_starting_address || 1;
var current_universe_buffer = new Buffer(512);
console.log("this in DMXout: " + JSON.stringify(this));
var current_universe = [];
for (var i = 0; i<512; i++){
current_universe[i] = 0;
}
current_universe_buffer = Buffer(current_universe);
var dmx_usb_pro = new DMX(this.port, current_universe_buffer);
this.on("input",function(msg) {
current_universe = msg.payload;
dmx_usb_pro.update(current_universe, this.DMX_offset);
node.send(current_universe);
});
this.on('close', function(done) {
dmx_usb_pro.close(function (err) {
console.log('dmxusbpro closed', err);
done();
});
});
}
RED.nodes.registerType("dmxusbpro",DMXout);
}