forked from rawcreative/node-e131
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctrl.js
56 lines (43 loc) · 1.26 KB
/
ctrl.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var e131 = require('./main.js');
var Controller = function(ip, universe, channels, name) {
this.client = e131.createClient(ip, 5568, universe, name);
this.client.UNIVERSE = universe;
this.channels = channels;
this.dmxData = new Array(channels);
}
Controller.prototype.setChannel = function(channel, value) {
this.dmxData[channel - 1] = value;
};
Controller.prototype.setUniverse = function(universeData) {
this.dmxData = universeData;
};
Controller.prototype.send = function(master) {
var masterised = this.dmxData.map(function(x) {return x * master});
this.client.send(masterised);
};
Controller.prototype.close = function() {
this.client.close();
};
module.exports.Controller = Controller;
var Pixel = function(controller, startChannel) {
this.map = {
red: 0,
green: 1,
blue: 2
};
this.controller = controller;
for (key in this.map) {
this[key] = startChannel + this.map[key];
}
};
Pixel.prototype.setVals = function(values) {
for (key in this.map) {
this.controller.setChannel(this[key], values[key]);
}
};
Pixel.prototype.setAll = function(value) {
for (key in this.map) {
this.controller.setChannel(this[key], value);
}
};
module.exports.Pixel = Pixel;