-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeater.js
113 lines (88 loc) · 2.05 KB
/
Heater.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
/**
* Created by prawda on 12.01.2015.
*/
var relay = require('./QuadRelay.js');
exports.turnOn = turnOn;
exports.turnOff = turnOff;
exports.setPower = setPower;
exports.disconnect = disconnect;
// controlling variables
var currentPower = 0;
var heaterOn = false;
var availablePower = [300, 600, 800, 1000, 1200, 1300, 1500, 1600, 1800, 2000];
function disconnect() {
relay.disconnect();
};
function setPower(value){
if(currentPower == 0) pressPowerUp();
if(value > currentPower){
while(value > currentPower) {
pressPowerUp();
}
}
else while(value < currentPower) {
pressPowerDown();
}
return currentPower;
}
function turnOn() {
if(!heaterOn) {
pressOnOff();
heatButton();
}
}
function turnOff() {
if(heaterOn) {
pressOnOff();
currentPower = 0;
}
}
function pressOnOff(){
onOff();
// set bool to new state
heaterOn = !heaterOn;
}
function pressPowerUp(){
// if lowest value already reached, do nothing
if(currentPower == 2000) return;
powerUp();
// set currentPower
if(currentPower == 0) currentPower = 1300;
else {
var index = availablePower.indexOf(currentPower);
currentPower = availablePower[index+1];
}
console.log("power up: "+currentPower);
}
function pressPowerDown(){
// if lowest value already reached, do nothing
if(currentPower == 300) return;
powerDown();
// set currentPower
if(currentPower == 0) currentPower = 1300;
else {
var index = availablePower.indexOf(currentPower);
currentPower = availablePower[index-1];
}
console.log("power down: "+currentPower);
}
function onOff() {
relay.flop(1);
}
function heatButton() {
relay.flop(2);
}
function powerUp() {
relay.flop(3);
}
function powerDown() {
relay.flop(4);
}
/* Zustände:
0: An/Aus, Gerät startet mit 1300W
1: nicht belegt
2: Leistung hoch
3: Leistung runter
Es gibt folgende Leistungswerte in Watt:
300, 600, 800, 1000, 1200, 1300, 1500, 1600, 1800, 2000
*/