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