-
Notifications
You must be signed in to change notification settings - Fork 0
/
pcLamp.js
112 lines (96 loc) · 2.81 KB
/
pcLamp.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
/********************************************************************
* Lamp mock for the non raspberry pi compatible computers.
*******************************************************************/
function Lamp() {
var intervalRed, intervalOrange, intervalGreen,
ledRed, ledOrange, ledGreen;
};
function Led(name, state, color) {
var name, state, color;
this.name = name;
this.state = state;
this.color = color;
};
Led.prototype.toString = function() {
return 'Led: name=' + this.name + ' state=' + this.state;
}
Led.prototype.info = function() {
console.log('The led ' + this.name + ' has the state ' + this.state);
}
Led.prototype.disable = function() {
this.state = 0;
}
Led.prototype.printLed = function() {
if(this.state === 0) {
console.log(' |○ |');
} else {
console.log(this.color, '|◉ |', '\x1b[0m');
}
}
Lamp.prototype.startup = function() {
this.ledRed = new Led('red', 0, '\x1b[31m');
this.ledOrange = new Led('orange', 0, '\x1b[33m');
this.ledGreen = new Led('green', 1, '\x1b[32m');
};
Lamp.prototype.shutdown = function() {
//this.disableAll();
};
Lamp.prototype.enableRed = function() {
// console.log('>>> enableRed');
// enableLed(this.ledRed, this.intervalRed);
}
Lamp.prototype.enableOrange = function() {
// console.log('>>> enableOrange');
// enableLed(this.ledOrange, this.intervalOrange);
}
Lamp.prototype.enableGreen = function() {
// console.log('>>> enableGreen');
// enableLed(this.ledGreen, this.intervalGreen);
}
Lamp.prototype.blinkRed = function() {
//blinkLed(this.ledRed, this.intervalRed);
}
Lamp.prototype.blinkOrange = function() {
//blinkLed(this.ledOrange, this.intervalOrange);
}
Lamp.prototype.blinkGreen = function() {
//blinkLed(this.ledGreen, this.intervalGreen);
}
Lamp.prototype.disableRed = function() {
//disableLed(this.ledRed, this.intervalRed);
}
Lamp.prototype.disableOrange = function() {
//disableLed(this.ledOrange, this.intervalOrange);
}
Lamp.prototype.disableGreen = function() {
//disableLed(this.ledGreen, this.intervalGreen);
}
Lamp.prototype.disableAll = function() {
disableLed(this.ledRed, this.intervalRed);
disableLed(this.ledOrange, this.intervalOrange);
disableLed(this.ledGreen, this.intervalGreen);
}
function enableLed(led, interval) {
clearInterval(interval);
led.state = 1;
led.printLed();
}
function blinkLed(led, interval) {
disableLed(led, interval);
interval = setInterval(function() {
var value = (led.state + 1) % 2;
if (value == 0) {
led.state = 0;
} else {
led.state = 1;
}
led.printLed();
}, 2000);
}
function disableLed(led, interval) {
clearInterval(interval);
led.state = 0;
led.printLed();
}
// export the class
module.exports = Lamp;