-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalibrate.js
66 lines (59 loc) · 1.55 KB
/
calibrate.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
var MiniPh = require('./index.js');
var miniPh = new MiniPh('/dev/i2c-0', 0x4d);
function read() {
miniPh.readPh(function (err, m) {
if (err) {
console.log(err);
}
});
}
function display() {
console.log({
raw : miniPh.raw,
filter : miniPh.filter,
pH : miniPh.ph
});
}
//show loaded config
console.log(MiniPh.params);
// read 10 times a second
setInterval(read, 100);
// display once a second
setInterval(display, 1000);
console.log('Commands - Return key after each');
console.log('Put probe in solution and wait for raw numbers to stablise');
console.log('h set high pH set point');
console.log('l set low pH set point');
console.log('s save config');
console.log('v view config');
console.log('c clear last value when changing test solution');
console.log('x exit');
var stdin = process.stdin;
stdin.resume();
stdin.setEncoding('utf8');
// Read commands from console
stdin.on('data', function (key) {
if (key == 'x\n')
process.exit();
if (key == 'h\n') {
console.log('Setting high point for pH' + MiniPh.params.pHCalHighSolution + ' to ' + miniPh.filter);
miniPh.calibratepHHigh(miniPh.filter);
}
if (key == 'l\n') {
console.log('Setting low point for pH' + MiniPh.params.pHCalLowSolution + ' to ' + miniPh.filter);
miniPh.calibratepHLow(miniPh.filter);
}
if (key == 'c\n') {
console.log('Changed Solution, filter reset');
miniPh.resetFilter();
}
if (key == 's\n') {
console.log('Saving Config..');
miniPh.saveConfig();
console.log('Saved');
}
if (key == 'v\n') {
console.log('current Config..');
console.log(MiniPh.params);
}
});