a scrappy gimbal that insults you in shakespearean english
1import { SerialPort } from "serialport";
2import express from "express";
3
4const app = express();
5app.use(express.json());
6
7const serialPort = new SerialPort({ path: "/dev/ttyACM0", baudRate: 115200 });
8
9app.post("/motor1", (req, res) => {
10 const speed = req.body.speed;
11 const command = `1 ${speed}\r`;
12 serialPort.write(command);
13 res.send("OK");
14});
15
16app.post("/motor2", (req, res) => {
17 const speed = req.body.speed;
18 const command = `2 ${speed}\r`;
19 serialPort.write(command);
20 res.send("OK");
21});
22
23app.all("*", (req, res) => {
24 if (req.method !== "POST") {
25 res.status(405).send("Method not allowed");
26 } else {
27 res.status(404).send("Not found");
28 }
29});
30
31const port = 3000;
32app.listen(port, () => {
33 console.log(`Server running at http://localhost:${port}`);
34});