Przeglądaj źródła

feature: 整理数据

Damon 8 miesięcy temu
rodzic
commit
f4119996e3

+ 12 - 5
devices/ble_manager.js

@@ -267,22 +267,29 @@ class bleManager {
   }
   // 开始搜索蓝牙设备
   async startScan(success, fail) {
-
-    let open = await this.getSetting()
+    const that = this;
+    let open = await that.getSetting()
     if (!open) {
       if (fail) {
         fail("需要先开启定位");
       }
       console.log('需要先开启定位');
     }
-    if (!this.isAvailable && !this.hasPermission) {
+    if (!that.isAvailable && !that.hasPermission) {
       return false;
     }
     wx.startBluetoothDevicesDiscovery({
       // services: ["ffc0", "ab00", "ffe5"],
       success: (res) => {
-        // this.onBluetoothDeviceFound();
-        console.log('蓝牙设备搜索已启动:', res);
+        // that.onBluetoothDeviceFound();
+        // {"errno":0,"errCode":0,"isDiscovering":true,"errMsg":"startBluetoothDevicesDiscovery:ok"}
+        console.log('蓝牙设备搜索已启动:' + JSON.stringify(res) + "===" + success);
+
+        // wx.onBluetoothDeviceFound((result) => {
+        //   console.log('找到设备==00===', result.devices);
+        //   console.log('找到设备==11===' + JSON.stringify(result));
+        // });
+
         if (success) {
           success(res);
         }

+ 451 - 419
devices/bt_helper.js

@@ -4,7 +4,10 @@
 // const BtIOSHelper = require('./BtIOSHelper');
 // const QueueManager = require('./QueueManager');
 // const DeviceManager = require('./DeviceManager');
-const { CmdBase, BtCmd, } = require('./../devices/bluetooth/bt_cmd');
+const {
+  CmdBase,
+  BtCmd,
+} = require('./../devices/bluetooth/bt_cmd');
 const BtParse = require('./../devices/bluetooth/bt_parse');
 // const VolumeUtil = require('./VolumeUtil');
 // const EventManager = require('./EventManager');
@@ -19,439 +22,468 @@ const QueueManager = require('./QueueManager');
 // const EnumLowDelayMode = require('./EnumLowDelayMode');
 // const EnumPlayStatus = require('./EnumPlayStatus');
 
-
-
-
 class BtHelper {
-
-    static getInstance() {
-        // if (!BtHelper._instance) {
-        //     BtHelper._instance = new BtHelper();
-        // }
-        return BtHelper._instance;
-    }
-
-    static _instance = new BtHelper();
-
-    static _isConnecting = false;
-    static isDisConnectByOTA = false;
-
-    // _helper;
-
-    constructor() {
-        this.timer = null;
-        this.bleManager = new bleManager();
-        // if (DeviceUtil.isAndroid) {
-        //     this._helper = BtAndroidHelper.instance;
-        // } else {
-        //     this._helper = BtIOSHelper.instance;
-        // }
-
-        // QueueManager.instance.listenTask((task) => {
-        //     if (!DeviceManager.instance.isWatch) {
-        //         this._helper.send({ cmd: task });
-        //     }
-        // });
-        this.queueManager = new QueueManager();
-        let _this = this
-        this.queueManager.clear();
-        this.queueManager.listenTask((task) => {
-            _this.bleManager.sendData(task);
-        });
-    }
-
-
-    resetConnectState(connect) {
-        // BtHelper._isConnecting = connect;
-    }
-
-    async search(stopCall) {
-        let res = await this.bleManager.startScan()
-        this.timer = null;
-        this.timer = setTimeout(() => {
-            this.stopSearch();
-            if (stopCall) {
-                stopCall()
-            }
-        }, 10000);
-        // console.log(res);
-        // return await this._helper.search();
-    }
-
-    async findDevices(callback) {
-        this.bleManager.onBluetoothDeviceFound(callback)
-        // return await this._helper.search();
-    }
-
-    async stopSearch() {
-        clearTimeout(this.timer);
-        this.timer = null;
-        await this.bleManager.stopScan();
-    }
-
-    async _connectSuccess() {
-        this.checkDevice()
-        this.getDeviceInfo()
-
-    }
-
-    async connect(data, onChanged) {
-        // await this._helper.connect({ data, onChanged, isClick });
-
-        clearTimeout(this.timer);
-        this.timer = null;
-        this.bleManager.stopScan()
-        var res = await this.bleManager.connectToDevice(data);
-        console.log(res ? '连接成功' : '连接失败');
-        // this.setData({ connectedDeviceId: deviceId });
-        if (res === false) {
-            console.log("连接失败")
-            this.disconnect(data)
-            if (onChanged) {
-                onChanged(false)
-            }
-            return
-        }
-        const serviceId = await this.bleManager.discoverServices(data.deviceId);
-        if (serviceId == "") {
-            console.log("连接失败")
-            this.disconnect(data)
-            if (onChanged) {
-                onChanged(false)
-            }
-            return
-        }
-        // this.setData({ services });
-        console.log("服务ID:" + serviceId)
-
-        var characteristics = await this.bleManager.discoverCharacteristics(data.deviceId, serviceId)
-        if (characteristics == "") {
-            console.log("连接失败")
-            this.disconnect(data)
-            if (onChanged) {
-                onChanged(false)
-            }
-            return
-        }
-        console.log('device特征值:', characteristics)
-        // let uuids = ["ab00", "ffc0"];
-        for (let i = 0; i < characteristics.length; i++) {
-            let charc = characteristics[i];
-            // if (!uuids.includes(charc.uuid)) {
-            //     if (onChanged) {
-            //         console.log('没有特征值:', charc.uuid);
-            //         onChanged(false)
-            //     }
-            //     return;
-            // }
-            if (charc.properties.notify) {
-                console.log('订阅数据:', charc.uuid);
-                // 订阅的
-                this.bleManager.notifyCharacteristicValueChange(charc.uuid, (res) => {
-                    BtParse.parseTLV(res);
-                })
-            }
-            if (charc.properties.write || charc.properties.writeWithoutResponse) {
-                // 写入的
-                this.bleManager.setWrite(charc, charc.uuid)
-                setTimeout(() => {
-                    this._connectSuccess()
-                }, 500);
-                if (onChanged) {
-                    onChanged(true)
-                }
-            }
-            // if (charc.properties.read) {
-            //     var chara = await this.bleManager.readCharacteristicValue(charc.uuid,)
-            // }
-        }
-
-
-        // this.setData({ characteristics: { ...this.data.characteristics, [service.uuid]: characteristics } });
-
-    }
-
-    async disconnect(data) {
-        this.bleManager.disconnect(data.deviceId)
-    }
-
-    async dispose() {
-        // await this._helper.dispose();
-    }
-
-    async sendNow(cmd) {
-        if (cmd) {
-            this.bleManager.sendData(cmd)
-        }
-    }
-    async send(cmd, type) {
-        if (cmd) {
-            this.queueManager.addTask(cmd)
+  static getInstance() {
+    // if (!BtHelper._instance) {
+    //     BtHelper._instance = new BtHelper();
+    // }
+    return BtHelper._instance;
+  }
+  static _instance = new BtHelper();
+  static _isConnecting = false;
+  static isDisConnectByOTA = false;
+  // _helper;
+
+  constructor() {
+    this.timer = null;
+    this.bleManager = new bleManager();
+    // if (DeviceUtil.isAndroid) {
+    //     this._helper = BtAndroidHelper.instance;
+    // } else {
+    //     this._helper = BtIOSHelper.instance;
+    // }
+
+    // QueueManager.instance.listenTask((task) => {
+    //     if (!DeviceManager.instance.isWatch) {
+    //         this._helper.send({ cmd: task });
+    //     }
+    // });
+    this.queueManager = new QueueManager();
+    let _this = this
+    this.queueManager.clear();
+    this.queueManager.listenTask((task) => {
+      _this.bleManager.sendData(task);
+    });
+  }
+
+
+  resetConnectState(connect) {
+    // BtHelper._isConnecting = connect;
+  }
+
+  async search(stopCall) {
+    let res = await this.bleManager.startScan();
+    this.timer = null;
+    this.timer = setTimeout(() => {
+      this.stopSearch();
+      if (stopCall) {
+        stopCall()
+      }
+    }, 10000);
+    // console.log(res);
+    // return await this._helper.search();
+  }
+
+  async findDevices(callback) {
+    this.bleManager.onBluetoothDeviceFound(callback)
+    // return await this._helper.search();
+  }
+
+  async stopSearch() {
+    clearTimeout(this.timer);
+    this.timer = null;
+    await this.bleManager.stopScan();
+  }
+
+  async _connectSuccess() {
+    this.checkDevice()
+    this.getDeviceInfo()
+
+  }
+
+  async connect(data, onChanged) {
+    // await this._helper.connect({ data, onChanged, isClick });
+
+    clearTimeout(this.timer);
+    this.timer = null;
+    this.bleManager.stopScan()
+    var res = await this.bleManager.connectToDevice(data);
+    console.log(res ? '连接成功' : '连接失败');
+    // this.setData({ connectedDeviceId: deviceId });
+    if (res === false) {
+      console.log("连接失败")
+      this.disconnect(data)
+      if (onChanged) {
+        onChanged(false)
+      }
+      return
+    }
+    const serviceId = await this.bleManager.discoverServices(data.deviceId);
+    if (serviceId == "") {
+      console.log("连接失败")
+      this.disconnect(data)
+      if (onChanged) {
+        onChanged(false)
+      }
+      return
+    }
+    // this.setData({ services });
+    console.log("服务ID:" + serviceId)
+
+    var characteristics = await this.bleManager.discoverCharacteristics(data.deviceId, serviceId)
+    if (characteristics == "") {
+      console.log("连接失败")
+      this.disconnect(data)
+      if (onChanged) {
+        onChanged(false)
+      }
+      return
+    }
+    console.log('device特征值:', characteristics)
+    // let uuids = ["ab00", "ffc0"];
+    for (let i = 0; i < characteristics.length; i++) {
+      let charc = characteristics[i];
+      // if (!uuids.includes(charc.uuid)) {
+      //     if (onChanged) {
+      //         console.log('没有特征值:', charc.uuid);
+      //         onChanged(false)
+      //     }
+      //     return;
+      // }
+      if (charc.properties.notify) {
+        console.log('订阅数据:', charc.uuid);
+        // 订阅的
+        this.bleManager.notifyCharacteristicValueChange(charc.uuid, (res) => {
+          BtParse.parseTLV(res);
+        })
+      }
+      if (charc.properties.write || charc.properties.writeWithoutResponse) {
+        // 写入的
+        this.bleManager.setWrite(charc, charc.uuid)
+        setTimeout(() => {
+          this._connectSuccess()
+        }, 500);
+        if (onChanged) {
+          onChanged(true)
         }
-        // QueueManager.instance.addTask({ task: cmd });
+      }
+      // if (charc.properties.read) {
+      //     var chara = await this.bleManager.readCharacteristicValue(charc.uuid,)
+      // }
     }
 
-    // onLoad: function () {
-    //     bleManager = new bleManager();
-    //     this.initBluetooth();
-    //   }
-
-    async initBluetooth(callback) {
-        let adpter = await this.bleManager.initBluetoothAdapter((res) => {
-            if (!res) {
-                wx.showToast({
-                    title: '请开启蓝牙功能',
-                    icon: 'none'
-                })
-                if (callback) {
-                    callback(false, false)
-                }
-                return
-            }
-        });
-        // console.log(res)
-
-
-        this.bleManager.checkBluetoothPermission(function (per) {
-            if (!per) {
-                wx.showToast({
-                    title: '没有蓝牙权限',
-                    icon: 'none'
-                })
-            }
-            if (callback) {
-                callback(adpter, per)
-            }
-        });
-    }
 
-    closeBle() {
-        this.bleManager.closeBle()
-    }
+    // this.setData({ characteristics: { ...this.data.characteristics, [service.uuid]: characteristics } });
 
-    async getConnectedDevices() {
-        try {
-            const connectedDevices = await this.bleManager.getConnectedDevices();
-            console.log("全部设备1:", connectedDevices)
-            if (connectedDevices.length) {
-                // todo 已经连接上的设备
-            }
-            const allDevices = await this.bleManager.getAllConnectedDevices()
-            console.log("全部设备2:", allDevices)
-            let newDevices = connectedDevices.concat(allDevices);
-            return newDevices
-        } catch (error) {
-            console.error(error);
-            return []
-        }
-    }
+  }
 
-    async checkDevice() {
-        // console.log("校验设备:", BtCmd); // 输出: EarPhone Info
-        this.sendNow(BtCmd.checkDevice());
-        //2.0有发这个,不知道是啥
-        this.send([0x54, 0x44, 0x44, 0x48, 0x01, 0x09, 0x26, 0x01, 0x01]);
-    }
+  async disconnect(data) {
+    this.bleManager.disconnect(data.deviceId)
+  }
 
-    async getVersion() {
-        this.send(BtCmd.queryVersion());
-    }
+  async dispose() {
+    // await this._helper.dispose();
+  }
 
-    _time() {
-        return 400;
+  async sendNow(cmd) {
+    if (cmd) {
+      this.bleManager.sendData(cmd)
     }
-
-    getDeviceInfo() {
-        // if (DeviceManager.instance.isEarphone) {
-        //     this.send(BtCmd.queryKwhEarPhone);
-        //     this.send(BtCmd.queryLowDelayMode);
-        //     this.send(BtCmd.queryEQ);
-        //     this.send(BtCmd.queryLowPower);
-        //     this.send(BtCmd.queryCtrlStatus);
-        // } else {
-        // this.send(BtCmd.setDevTime());
-        this.send(BtCmd.queryKwh());
-        this.getSleep();
-        this.getAlert();
-        this.send(BtCmd.queryRGB());
-        this.getVolume();
-        this.setVolume(8)
-        this.getPauseSleep();
-        // }
-    }
-
-    async getAlert() {
-        this.send(BtCmd.queryAlarm());
+  }
+  async send(cmd, type) {
+    if (cmd) {
+      this.queueManager.addTask(cmd)
     }
+    // QueueManager.instance.addTask({ task: cmd });
+  }
 
-    async getSleep() {
-        this.send(BtCmd.querySleep());
-    }
+  // onLoad: function () {
+  //     bleManager = new bleManager();
+  //     this.initBluetooth();
+  //   }
 
-    async setAlert(open, weekCycle, hour, minutes, channel = 1) {
-        this.send(BtCmd.setAlarm({ switchStatus: open, weekCycle, hour, minutes }));
-    }
-
-    async setAutoPlay(open) {
-        this.send(BtCmd.setAutoPlay({ switchStatus: open }));
-    }
-
-    async getAutoPlay() {
-        this.send(BtCmd.getAutoPlay);
-    }
-
-    async setLowKwhWarningTone(notify) {
-        this.send(BtCmd.setLowKwhWarningTone({ notify }));
-    }
-
-    async setPauseSleep(time) {
-        this.send(BtCmd.setSleepAfterPlayPause({ time }));
-    }
-
-    async getPauseSleep() {
-        this.send(BtCmd.querySleepAfterPlayPause());
-    }
-
-    async setRGB(r, g, b) {
-        this.send(BtCmd.setRGB({ r, g, b }));
-    }
-
-    async setSleep(open, hour, minutes) {
-        this.send(BtCmd.setSleep({ switchStatus: open, hour, minutes }));
-    }
-
-    async setTime() {
-        console.log("setTime========111")
-        // this.send(BtCmd.setTime());
-    }
-
-    async setVolume(volume) {
-        // VolumeUtil.setVolume(volume, { hideVolumeView: true });
-
-        const phoneMax = 15;//await VolumeUtil.getMaxVolume();
-        const result = Math.floor(CmdBase.volumeMax * volume / phoneMax);
-
-        console.log(`phoneMax=${phoneMax}, deviceMax=${CmdBase.volumeMax}, setVolume=${volume}, result=${result}`);
-
-        this.send(BtCmd.setVolume({ volume: 8 }));
-    }
-
-    async getVolume() {
-        this.send(BtCmd.queryVolume());
-    }
-
-    stop() {
-        // EventManager.fire({ event: 'playStatus', playStatus: EnumPlayStatus.stop.index });
-    }
-
-    next() {
-        // TODO: implement next
-    }
-
-    pause() {
-        // EventManager.fire({ event: 'playStatus', playStatus: EnumPlayStatus.pause.index });
-    }
-
-    play() {
-        // TODO: implement play
-    }
-
-    previous() {
-        // TODO: implement previous
-    }
-
-    startVoiceRecordResponse(supplier) {
-        console.log(`回调开始录音:${supplier}`);
-        // switch (supplier) {
-        //     case EnumSupplier.jieLi:
-        //         this.send(BtCmd.jlStartVoiceResponse);
-        //         break;
-        //     case EnumSupplier.lingXin:
-        //         this.send(BtCmd.lxStartVoiceResponse);
-        //         break;
-        //     case EnumSupplier.qiXinWei:
-        //         this.send(BtCmd.b1StartVoiceResponse);
-        //         break;
-        // }
-    }
-
-    stopVoiceRecordResponse(supplier) {
-        console.log(`回调结束录音:${supplier}`);
-        // switch (supplier) {
-        //     case EnumSupplier.jieLi:
-        //         this.send(BtCmd.jlStopVoiceResponse());
-        //         break;
-        //     case EnumSupplier.lingXin:
-        //         this.send(BtCmd.lxStopVoiceResponse());
-        //         break;
-        //     case EnumSupplier.qiXinWei:
-        //         this.send(BtCmd.b1StopVoiceResponse());
-        //         break;
-        // }
-    }
-
-    async getLowDelayMode() {
-        this.send(BtCmd.queryLowDelayMode());
-    }
-
-    async setLowDelayMode(open, mode) {
-        this.send(BtCmd.setLowDelayMode({ open, mode }));
-    }
-
-    async setLowPowerMode(isOpen) {
-        this.send(BtCmd.setLowPowerMode({ isOpen: isOpen ? EnumOpen.open : EnumOpen.close }));
-    }
-
-    async queryLowPower() {
-        this.send(BtCmd.queryLowPower());
-    }
-
-    async setCtrlStatus(singleClick, doubleClick, longClick) {
-        this.send(BtCmd.setCtrlStatus({ singleClick, doubleClick, longClick }));
-    }
-
-    async getEQ() {
-        this.send(BtCmd.queryEQ());
-    }
-
-    async setEQ(list) {
-        this.send(BtCmd.setEQ({ list }));
-    }
-
-    async queryLowKwhWarningTone() {
-        this.send(BtCmd.queryLowKwhWarningTone());
-    }
-
-    async changeChannelCallBack() {
-        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]));
-    }
-
-    /* 黑胶音箱的指令 */
-    // 壁纸指令 1开始, 0结束
-    static wallPaper(value) {
-        this.send(BtCmd.wallPaper(value));
-    }
-    // 壁纸指令 
-    static wallPaperData(value) {
-        this.send(BtCmd.wallPaperData(value));
-    }
-    // 背景图指令
-    static backgroudImg(value) {
-        this.send(BtCmd.backgroudImg(value));
-    }   // 背景图指令
-    static backgroudImgData(value) {
-        this.send(BtCmd.backgroudImgData(value));
-    }
-    // OTA指令
-    static OTA(value) {
-        this.send(BtCmd.OTA(value));
-    } static OtaData(value) {
-        this.send(BtCmd.OtaData(value));
-    }
+  ///初始化蓝牙
+  async initBluetooth(callback) {
+    var that = this;
+    let adpter = await that.bleManager.initBluetoothAdapter((res) => {
+      if (!res) {
+        wx.showToast({
+          title: '请开启蓝牙功能',
+          icon: 'none'
+        })
+        if (callback) {
+          callback(false, false)
+        }
+        return
+      }
+    });
+    // console.log(res)
+    that.bleManager.checkBluetoothPermission(function (per) {
+      if (!per) {
+        wx.showToast({
+          title: '没有蓝牙权限',
+          icon: 'none'
+        })
+      }
+      if (callback) {
+        callback(adpter, per)
+      }
+    });
+  }
+
+  closeBle() {
+    var that = this;
+    that.bleManager.closeBle()
+  }
+
+  async getConnectedDevices() {
+    try {
+      const connectedDevices = await this.bleManager.getConnectedDevices();
+      console.log("全部设备1:", connectedDevices)
+      if (connectedDevices.length) {
+        // todo 已经连接上的设备
+      }
+      const allDevices = await this.bleManager.getAllConnectedDevices()
+      console.log("全部设备2:", allDevices)
+      let newDevices = connectedDevices.concat(allDevices);
+      return newDevices
+    } catch (error) {
+      console.error(error);
+      return []
+    }
+  }
+
+  async checkDevice() {
+    // console.log("校验设备:", BtCmd); // 输出: EarPhone Info
+    this.sendNow(BtCmd.checkDevice());
+    //2.0有发这个,不知道是啥
+    this.send([0x54, 0x44, 0x44, 0x48, 0x01, 0x09, 0x26, 0x01, 0x01]);
+  }
+
+  async getVersion() {
+    this.send(BtCmd.queryVersion());
+  }
+
+  _time() {
+    return 400;
+  }
+
+  getDeviceInfo() {
+    // if (DeviceManager.instance.isEarphone) {
+    //     this.send(BtCmd.queryKwhEarPhone);
+    //     this.send(BtCmd.queryLowDelayMode);
+    //     this.send(BtCmd.queryEQ);
+    //     this.send(BtCmd.queryLowPower);
+    //     this.send(BtCmd.queryCtrlStatus);
+    // } else {
+    // this.send(BtCmd.setDevTime());
+    this.send(BtCmd.queryKwh());
+    this.getSleep();
+    this.getAlert();
+    this.send(BtCmd.queryRGB());
+    this.getVolume();
+    this.setVolume(8)
+    this.getPauseSleep();
+    // }
+  }
+
+  async getAlert() {
+    this.send(BtCmd.queryAlarm());
+  }
+
+  async getSleep() {
+    this.send(BtCmd.querySleep());
+  }
+
+  async setAlert(open, weekCycle, hour, minutes, channel = 1) {
+    this.send(BtCmd.setAlarm({
+      switchStatus: open,
+      weekCycle,
+      hour,
+      minutes
+    }));
+  }
+
+  async setAutoPlay(open) {
+    this.send(BtCmd.setAutoPlay({
+      switchStatus: open
+    }));
+  }
+
+  async getAutoPlay() {
+    this.send(BtCmd.getAutoPlay);
+  }
+
+  async setLowKwhWarningTone(notify) {
+    this.send(BtCmd.setLowKwhWarningTone({
+      notify
+    }));
+  }
+
+  async setPauseSleep(time) {
+    this.send(BtCmd.setSleepAfterPlayPause({
+      time
+    }));
+  }
+
+  async getPauseSleep() {
+    this.send(BtCmd.querySleepAfterPlayPause());
+  }
+
+  async setRGB(r, g, b) {
+    this.send(BtCmd.setRGB({
+      r,
+      g,
+      b
+    }));
+  }
+
+  async setSleep(open, hour, minutes) {
+    this.send(BtCmd.setSleep({
+      switchStatus: open,
+      hour,
+      minutes
+    }));
+  }
+
+  async setTime() {
+    console.log("setTime========111")
+    // this.send(BtCmd.setTime());
+  }
+
+  async setVolume(volume) {
+    // VolumeUtil.setVolume(volume, { hideVolumeView: true });
+
+    const phoneMax = 15; //await VolumeUtil.getMaxVolume();
+    const result = Math.floor(CmdBase.volumeMax * volume / phoneMax);
+
+    console.log(`phoneMax=${phoneMax}, deviceMax=${CmdBase.volumeMax}, setVolume=${volume}, result=${result}`);
+
+    this.send(BtCmd.setVolume({
+      volume: 8
+    }));
+  }
+
+  async getVolume() {
+    this.send(BtCmd.queryVolume());
+  }
+
+  stop() {
+    // EventManager.fire({ event: 'playStatus', playStatus: EnumPlayStatus.stop.index });
+  }
+
+  next() {
+    // TODO: implement next
+  }
+
+  pause() {
+    // EventManager.fire({ event: 'playStatus', playStatus: EnumPlayStatus.pause.index });
+  }
+
+  play() {
+    // TODO: implement play
+  }
+
+  previous() {
+    // TODO: implement previous
+  }
+
+  startVoiceRecordResponse(supplier) {
+    console.log(`回调开始录音:${supplier}`);
+    // switch (supplier) {
+    //     case EnumSupplier.jieLi:
+    //         this.send(BtCmd.jlStartVoiceResponse);
+    //         break;
+    //     case EnumSupplier.lingXin:
+    //         this.send(BtCmd.lxStartVoiceResponse);
+    //         break;
+    //     case EnumSupplier.qiXinWei:
+    //         this.send(BtCmd.b1StartVoiceResponse);
+    //         break;
+    // }
+  }
+
+  stopVoiceRecordResponse(supplier) {
+    console.log(`回调结束录音:${supplier}`);
+    // switch (supplier) {
+    //     case EnumSupplier.jieLi:
+    //         this.send(BtCmd.jlStopVoiceResponse());
+    //         break;
+    //     case EnumSupplier.lingXin:
+    //         this.send(BtCmd.lxStopVoiceResponse());
+    //         break;
+    //     case EnumSupplier.qiXinWei:
+    //         this.send(BtCmd.b1StopVoiceResponse());
+    //         break;
+    // }
+  }
+
+  async getLowDelayMode() {
+    this.send(BtCmd.queryLowDelayMode());
+  }
+
+  async setLowDelayMode(open, mode) {
+    this.send(BtCmd.setLowDelayMode({
+      open,
+      mode
+    }));
+  }
+
+  async setLowPowerMode(isOpen) {
+    this.send(BtCmd.setLowPowerMode({
+      isOpen: isOpen ? EnumOpen.open : EnumOpen.close
+    }));
+  }
+
+  async queryLowPower() {
+    this.send(BtCmd.queryLowPower());
+  }
+
+  async setCtrlStatus(singleClick, doubleClick, longClick) {
+    this.send(BtCmd.setCtrlStatus({
+      singleClick,
+      doubleClick,
+      longClick
+    }));
+  }
+
+  async getEQ() {
+    this.send(BtCmd.queryEQ());
+  }
+
+  async setEQ(list) {
+    this.send(BtCmd.setEQ({
+      list
+    }));
+  }
+
+  async queryLowKwhWarningTone() {
+    this.send(BtCmd.queryLowKwhWarningTone());
+  }
+
+  async changeChannelCallBack() {
+    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]));
+  }
+
+  /* 黑胶音箱的指令 */
+  // 壁纸指令 1开始, 0结束
+  static wallPaper(value) {
+    this.send(BtCmd.wallPaper(value));
+  }
+  // 壁纸指令 
+  static wallPaperData(value) {
+    this.send(BtCmd.wallPaperData(value));
+  }
+  // 背景图指令
+  static backgroudImg(value) {
+    this.send(BtCmd.backgroudImg(value));
+  } // 背景图指令
+  static backgroudImgData(value) {
+    this.send(BtCmd.backgroudImgData(value));
+  }
+  // OTA指令
+  static OTA(value) {
+    this.send(BtCmd.OTA(value));
+  }
+  static OtaData(value) {
+    this.send(BtCmd.OtaData(value));
+  }
 }
 
 // 导出 BtHelper 类
 // const btHelper = new BtHelper();
 
-module.exports = { BtHelper }
+module.exports = {
+  BtHelper
+}

Plik diff jest za duży
+ 55 - 110
pages/connectBle/connectBle.js


+ 7 - 7
pages/connectBle/connectBle.wxml

@@ -1,10 +1,10 @@
 <!-- pages/connectBle/connectBle.wxml -->
 <view class="container">
-				<nav-bar bind:goBack="_goBack" nav-bgc-class="ex-nav-bgc-class" nav-title-class="ex-nav-title-class" ex-back-pre="ex-back-pre" navbar-data='{{nvabarData}}'></nav-bar>
-				<image class="device_pic" src="{{connectDevice.img}}" mode="aspectFill" />
-				<view class="top_tips main_black">{{searchTips}}</view>
-				<view style="font-size: 28rpx; color: #666666; margin-top: 32rpx; display: flex; justify-content: center; align-items: center;">
-								{{subTips}}
-				</view>
-				<view class="main_color connect_button" bind:tap="connectDeviceTap">{{buttonTips}}</view>
+  <nav-bar bind:goBack="_goBack" nav-bgc-class="ex-nav-bgc-class" nav-title-class="ex-nav-title-class" ex-back-pre="ex-back-pre" navbar-data='{{nvabarData}}'></nav-bar>
+  <image class="device_pic" src="{{connectDevice.img}}" mode="aspectFill" />
+  <view class="top_tips main_black">{{searchTips}}</view>
+  <view style="font-size: 28rpx; color: #666666; margin-top: 32rpx; display: flex; justify-content: center; align-items: center;">
+    {{subTips}}
+  </view>
+  <view class="main_color connect_button" bind:tap="connectDeviceTap">{{buttonTips}}</view>
 </view>

+ 1 - 0
pages/deviceConnect0/deviceConnect0.js

@@ -43,6 +43,7 @@ Page({
       })
     }
   },
+
   getBluetoothStatusCallck(v) {
     this.setData({
       scopeBluetooth: v

+ 17 - 48
pages/deviceConnect1/deviceConnect1.js

@@ -22,20 +22,23 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad() {
-    
+
   },
+
   getBluetoothStatus() {
     app.getBluetoothStatus();
   },
+
   setPwd: function (e) {
     app.globalData.pwdData = e.detail.value;
     this.setData({
       pwdData: e.detail.value,
     });
   },
+
   setSsid: function (e) {
     let str = false;
-    if(e.detail.value.indexOf("5G") !== -1) {
+    if (e.detail.value.indexOf("5G") !== -1) {
       str = true;
     };
     this.setData({
@@ -43,18 +46,19 @@ Page({
       is5GWifi: str
     });
   },
-  getWifiStatus(){
+
+  getWifiStatus() {
     const _this = this;
     wx.getNetworkType({
-      success (res) {
-        if(res.networkType === "wifi") {
+      success(res) {
+        if (res.networkType === "wifi") {
           wx.startWifi({
             success(res) {
               //获取当前已连接wifi名
               wx.getConnectedWifi({
                 success: function (res) {
                   // 5Gwifi
-                  if(res.wifi.SSID.indexOf("5G") !== -1) {
+                  if (res.wifi.SSID.indexOf("5G") !== -1) {
                     _this.setData({
                       is5GWifi: true
                     });
@@ -69,9 +73,9 @@ Page({
                   app.globalData.ssid = res.wifi.SSID;
                   wx.getStorage({
                     key: 'wifiInfo',
-                    success (wifiInfo) {
+                    success(wifiInfo) {
                       const resData = JSON.parse(wifiInfo.data);
-                      if(resData.ssid === res.wifi.SSID) {
+                      if (resData.ssid === res.wifi.SSID) {
                         _this.setData({
                           pwdData: resData.password,
                         });
@@ -83,12 +87,12 @@ Page({
             }
           })
         }
-        
+
       }
     })
   },
-  next(){
-    if(this.data.ssid === ""){
+  next() {
+    if (this.data.ssid === "") {
       wx.showToast({
         title: '请输入WIFI名称',
         icon: 'none',
@@ -96,7 +100,7 @@ Page({
       })
       return;
     };
-    if(this.data.pwdData === ""){
+    if (this.data.pwdData === "") {
       wx.showToast({
         title: '请输入WIFI密码',
         icon: 'none',
@@ -110,7 +114,7 @@ Page({
       url: './../deviceConnect2/deviceConnect2',
     })
   },
-  notRoter(){
+  notRoter() {
     wx.navigateBack({
       delta: 1
     });
@@ -133,39 +137,4 @@ Page({
   onShow() {
     this.getWifiStatus();
   },
-
-  /**
-   * 生命周期函数--监听页面隐藏
-   */
-  onHide() {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面卸载
-   */
-  onUnload() {
-
-  },
-
-  /**
-   * 页面相关事件处理函数--监听用户下拉动作
-   */
-  onPullDownRefresh() {
-
-  },
-
-  /**
-   * 页面上拉触底事件的处理函数
-   */
-  onReachBottom() {
-
-  },
-
-  /**
-   * 用户点击右上角分享
-   */
-  onShareAppMessage() {
-
-  }
 })

+ 2 - 1
pages/deviceConnect2/deviceConnect2.js

@@ -54,7 +54,6 @@ Page({
     switch (options.type) {
       case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
         // 搜索到蓝牙
-        // console.log("gadsfadsfadsfa==xxx===" + JSON.stringify(options));
         if (options.result) {
           if (options.data.filter((v) => v.name.indexOf("BLUFI_") !== -1).length > 0) {
             _this.setData({
@@ -138,6 +137,8 @@ Page({
     //   return;
     // };
 
+    // [{"deviceId":"7C:DF:A1:FC:BB:26","name":"BLUFI_7cdfa1fcbb24","RSSI":-51,"connectable":true,"advertisData":"","advertisServiceUUIDs":["0000FFFF-0000-1000-8000-00805F9B34FB"],"localName":"BLUFI_7cdfa1fcbb24","serviceData":{}}]
+
     const deviceIdData = this.data.devicesList;
     if (deviceIdData.length < 1) {
       wx.showToast({

+ 1 - 1
project.private.config.json

@@ -25,5 +25,5 @@
       ]
     }
   },
-  "libVersion": "2.25.4"
+  "libVersion": "3.6.6"
 }