From 8411e91f048aab9e71ddd14007000206e5fe1bc6 Mon Sep 17 00:00:00 2001 From: 17792275749 <812100002@qq.com> Date: Tue, 8 Apr 2025 14:32:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E7=A7=A4=E6=96=AD=E5=BC=80?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E9=87=8D=E8=BF=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index bf5a125..281e7db 100644 --- a/app.js +++ b/app.js @@ -76,12 +76,31 @@ App({ initPpScale() { this.globalData.ppScale.plugin = requirePlugin('ppScale-plugin'); - const plugin = this.globalData.ppScale.plugin; - plugin.bus.subscribe("connectState", (res) => { + this.globalData.ppScale.plugin.bus.subscribe("connectState", (res) => { console.log("app.js ===> connectState", res); + // 连接失败则重新连接 + if (res == this.globalData.ppScale.plugin.BLUE_STATE.CONNECTFAILED) { + this.reconnectDevice() + } wx.hideLoading(); }); + + this.globalData.ppScale.plugin.bus.subscribe("deviceWillDisconnect", (res) => { + console.log("app.js ===> deviceWillDisconnect", res); + + this.reconnectDevice(); + }) }, + + reconnectDevice() { + this.globalData.ppScale.plugin.Blue.disconnect((disres) => { + if (disres.errCode == 0) { + this.globalData.ppScale.plugin.Blue.startBluetoothDevicesDiscovery(); + } else { + this.reconnectDevice(); + } + }) + } }) \ No newline at end of file