Przeglądaj źródła

feature:修改壁纸的传输数据方法

zeng.chen 7 miesięcy temu
rodzic
commit
4d24b41fac

+ 3 - 3
devices/QueueManager.js

@@ -5,7 +5,7 @@ class QueueManager {
         this._tasks = [];
         this._listenMap = {};
         this._timer = null;
-        this._interval = 200;
+        this._interval = 20;
     }
 
     // static get instance() {
@@ -50,14 +50,14 @@ class QueueManager {
     }
 
     clear() {
-//        console.log('QueueManager======clear======');
+        //        console.log('QueueManager======clear======');
         if (this._tasks.length > 0) {
             this._tasks.length = 0;
         }
     }
 
     dispose() {
-//        console.log('QueueManager======dispose======');
+        //        console.log('QueueManager======dispose======');
         this.clear();
         if (this._timer) {
             clearInterval(this._timer);

+ 22 - 9
devices/ble_manager.js

@@ -62,7 +62,9 @@ class bleManager {
         if (that.callBackConnect != null) {
           if (that.connectWillDevice != null && res.name == that.connectWillDevice.clientType) {
             res.mac = res.advertisData ? that.buf2hex(res.advertisData) : '';
-            if (that.callBackConnect != null) {
+            // if (that.callBackConnect != null) {
+            console.log("1111", res.mac);
+            if (that.callBackConnect != null && res.mac.includes("D4:D7")) {
               that.callBackConnect(res);
             }
           }
@@ -94,6 +96,8 @@ class bleManager {
             //            }
             if (that.connectWillDevice != null && temp.name == that.connectWillDevice.clientType) {
               temp.mac = temp.advertisData ? that.buf2hex(temp.advertisData) : '';
+              // if (that.callBackConnect != null) {
+              // console.log("2222", temp.mac);
               if (that.callBackConnect != null) {
                 that.callBackConnect(temp);
               }
@@ -126,7 +130,11 @@ class bleManager {
         if (that.callBackConnect != null) {
           if (that.connectWillDevice != null && res[0].name == that.connectWillDevice.clientType) {
             res[0].mac = res[0].advertisData ? that.buf2hex(res[0].advertisData) : '';
-            if (that.callBackConnect != null) {
+            // if (that.callBackConnect != null) {
+            console.log("3333", res.mac);
+
+            if (that.callBackConnect != null && res.mac.includes("D4:D7")) {
+
               that.callBackConnect(res[0]);
             }
           }
@@ -196,7 +204,12 @@ class bleManager {
             var temp = res.devices[i];
             if (that.connectWillDevice != null && temp.name == that.connectWillDevice.clientType) {
               temp.mac = temp.advertisData ? that.buf2hex(temp.advertisData) : '';
-              if (that.callBackConnect != null) {
+              if (temp.mac) {
+                console.log("搜索到的" + JSON.stringify(temp));
+              }
+              // if (that.callBackConnect != null) {
+              if (that.callBackConnect != null && temp.mac.includes("D4:D7")) {
+                // if (that.callBackConnect != null && temp.mac.includes("CF:CA")) {
                 that.callBackConnect(temp);
               }
               break;
@@ -476,7 +489,7 @@ class bleManager {
       });
       // }
 
-      console.log('开始发送数据:', data, buffer);
+      // console.log('开始发送数据:', data);
       wx.writeBLECharacteristicValue({
         deviceId: that.publicDevice.deviceId,
         serviceId: that.publicDevice.serviceId,
@@ -487,14 +500,14 @@ class bleManager {
           if (callback) {
             callback(true)
           }
-          resolve(res);
+          resolve(true);
         },
         fail: (err) => {
           if (callback) {
             callback(false)
           }
-          console.error('数据发送失败:', err);
-          reject(new Error('数据发送失败'));
+          console.log('数据发送失败:', err);
+          resolve(false);
         }
       });
     });
@@ -592,7 +605,7 @@ class bleManager {
     });
   }
 
-  connect() {}
+  connect() { }
 
   // 发现特征值 read / write
   discoverCharacteristics(deviceId, serviceId) {
@@ -669,7 +682,7 @@ class bleManager {
             dataResult.push(dataView.getUint8(i))
           }
           const result = dataResult
-          console.log("拿到的数据:", result)
+          // console.log("拿到的数据:", result)
 
           if (callback) {
             callback(result)

+ 3 - 1
devices/bluetooth/bt_cmd.js

@@ -245,7 +245,9 @@ class BtCmd {
     }
     // 壁纸指令 
     static wallPaperData(value) {
-        return this._build(CmdBase.wallPaperData, [value]);
+        let cmd = this._build(CmdBase.wallPaperData, value);
+        // console.log("发送图片数据:", value)
+        return cmd;
     }
     // 背景图指令 1开始, 0结束
     static backgroudImg(value) {

+ 1 - 1
devices/bluetooth/bt_parse.js

@@ -75,7 +75,7 @@ class BtParse {
                     // 控制指令
                     BtParse._controlCmd(cmd);
                 } else {
-                    console.log("收到不明指令:", cmd);
+                    // console.log("收到不明指令:", cmd);
                     const manufacturer = "";
                     // DeviceManager.instance.device?.manufacturer ?? "";
 

+ 28 - 18
devices/bt_helper.js

@@ -141,18 +141,18 @@ class BtHelper {
         mDevice.volume = volume;
         break;
 
-        ///电量
+      ///电量
       case EnumCmdEvent.battery:
         mDevice.kwh = event.kwh;
         break;
 
-        ///低时延模式  低时延模式开启 1:音乐 , 2: 游戏 , 3: movie
+      ///低时延模式  低时延模式开启 1:音乐 , 2: 游戏 , 3: movie
       case EnumCmdEvent.lowDelayMode:
         mDevice.lowDelayMode = event.lowDelayMode;
         mDevice.lowDelayModeOpen = event.lowDelayModeOpen;
         break;
 
-        ///电量 耳机电量
+      ///电量 耳机电量
       case EnumCmdEvent.batteryEarphone:
         mDevice.kwh = event.kwh;
         mDevice.kwhLeft = event.kwhLeft;
@@ -160,12 +160,12 @@ class BtHelper {
         mDevice.kwhBox = event.kwhBox;
         break;
 
-        ///是否支持TTS
+      ///是否支持TTS
       case EnumCmdEvent.enableTTS:
         mDevice.enableTTS = event.enableTTS;
         break;
 
-        ///切换设备连接模式 0:未知 1:低功耗蓝牙 2:wifi类型 3:经典蓝牙(不做任何操作) 4:4G类型
+      ///切换设备连接模式 0:未知 1:低功耗蓝牙 2:wifi类型 3:经典蓝牙(不做任何操作) 4:4G类型
       case EnumCmdEvent.switchDeviceMode:
         var deviceMode = event.deviceMode.index;
         if (deviceMode != null) {
@@ -174,14 +174,14 @@ class BtHelper {
         }
         break;
 
-        ///4G外插卡  4G虚拟卡 当前使用的sim卡
+      ///4G外插卡  4G虚拟卡 当前使用的sim卡
       case EnumCmdEvent.sim:
         mDevice.sim = event.sim;
         mDevice.eSim = event.eSim;
         mDevice.simIndex = event.simIndex;
         break;
 
-        ///闹钟是否开启  闹钟周期 闹钟唤醒时间
+      ///闹钟是否开启  闹钟周期 闹钟唤醒时间
       case EnumCmdEvent.wake:
         mDevice.wakeSwitch = event.wakeSwitch;
         mDevice.wakeCycle = event.wakeCycle;
@@ -189,14 +189,14 @@ class BtHelper {
         mDevice.wakeMinutes = event.wakeMinutes;
         break;
 
-        ///休眠是否开启 休眠时间
+      ///休眠是否开启 休眠时间
       case EnumCmdEvent.sleep:
         mDevice.sleepSwitch = event.sleepSwitch;
         mDevice.sleepHour = event.sleepHour;
         mDevice.sleepMinutes = event.sleepMinutes;
         break;
 
-        ///版本和型号
+      ///版本和型号
       case EnumCmdEvent.version:
         mDevice.version = event.version;
         var clientType = mDevice.clientType ?? "";
@@ -229,7 +229,7 @@ class BtHelper {
         // }
         break;
 
-        ///云小微授权
+      ///云小微授权
       case EnumCmdEvent.auth:
         var authInfo = event.authInfo;
         mDevice.authInfo = authInfo;
@@ -245,17 +245,17 @@ class BtHelper {
         // });
         break;
 
-        ///EQ音效
+      ///EQ音效
       case EnumCmdEvent.eq:
         mDevice.eqs = event.eqs;
         break;
 
-        ///payId 充流量使用
+      ///payId 充流量使用
       case EnumCmdEvent.payId:
         mDevice.payId = event.payId;
         break;
 
-        ///QQ音乐使用dsn授权
+      ///QQ音乐使用dsn授权
       case EnumCmdEvent.dsn:
         var dsn = event.dsn;
         mDevice.dsn = dsn;
@@ -264,13 +264,13 @@ class BtHelper {
         // ProviderUtil.twelvePublic.wifiDeviceConnected();
         break;
 
-        ///自动切换 0,1不能
-        ///
+      ///自动切换 0,1不能
+      ///
       case EnumCmdEvent.netModeAuto:
         mDevice.netModeAuto = event.netModeAuto;
         break;
 
-        ///解绑设备
+      ///解绑设备
       case EnumCmdEvent.unbind:
         //   let unbindAddress = event.item.address ?? "";
         //     if (unbindAddress != mDevice.address) {
@@ -286,7 +286,7 @@ class BtHelper {
 
         break;
 
-        ///解绑设备
+      ///解绑设备
       case EnumCmdEvent.ctrlStatus:
         // List < int > ctrlList = event.ctrlStatus;
         // if (ctrlList.length == 3) {
@@ -308,7 +308,7 @@ class BtHelper {
         // notifyListeners();
         break;
 
-        ///设备信息
+      ///设备信息
       case EnumCmdEvent.getDeviceInfo:
         //   List list = [];
         //   String userId = ProviderUtil.user.userModel.uid ?? "";
@@ -744,8 +744,18 @@ class BtHelper {
   }
   // 壁纸指令 
   wallPaperData(value, callback) {
+    // this.send(BtCmd.wallPaperData(value));
     BtHelper.sendCallBack(BtCmd.wallPaperData(value), callback);
   }
+
+  // 壁纸指令 
+  async wallPaperSyncData(value) {
+    // this.send(BtCmd.wallPaperData(value));
+    // BtHelper.sendCallBack(BtCmd.wallPaperData(value), callback);
+    return await this.bleManager.sendData(BtCmd.wallPaperData(value))
+
+  }
+
   // 背景图指令
   backgroudImg(value) {
     var that = this;

+ 2 - 2
pages/deviceDetail/detail.js

@@ -108,11 +108,11 @@ Page({
     this.setData({
       device: device,
       powerOpen: (device.pauseSleep ?? -1) > 0,
-      isShowWallpaper: device.clientType === 'MW-S2(BLE)'
+      isShowWallpaper: device.clientType === '猫王妙播黑胶音箱(BLE)'
     })
 
     const btHelper = BtHelper.getInstance();
-    let isShowOta = device.clientType === 'MW-S2(BLE)' || device.clientType === 'MW-S2'
+    let isShowOta = device.clientType === '猫王妙播黑胶音箱(BLE)' || device.clientType === 'MW-S2'
     if (isShowOta) {
       btHelper.getVersion()
     }

Plik diff jest za duży
+ 26 - 17
pages/deviceList/deviceList.js


+ 7 - 7
pages/index/index.js

@@ -34,11 +34,11 @@ Page({
     isLogin: false,
     greeting: "",
     bannerList: [{
-        "pic": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20241028142233669038262.png"
-      },
-      {
-        "pic": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20240823145816541223911.png"
-      }
+      "pic": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20241028142233669038262.png"
+    },
+    {
+      "pic": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20240823145816541223911.png"
+    }
     ],
     autoplay: true,
     interval: 3000, // 切换时间间隔
@@ -177,7 +177,7 @@ Page({
       case "connect":
         lexin_subscribe.subscribeAllDevice();
         break;
-        ///再走有在线
+      ///再走有在线
       case "message_onoffline":
         lexin_connect.searchOnlineDevice(payloads, function (list) {
           that.updateDeviceList(list, false, false);
@@ -415,7 +415,7 @@ Page({
 
     ///去蓝牙连接处理
     if (index === deviceListSelect) {
-      route_util.jumpParam('/pages/deviceDetail/detail', JSON.stringify(item))
+      route_util.jumpParam('/pages/deviceDetail/detail', JSON.stringify(device))
     } else if (device.state === "offline") {
       console.log("去连接蓝牙")
     } else {

+ 1 - 1
pages/ota/ota.js

@@ -266,7 +266,7 @@ Page({
     let next = index + chunkSize;
     const chunk = imageBuffer.slice(index, next);
     BtHelper.getInstance().wallPaperData(chunk, function (res) {
-      console.log("发送图片数据:", next)
+      console.log("发送OTA数据:", next)
       if (res) {
         _this.updateProgress(next, total);
 

+ 50 - 23
pages/piano/cropper/cropper.js

@@ -122,7 +122,8 @@ Page({
       encoding: 'base64',
       success: (res) => {
         // const base64Data = 'data:image/png;base64,' + res.data;
-        let rgbData = _this.RGBAtoRGB565(res.data)
+        // let rgbData = _this.RGBAtoRGB565(res.data)
+        let rgbData = res.data
         console.log("转换rgb:", rgbData.length)
         _this.data._imageBuffer = rgbData;
         wx.hideLoading();
@@ -138,7 +139,15 @@ Page({
   },
 
   startImage() {
-    BtHelper.getInstance().sendData(BtCmd.wallPaper(1));
+    BtHelper.getInstance().send(BtCmd.wallPaper(1));
+  },
+  sliceDataIntoChunks(data, chunkSize) {
+    const chunks = [];
+    for (let i = 0; i < data.length; i += chunkSize) {
+      const chunk = data.slice(i, i + chunkSize);
+      chunks.push(chunk);
+    }
+    return chunks;
   },
   startSendImage(imageBuffer) {
     if (imageBuffer == null) {
@@ -149,33 +158,49 @@ Page({
       _this.endImage(2)
       return;
     }
-    _this.sendImage(imageBuffer, 0)
+    // _this.sendImage(imageBuffer, 0)
+
     // }
-  }, sendImage(imageBuffer, index) {
+  },
+  async sendImage(imageBuffer, index) {
     let _this = this
 
-    if (index >= chunkSize) {
-      _this.endImage(0)
-      return;
-    }
+    // if (index >= chunkSize) {
+    //   wx.showModal({
+    //     title: '图片上传成功1',
+    //     showCancel: false
+    //   })
+    //   _this.endImage(0)
+    //   return;
+    // }
 
-    let chunkSize = 20;
+    let chunks = this.sliceDataIntoChunks(imageBuffer, 20);
 
-    let total = imageBuffer.length
-    let next = index + chunkSize;
-    const chunk = imageBuffer.slice(index, next);
-    BtHelper.getInstance().wallPaperData(chunk, function (res) {
-      console.log("发送图片数据:", sendImage)
-      _this.updateProgress(next, total);
-      if (res) {
-        _this.sendImage(imageBuffer)
-      } else {
+    let next = 0;
+    let total = imageBuffer.length;
+    for (let i = 0; i < chunks.length; i++) {
+      const chunk = chunks[i];
+      next += chunk.length;
+      console.log("发送图片数据:", i, next, chunk)
+
+      let res = await BtHelper.getInstance().wallPaperSyncData(chunk);
+      let nowDate = Date.now()
+      if (i === chunks.length - 1 && res) {
+        wx.showModal({
+          title: '图片上传成功' + i + " / " + nowDate,
+          showCancel: false
+        })
+        _this.endImage(0)
+      } else if (!res) {
         wx.showModal({
           title: '图片上传失败了',
           showCancel: false
         })
+        _this.endImage(2)
+        break;
       }
-    })
+      _this.updateProgress(next, total);
+    }
 
   },
   endImage(value) {
@@ -188,9 +213,9 @@ Page({
     })
   },
   updateProgress(chunk, total) {
-    let progress = chunk / total * 100;
+    let progress = chunk / total;
     let _this = this
-    if (progress >= 100) {
+    if (chunk >= total) {
       _this.setData({
         progress: 0,
         showProgress: false,
@@ -199,6 +224,8 @@ Page({
       wx.showToast({
         title: '图片上传成功',
       })
+      _this.endImage(0)
+
     } else {
       _this.setData({
         progress: progress,
@@ -232,11 +259,11 @@ Page({
 
           if (otaCmd === 1 && kind == 1) {
             // 开始发送
-            _this.sendImage(_this.data._imageBuffer)
+            _this.sendImage(_this.data._imageBuffer, 0)
             _this.startProgress()
           } else if (otaCmd === 0 && kind == 1) {
             // 发送结束
-            _this.endImage(0)
+            // _this.endImage(0)
           } else if (kind == 0) {
             wx.hideLoading()
             wx.showModal({