|
@@ -11,6 +11,8 @@ const ble = require('./ble_manager');
|
|
|
// const EventManager = require('./EventManager');
|
|
|
// const CmdBase = require('./../devices/bluetooth/bt_cmd');
|
|
|
const bleManager = require('./ble_manager');
|
|
|
+const QueueManager = require('./QueueManager');
|
|
|
+
|
|
|
// const EnumConnectStatus = require('./EnumConnectStatus');
|
|
|
// const EnumOpen = require('./EnumOpen');
|
|
|
// const EnumSupplier = require('./EnumSupplier');
|
|
@@ -22,11 +24,15 @@ const bleManager = require('./ble_manager');
|
|
|
|
|
|
|
|
|
class BtHelper {
|
|
|
- // static get instance() {
|
|
|
- // return this._instance;
|
|
|
- // }
|
|
|
|
|
|
- // static _instance = new BtHelper();
|
|
|
+ static getInstance() {
|
|
|
+ // if (!BtHelper._instance) {
|
|
|
+ // BtHelper._instance = new BtHelper();
|
|
|
+ // }
|
|
|
+ return BtHelper._instance;
|
|
|
+ }
|
|
|
+
|
|
|
+ static _instance = new BtHelper();
|
|
|
|
|
|
static _isConnecting = false;
|
|
|
static isDisConnectByOTA = false;
|
|
@@ -46,6 +52,10 @@ class BtHelper {
|
|
|
// this._helper.send({ cmd: task });
|
|
|
// }
|
|
|
// });
|
|
|
+ // this.queueManager = new QueueManager();
|
|
|
+ // this.queueManager.listenTask((task) => {
|
|
|
+ // bleManager.sendData(task);
|
|
|
+ // });
|
|
|
}
|
|
|
|
|
|
|
|
@@ -72,12 +82,14 @@ class BtHelper {
|
|
|
}
|
|
|
|
|
|
async stopSearch() {
|
|
|
+ clearTimeout(this.timer);
|
|
|
+ this.timer = null;
|
|
|
await bleManager.stopScan();
|
|
|
}
|
|
|
|
|
|
async _connectSuccess() {
|
|
|
- btHelper.checkDevice()
|
|
|
- btHelper.getDeviceInfo()
|
|
|
+ this.checkDevice()
|
|
|
+ this.getDeviceInfo()
|
|
|
}
|
|
|
|
|
|
async connect(data, onChanged) {
|
|
@@ -161,32 +173,34 @@ class BtHelper {
|
|
|
// await this._helper.dispose();
|
|
|
}
|
|
|
|
|
|
- send(cmd, type) {
|
|
|
- console.log('开始发送数据:', cmd)
|
|
|
+ async send(cmd, type) {
|
|
|
if (cmd) {
|
|
|
+ // this.queueManager.addTask(cmd)
|
|
|
bleManager.sendData(cmd)
|
|
|
}
|
|
|
-
|
|
|
// QueueManager.instance.addTask({ task: cmd });
|
|
|
}
|
|
|
+
|
|
|
// onLoad: function () {
|
|
|
// bleManager = new bleManager();
|
|
|
// this.initBluetooth();
|
|
|
// }
|
|
|
|
|
|
async initBluetooth(callback) {
|
|
|
- let adpter = await bleManager.initBluetoothAdapter((res) => { });
|
|
|
- // console.log(res)
|
|
|
- if (!adpter) {
|
|
|
- wx.showToast({
|
|
|
- title: '请开启蓝牙功能',
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- if (callback) {
|
|
|
- callback(false, false)
|
|
|
+ let adpter = await bleManager.initBluetoothAdapter((res) => {
|
|
|
+ if (!res) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '请开启蓝牙功能',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ if (callback) {
|
|
|
+ callback(false, false)
|
|
|
+ }
|
|
|
+ return
|
|
|
}
|
|
|
- return
|
|
|
- }
|
|
|
+ });
|
|
|
+ // console.log(res)
|
|
|
+
|
|
|
|
|
|
bleManager.checkBluetoothPermission(function (per) {
|
|
|
if (!per) {
|
|
@@ -224,13 +238,13 @@ class BtHelper {
|
|
|
|
|
|
async checkDevice() {
|
|
|
// console.log("校验设备:", BtCmd); // 输出: EarPhone Info
|
|
|
- await this.send(BtCmd.checkDevice());
|
|
|
+ this.send(BtCmd.checkDevice());
|
|
|
//2.0有发这个,不知道是啥
|
|
|
- await this.send([0x54, 0x44, 0x44, 0x48, 0x01, 0x09, 0x26, 0x01, 0x01]);
|
|
|
+ this.send([0x54, 0x44, 0x44, 0x48, 0x01, 0x09, 0x26, 0x01, 0x01]);
|
|
|
}
|
|
|
|
|
|
async getVersion() {
|
|
|
- await this.send(BtCmd.queryVersion());
|
|
|
+ this.send(BtCmd.queryVersion());
|
|
|
}
|
|
|
|
|
|
_time() {
|
|
@@ -256,48 +270,48 @@ class BtHelper {
|
|
|
}
|
|
|
|
|
|
async getAlert() {
|
|
|
- await this.send(BtCmd.queryAlarm());
|
|
|
+ this.send(BtCmd.queryAlarm());
|
|
|
}
|
|
|
|
|
|
async getSleep() {
|
|
|
- await this.send(BtCmd.querySleep());
|
|
|
+ this.send(BtCmd.querySleep());
|
|
|
}
|
|
|
|
|
|
async setAlert(open, weekCycle, hour, minutes, channel = 1) {
|
|
|
- await this.send(BtCmd.setAlarm({ switchStatus: open, weekCycle, hour, minutes }));
|
|
|
+ this.send(BtCmd.setAlarm({ switchStatus: open, weekCycle, hour, minutes }));
|
|
|
}
|
|
|
|
|
|
async setAutoPlay(open) {
|
|
|
- await this.send(BtCmd.setAutoPlay({ switchStatus: open }));
|
|
|
+ this.send(BtCmd.setAutoPlay({ switchStatus: open }));
|
|
|
}
|
|
|
|
|
|
async getAutoPlay() {
|
|
|
- await this.send(BtCmd.getAutoPlay);
|
|
|
+ this.send(BtCmd.getAutoPlay);
|
|
|
}
|
|
|
|
|
|
async setLowKwhWarningTone(notify) {
|
|
|
- await this.send(BtCmd.setLowKwhWarningTone({ notify }));
|
|
|
+ this.send(BtCmd.setLowKwhWarningTone({ notify }));
|
|
|
}
|
|
|
|
|
|
async setPauseSleep(time) {
|
|
|
- await this.send(BtCmd.setSleepAfterPlayPause({ time }));
|
|
|
+ this.send(BtCmd.setSleepAfterPlayPause({ time }));
|
|
|
}
|
|
|
|
|
|
async getPauseSleep() {
|
|
|
- await this.send(BtCmd.querySleepAfterPlayPause());
|
|
|
+ this.send(BtCmd.querySleepAfterPlayPause());
|
|
|
}
|
|
|
|
|
|
async setRGB(r, g, b) {
|
|
|
- await this.send(BtCmd.setRGB({ r, g, b }));
|
|
|
+ this.send(BtCmd.setRGB({ r, g, b }));
|
|
|
}
|
|
|
|
|
|
async setSleep(open, hour, minutes) {
|
|
|
- await this.send(BtCmd.setSleep({ switchStatus: open, hour, minutes }));
|
|
|
+ this.send(BtCmd.setSleep({ switchStatus: open, hour, minutes }));
|
|
|
}
|
|
|
|
|
|
async setTime() {
|
|
|
console.log("setTime========111")
|
|
|
- // await this.send(BtCmd.setTime());
|
|
|
+ // this.send(BtCmd.setTime());
|
|
|
}
|
|
|
|
|
|
async setVolume(volume) {
|
|
@@ -308,11 +322,11 @@ class BtHelper {
|
|
|
|
|
|
console.log(`phoneMax=${phoneMax}, deviceMax=${CmdBase.volumeMax}, setVolume=${volume}, result=${result}`);
|
|
|
|
|
|
- await this.send(BtCmd.setVolume({ volume: result }));
|
|
|
+ this.send(BtCmd.setVolume({ volume: result }));
|
|
|
}
|
|
|
|
|
|
async getVolume() {
|
|
|
- await this.send(BtCmd.queryVolume());
|
|
|
+ this.send(BtCmd.queryVolume());
|
|
|
}
|
|
|
|
|
|
stop() {
|
|
@@ -366,44 +380,44 @@ class BtHelper {
|
|
|
}
|
|
|
|
|
|
async getLowDelayMode() {
|
|
|
- await this.send(BtCmd.queryLowDelayMode());
|
|
|
+ this.send(BtCmd.queryLowDelayMode());
|
|
|
}
|
|
|
|
|
|
async setLowDelayMode(open, mode) {
|
|
|
- await this.send(BtCmd.setLowDelayMode({ open, mode }));
|
|
|
+ this.send(BtCmd.setLowDelayMode({ open, mode }));
|
|
|
}
|
|
|
|
|
|
async setLowPowerMode(isOpen) {
|
|
|
- await this.send(BtCmd.setLowPowerMode({ isOpen: isOpen ? EnumOpen.open : EnumOpen.close }));
|
|
|
+ this.send(BtCmd.setLowPowerMode({ isOpen: isOpen ? EnumOpen.open : EnumOpen.close }));
|
|
|
}
|
|
|
|
|
|
async queryLowPower() {
|
|
|
- await this.send(BtCmd.queryLowPower());
|
|
|
+ this.send(BtCmd.queryLowPower());
|
|
|
}
|
|
|
|
|
|
async setCtrlStatus(singleClick, doubleClick, longClick) {
|
|
|
- await this.send(BtCmd.setCtrlStatus({ singleClick, doubleClick, longClick }));
|
|
|
+ this.send(BtCmd.setCtrlStatus({ singleClick, doubleClick, longClick }));
|
|
|
}
|
|
|
|
|
|
async getEQ() {
|
|
|
- await this.send(BtCmd.queryEQ());
|
|
|
+ this.send(BtCmd.queryEQ());
|
|
|
}
|
|
|
|
|
|
async setEQ(list) {
|
|
|
- await this.send(BtCmd.setEQ({ list }));
|
|
|
+ this.send(BtCmd.setEQ({ list }));
|
|
|
}
|
|
|
|
|
|
async queryLowKwhWarningTone() {
|
|
|
- await this.send(BtCmd.queryLowKwhWarningTone());
|
|
|
+ this.send(BtCmd.queryLowKwhWarningTone());
|
|
|
}
|
|
|
|
|
|
async changeChannelCallBack() {
|
|
|
- await this.send(Uint8Array.from([0x54, 0x44, 0x44, 0x48, 0x01, 0x0a, 0x29, 0x02, 0x00, 0x01]));
|
|
|
- await this.send(Uint8Array.from([0x54, 0x44, 0x44, 0x48, 0x01, 0x09, 0x39, 0x01, 0x00]));
|
|
|
+ this.send(Uint8Array.from([0x54, 0x44, 0x44, 0x48, 0x01, 0x0a, 0x29, 0x02, 0x00, 0x01]));
|
|
|
+ this.send(Uint8Array.from([0x54, 0x44, 0x44, 0x48, 0x01, 0x09, 0x39, 0x01, 0x00]));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 导出 BtHelper 类
|
|
|
-const btHelper = new BtHelper();
|
|
|
+// const btHelper = new BtHelper();
|
|
|
|
|
|
-module.exports = btHelper;
|
|
|
+module.exports = { BtHelper }
|