generated from dannybarake/electron-quick-start
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprintfrontsensors.js
35 lines (32 loc) · 1.34 KB
/
printfrontsensors.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
var SerialPort = require('serialport');
const ReadlineFront = require('@serialport/parser-readline');
var serialPort = new SerialPort('/dev/ttyACM1', {
baudRate: 9600
});
let tempfrontsensor1 = '286C08F80900007D';
let tempfrontsensor2 = '282099F80900000F';
const parserFront = serialPort.pipe(new ReadlineFront({delimiter: '\r\n'}))
parserFront.on('data', function (data) {
if (data.includes(tempfrontsensor1)) {
let value = data.trim().slice(-5);
if (parseInt(value) >= 35) {
document.getElementById('frontsensor1').className = 'text-danger';
} else if (parseInt(value) >= 30) {
document.getElementById('frontsensor1').className = 'text-secondary';
} else {
document.getElementById('frontsensor1').className = '';
}
document.getElementById('frontsensor1').innerText = value;
}
if (data.includes(tempfrontsensor2)) {
let value = data.trim().slice(-5);
if (parseInt(value) >= 35) {
document.getElementById('frontsensor2').className = 'text-danger';
} else if (parseInt(value) >= 30) {
document.getElementById('frontsensor2').className = 'text-secondary';
} else {
document.getElementById('frontsensor2').className = '';
}
document.getElementById('frontsensor2').innerText = value;
}
});