-
Notifications
You must be signed in to change notification settings - Fork 53
/
launchPad.js
executable file
·41 lines (33 loc) · 916 Bytes
/
launchPad.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
#!/usr/bin/env node
// From: https://github.com/jamesp/node-nmea
// Need to add exports.serialParsers = m.module.parsers;
// to /usr/local/lib/node_modules/bonescript/serial.js
var b = require('bonescript');
var port = '/dev/ttyO1';
var options = {
baudrate: 9600,
parser: b.serialParsers.readline("\n")
};
b.serialOpen(port, options, onSerial);
function onSerial(x) {
console.log(x.event);
if (x.err) {
console.log('***ERROR*** ' + JSON.stringify(x));
}
if (x.event == 'open') {
console.log('***OPENED***');
setInterval(sendCommand, 1000);
}
if (x.event == 'data') {
console.log(String(x.data));
}
}
var command = ['r', 'R', 'g', 'G'];
var commIdx = 1;
function sendCommand() {
// console.log('Command: ' + command[commIdx]);
b.serialWrite(port, command[commIdx++]);
if(commIdx >= command.length) {
commIdx = 0;
}
}