-
Notifications
You must be signed in to change notification settings - Fork 0
/
lightctrl.js
64 lines (61 loc) · 1.58 KB
/
lightctrl.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
57
58
59
60
61
62
63
64
var artnet = require('artnet-node');
var Client = function(ip, port){
this.ip = ip;
this.port = port || 6454;
this.client = new artnet.Client.ArtNetClient(this.ip, this.port);
this.client.UNIVERSE = [1,0];
this.dmx_dta = new Array(512);
};
Client.prototype.setChannel = function(channel, value){
this.dmx_dta[channel-1] = value;
};
Client.prototype.flush = function(){
this.client.send(this.dmx_dta);
};
module.exports.DmxClient = Client;
var modes = {
'3_segment' : {
mode : 41,
shutter : 1,
red_l : 2,
green_l : 3,
blue_l : 4,
red_m : 5,
green_m : 6,
blue_m : 7,
red_r : 8,
green_r : 9,
blue_r : 10
},
'1_segment' : {
mode : 81,
shutter : 1,
red : 2,
green : 3,
blue : 4
}
};
module.exports.modes = modes;
var Device = function(client, channel, mode){
this.client = client;
this.channel = channel;
this.mode = mode;
};
Device.prototype.setMode = function(mode){
this.mode = mode;
};
Device.prototype.setVals = function(values, flush){
if(this.mode!=-1)
this.client.setChannel(this.channel, this.mode.mode);
for(key in values){
if(this.mode[key]==undefined){
console.log("key %s not known in current mode.", key);
continue
}
this.client.setChannel(this.channel + this.mode[key], values[key]);
}
if(flush)
this.client.flush();
};
module.exports.Device = Device;
module.exports.Colors = require('./colors.js');