-
Notifications
You must be signed in to change notification settings - Fork 0
/
indexLidar.js
40 lines (30 loc) · 926 Bytes
/
indexLidar.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
const express = require('express');
const app = express();
const server = require('http')
.Server(app);
const io = require('socket.io')(server);
const path = require('path');
const lidar = require('./tourelle-rplidar');
const emitter = lidar.getScanEmitter();
emitter.on('scan', (data) => {
if (currentSocket != undefined) currentSocket.emit('scan', data);
});
let currentSocket = undefined;
app.use('/', express.static(path.join(__dirname, 'html_root')));
io.on('connection', function(socket) {
currentSocket = socket;
socket.on('error', console.log);
socket.on('start', lidar.start);
socket.on('stop', lidar.stop);
});
server.listen(8080);
const exitHandler = () => {
console.log("Clean exit");
//lidar.stop(()=> {
process.exit();
//});
}
//catches ctrl+c event
process.on('SIGINT', exitHandler.bind(null, {}));
//catches uncaught exceptions
process.on('uncaughtException', exitHandler.bind(null, {}));