From 46b8c003f79cb606b2a10d4cd7be9bf38462d5b4 Mon Sep 17 00:00:00 2001 From: zhangjiming Date: Thu, 3 Apr 2025 16:15:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E8=93=9D=E7=89=99=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5/=E6=96=AD=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/index.html | 3 +++ public/main.js | 29 ++++++++++++++++++++++++++++- src/routes/cmd.ts | 38 ++++++++++++++++++++++++++------------ 3 files changed, 57 insertions(+), 13 deletions(-) diff --git a/public/index.html b/public/index.html index 253bece..0b72df2 100644 --- a/public/index.html +++ b/public/index.html @@ -14,6 +14,9 @@ + + + diff --git a/public/main.js b/public/main.js index 10b168e..b81cd10 100644 --- a/public/main.js +++ b/public/main.js @@ -41,4 +41,31 @@ $("#endRecord").on("click", () => { }, }); }); - +$('#disconnect-ble').on("click", ()=> { + $.ajax({ + type: "POST", + url: "/api/cmd/disconnect-ble", + data: JSON.stringify({}), + contentType: "application/json", + success: res => { + console.log("Success", res); + }, + error: err => { + console.error("Error", err); + }, + }) +}) +$('#connect-ble').on("click", ()=> { + $.ajax({ + type: "POST", + url: "/api/cmd/connect-ble", + data: JSON.stringify({}), + contentType: "application/json", + success: res => { + console.log("Success", res); + }, + error: err => { + console.error("Error", err); + }, + }) +}) diff --git a/src/routes/cmd.ts b/src/routes/cmd.ts index bc2a261..344c680 100644 --- a/src/routes/cmd.ts +++ b/src/routes/cmd.ts @@ -1,19 +1,33 @@ import express from "express"; import { delay } from "../utils/helper"; +import { WsProxy } from "../utils/wss"; const router = express.Router(); -router.post("/", async (req, res) => { - await delay(200); - // setTimeout(() => { - // wsSend(req.app.locals["wss"], { - // type: "cmd", - // data: { - // commandId: req.body.commandId, - // status: "D0000", - // }, - // }); - // }, 2000); - res.json({ code: "00000", msg: "执行成功" }); +router.post("/disconnect-ble", async (req, res) => { + WsProxy.sendMobile({ + type: "peripheral-status", + data: { + connected: false, //是否已连接蓝牙 + power: 60, //电量 + inclinatorX: 0.276, //x轴倾斜 + inclinatorY: 3.019, //y轴倾斜 + temperature: 32.026, //温度 + }, + }); + res.json({ success: true }); +}); +router.post("/connect-ble", async (req, res) => { + WsProxy.sendMobile({ + type: "peripheral-status", + data: { + connected: true, //是否已连接蓝牙 + power: 60, //电量 + inclinatorX: 0.276, //x轴倾斜 + inclinatorY: 3.019, //y轴倾斜 + temperature: 32.026, //温度 + }, + }); + res.json({ success: true }); }); export default router;