forked from magicmonkey/lifxjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli2.js
149 lines (122 loc) · 3.89 KB
/
cli2.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
var lifx = require('./lifx');
var util = require('util');
var step = 100;
var autoCommit = true;
var timing = 0;
var lx = lifx.init();
lx.on('bulbstate', function(b) {
console.log('Bulb state: ' + util.inspect(b));
});
lx.on('bulbonoff', function(b) {
console.log('Bulb on/off: ' + util.inspect(b));
});
lx.on('bulb', function(b) {
console.log('New bulb found: ' + b.name);
});
lx.on('gateway', function(g) {
console.log('New gateway found: ' + g.ipAddress.ip);
});
console.log("Keys:");
console.log("Press 1 to turn the lights on");
console.log("Press 2 to turn the lights off");
console.log("");
console.log("Press q and a to cycle the hue");
console.log("Press w and s to cycle the saturation");
console.log("Press e and d to cycle the luminance");
console.log("Press r and f to cycle the white colour");
console.log("Press enter to send these values to the bulbs");
console.log("");
console.log("Press 6 to make the changes apply immediately");
console.log("Press 7 to make it wait until you hit enter before applying");
console.log("Press 8 to show debug messages including network traffic");
console.log("Press 9 to hide debug messages including network traffic");
//console.log("Press a to request an info update from the lights");
var stdin = process.openStdin();
process.stdin.setRawMode(true);
process.stdin.resume();
var hue = 0;
var sat = 0;
var lum = 0;
var whi = 0;
stdin.on('data', function (key) {
//process.stdout.write('Got key ' + util.inspect(key) + '\n');
switch (key[0]) {
case 0x31: // 1
console.log("Lights on");
lx.lightsOn();
break;
case 0x32: // 2
console.log("Lights off");
lx.lightsOff();
break;
case 0x36: // 6
console.log("Auto commit on");
autoCommit = true;
break;
case 0x37: // 7
console.log("Auto commit off");
autoCommit = false;
break;
case 0x38: // 8
console.log("Debug on");
lifx.setDebug(true);
break;
case 0x39: // 9
console.log("Debug off");
lifx.setDebug(false);
break;
case 0x71: // q
hue = (hue + step) & 0xffff;
console.log("H<" + hue + "> S<" + sat + "> L<" + lum + "> W<" + whi + ">");
if (autoCommit) lx.lightsColour(hue, sat, lum, whi, timing);
break;
case 0x61: // a
hue = (hue - step) & 0xffff;
console.log("H<" + hue + "> S<" + sat + "> L<" + lum + "> W<" + whi + ">");
if (autoCommit) lx.lightsColour(hue, sat, lum, whi, timing);
break;
case 0x77: // w
sat = (sat + step) & 0xffff;
console.log("H<" + hue + "> S<" + sat + "> L<" + lum + "> W<" + whi + ">");
if (autoCommit) lx.lightsColour(hue, sat, lum, whi, timing);
break;
case 0x73: // s
sat = (sat - step) & 0xffff;
console.log("H<" + hue + "> S<" + sat + "> L<" + lum + "> W<" + whi + ">");
if (autoCommit) lx.lightsColour(hue, sat, lum, whi, timing);
break;
case 0x65: // e
lum = (lum + step) & 0xffff;
console.log("H<" + hue + "> S<" + sat + "> L<" + lum + "> W<" + whi + ">");
if (autoCommit) lx.lightsColour(hue, sat, lum, whi, timing);
break;
case 0x64: // d
lum = (lum - step) & 0xffff;
console.log("H<" + hue + "> S<" + sat + "> L<" + lum + "> W<" + whi + ">");
if (autoCommit) lx.lightsColour(hue, sat, lum, whi, timing);
break;
case 0x72: // r
whi = (whi + step) & 0xffff;
console.log("H<" + hue + "> S<" + sat + "> L<" + lum + "> W<" + whi + ">");
if (autoCommit) lx.lightsColour(hue, sat, lum, whi, timing);
break;
case 0x66: // f
whi = (whi - step) & 0xffff;
console.log("H<" + hue + "> S<" + sat + "> L<" + lum + "> W<" + whi + ">");
if (autoCommit) lx.lightsColour(hue, sat, lum, whi, timing);
break;
case 0x67: // g
lx.findBulbs();
break;
case 0x0d: // enter
console.log("Sending H<" + hue + "> S<" + sat + "> L<" + lum + "> W<" + whi + ">");
lx.lightsColour(hue, sat, lum, whi, timing);
break;
case 0x03: // ctrl-c
console.log("Closing...");
lx.close();
process.stdin.pause();
//process.exit();
break;
}
});