-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselfTest.js
124 lines (91 loc) · 2.46 KB
/
selfTest.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
const five = require('johnny-five');
const WaterPump = require('./src/water/WaterPump');
const Hygro = require('./src/hygro/Hygro');
const Proximity = require('./src/proximity/Proximity');
const DataMailer = require('./src/mailer/DataMailer');
const options = {
debugMode: process.env.DEBUG || 0,
wateringTriggerValue: process.env.WATERING_TRIGGER_VALUE || 800,
wateringTime: process.env.WATERING_TIME || 1000,
measureInterval: process.env.MEASURE_INTERVAL || 2000
}
class SelfCheck {
constructor() {
let that = this;
this.board = new five.Board();
this.proximity = null;
this.hygroMeter = null;
this.hygroValue = 0;
this.mailer = new DataMailer({isActive:true})
// setTimeout(() => {
// this.checkMailer();
// }, 5000);
this.board.on('ready', function () {
that.waterPump = new WaterPump({
wateringTime: 5000,
inDebugMode: 0
});
that.hygroMeter = new Hygro();
that.hygroMeter.powerOn();
that.proximity = new Proximity({waterTankDepth:150, minWaterLevel:40});
that.proximity.verbose=false;
that.display='water';
that.displayCounter = 0;
// that.waterPump.water();
this.loop(90,()=>{
// that.proximity.verbose=true;
that.hygroMeter.hygro.query(state=>{
console.log(`HygroValue: ${state.value}`)
});
})
// that.run().bind(that)
});
}
checkProximity() {
let that = this;
this.board.on('ready', function () {
that.proximity = new Proximity()
this.loop(90, () => {
console.log(that.proximity.currentValue);
})
});
}
checkHygro() {
let that = this;
this.board.on('ready', function () {
that.hygroMeter = new Hygro();
that.hygroMeter.powerOn();
this.loop(1000, () => {
console.log('Start Check');
that.hygroMeter.hygro.query((state) => {
that.hygroValue = state.value;
console.log('Hygro-Value', state.value);
});
}
)
}
)
}
checkPump() {
this.board.on('ready', function () {
var waterPump = new WaterPump({
wateringTime: 1000,
inDebugMode: 0
});
waterPump.water();
})
}
// checkMailer() {
// this.mailer.sendStatusMail({
// hygroValue: this.hygroMeter.currentValue,
// willWater: false,
// waterLevel: this.proximity.percentage,
// waterAboveGround: this.proximity.waterAboveGround(),
// hasWater:this.proximity.hasWater()
// });
// }
}
let selfCheck = new SelfCheck()
// selfCheck.checkHygro();
// selfCheck.checkPump();
// selfCheck.checkProximity()