-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmshell.js
92 lines (86 loc) · 1.93 KB
/
mshell.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
'use strict';
var mb=require('./milight.js');
mb.initiate("10.1.1.2","5987");
var baseCtl=mb.baseCtlFactory();
var zone1Ctl=mb.zoneCtlRGBWFactory(0x01);
var readline = require('readline'),
rl = readline.createInterface(process.stdin, process.stdout),
prefix = 'OHAI> ';
var cmd;
rl.on('line', function(line) {
switch(line.trim()) {
case 'hello':
console.log('world!');
break;
case 'zone1 on':
cmd=zone1Ctl.on();
break;
case 'zone1 off':
cmd=zone1Ctl.off();
break;
case 'zone1 white':
cmd=zone1Ctl.whiteMode();
break;
case 'zone1 brighter':
cmd=zone1Ctl.brightnessUp();
break;
case 'zone1 dimmer':
cmd=zone1Ctl.brightnessDown();
//var nFrame=buildFrame(bridgeID,zone1Ctl.brightnessDown(),0x01);
//sendFrame(nFrame);
break;
case 'zone1 colorUp':
cmd=zone1Ctl.colorUp();
break;
case 'zone1 colorDown':
cmd=zone1Ctl.colorDown();
break;
case 'zone1 mode1':
cmd=zone1Ctl.mode(1);
break;
case 'zone1 mode2':
cmd=zone1Ctl.mode(2);
break;
case 'base on':
cmd=baseCtl.on();
break;
case 'base off':
cmd=baseCtl.off();
break;
case 'base white':
cmd=baseCtl.whiteMode();
break;
case 'base brighter':
cmd=baseCtl.brightnessUp();
break;
case 'base dimmer':
cmd=baseCtl.brightnessDown();
//var nFrame=buildFrame(bridgeID,baseCtl.brightnessDown(),0x01);
//sendFrame(nFrame);
break;
case 'base colorUp':
cmd=baseCtl.colorUp();
break;
case 'base colorDown':
cmd=baseCtl.colorDown();
break;
case 'base mode1':
cmd=baseCtl.mode(1);
break;
case 'base mode2':
cmd=baseCtl.mode(2);
break;
default:
console.log('Say what? I might have heard `' + line.trim() + '`');
break;
}
mb.sendCmd(cmd);
rl.setPrompt(prefix, prefix.length);
rl.prompt();
}).on('close', function() {
console.log('Have a great day!');
process.exit(0);
});
console.log(prefix + 'Good to see you. Try typing stuff.');
rl.setPrompt(prefix, prefix.length);
rl.prompt();