-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbittle.js
65 lines (56 loc) · 1.28 KB
/
bittle.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
const SerialPort = require('serialport').SerialPort;
class UART {
constructor(path, baudRate, dataBits, stopBits, parity) {
this.comPortB = new SerialPort({
path: path,
baudRate: baudRate,
dataBits: dataBits,
stopBits: stopBits,
parity: parity,
});
this.comPortB.on('open', () => {
console.log('Serial Port connected');
this.comPortB.on('data', (data) => {
console.log('>:^.^:>\n' + data);
});
});
this.standAndGreet = new standAndGreet(this.comPortB);
}
}
class standAndGreet {
constructor(comPortB) {
this.comPortB = comPortB;
}
async standUp(delay) {
try {
setTimeout(() => {
this.comPortB.write('kup');
}, delay);
} catch (error) {
console.error('An error occurred: ', error);
}
}
async highFive(delay) {
try {
setTimeout(() => {
this.comPortB.write('khsk');
}, delay);
} catch (error) {
console.error('An error occurred: ', error);
}
}
async standDown(delay) {
try {
setTimeout(() => {
this.comPortB.write('d');
}, delay);
} catch (error) {
console.error('An error occurred: ', error);
}
}
}
const comPortB = new UART('/dev/cu.usbmodem56D00039821', 115200, 8, 1, 'none');
const greeting= comPortB.standAndGreet;
greeting.standUp(4000);
greeting.highFive(7000);
greeting.standDown(11000);