-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
65 lines (56 loc) · 1.24 KB
/
server.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
/********************************************************
* server.js
*
* Written by https://github.com/blex41
*
* Part of the cnc-pi project:
* https://github.com/blex41/cnc-pi
*
* Free to use without limitations
*
* This server exposes a web interface for drawing
* with cnc-pi.
*
*
********************************************************/
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const gpio = require('rpi-gpio');
const CNC = require('./controllers/CNCController.js');
const cnc = CNC({
name: 'myCNC',
x: {
pins: [15, 11, 13, 12],
delay: 5,
type: 'stepper',
gpio: gpio
},
y: {
pins: [37, 33, 35, 31],
delay: 5,
type: 'stepper',
gpio: gpio
},
z: {
pins: [18, 16, 22],
delay: 10,
type: 'dc',
gpio: gpio
}
});
cnc.init()
.then(() => {
// Serve static files from the public folder
app.use(express.static('public'));
// Accept JSON-encoded bodies
app.use(bodyParser.json());
app.post('/draw', (req, res) => {
res.send('Received a drawing');
const path = req.body.path;
// Return to original position after drawing
path.push([0, 0, 1]);
cnc.trace(path);
});
app.listen(3000, () => console.log('CNC server listening on port 3000!'));
});