Browse Source

Merge branch 'develop/3.2.4_黑胶' of http://60.205.190.38:9000/zhaoheqing/wxmini into develop/3.2.4_黑胶

332777428@qq.com 6 tháng trước cách đây
mục cha
commit
bf14fb7923

+ 21 - 17
devices/ble_manager.js

@@ -103,6 +103,7 @@ class bleManager {
               // if (that.callBackConnect != null) {
               console.log("2222:", temp.mac, ":", temp.mac2, ":", temp.deviceId, temp);
               if (that.callBackConnect != null) {
+                // if (that.callBackConnect != null && (temp.deviceId != "6E:66:C2:CA:74:F8" || temp.deviceId != "1A:B4:E0:40:22:8B")) {
                 that.callBackConnect(temp);
               }
               break;
@@ -163,9 +164,11 @@ class bleManager {
         }
       }
     });
-
+  }
+  onBLEConnectionStateChange(callback) {
     ///监听已连接或没有连接 连接和断开的时候会回调
     // {"deviceId":"E4:9F:80:09:40:EC","connected":false}
+    let that = this;
     wx.onBLEConnectionStateChange((result) => {
       if (result.connected) {
         for (var i = 0; i < that.dissmissDevice.length; i++) {
@@ -185,6 +188,12 @@ class bleManager {
         if (!has) {
           that.dissmissDevice.push(result);
         }
+
+      }
+      // that.disconnect(result)
+      //断开连接是失败的, 只能监听到下线。
+      if (callback != null) {
+        callback(result);
       }
 
       // ///是否已配对
@@ -451,27 +460,18 @@ class bleManager {
     if (strings.isEmpty(deviceId)) {
       return;
     }
-    console.log('断开连接', device);
+    console.log('开始断开连接', device);
 
     return new Promise((resolve, reject) => {
-      wx.getConnectedBluetoothDevices({
+      wx.closeBLEConnection({
+        deviceId: deviceId,
         success: (res) => {
-          if (res.devices.length > 0) {
-            wx.closeBLEConnection({
-              deviceId: deviceId,
-              success: (res) => {
-                that.publicDevice = null;
-                resolve(res);
-              },
-              fail: (err) => {
-                resolve(err);
-              }
-            });
-          } else {
-            resolve("暂无连接设备");
-          }
+          console.log('成功断开连接', res);
+          that.publicDevice = null;
+          resolve(res);
         },
         fail: (err) => {
+          console.log('断开连接失败', err);
           resolve(err);
         }
       });
@@ -537,6 +537,7 @@ class bleManager {
             callback(false)
           }
           console.log('数据发送失败:', err);
+          that.errorDisconnect()
           resolve(false);
         }
       });
@@ -731,6 +732,9 @@ class bleManager {
     // that.publicDevice .wirte = wirte
     that.publicDevice.characteristicId = characteristicId;
   }
+  errorDisconnect() {
+    this.disconnect();
+  }
 }
 // const ble = new bleManager();
 

+ 10 - 1
devices/bt_helper.js

@@ -21,6 +21,7 @@ const BtParse = require('./../devices/bluetooth/bt_parse');
 // const CmdBase = require('./../devices/bluetooth/bt_cmd');
 const bleManager = require('./ble_manager');
 const QueueManager = require('./QueueManager');
+const event_bus = require('./../utils/event_bus');
 
 // const EnumConnectStatus = require('./EnumConnectStatus');
 // const EnumOpen = require('./EnumOpen');
@@ -92,6 +93,14 @@ class BtHelper {
     that.bleManager.initBluetoothAdapter();
   }
 
+  onConnectionStateChange(callback) {
+    var that = this;
+    that.bleManager.onBLEConnectionStateChange(function (e) {
+
+      event_bus.fire(CmdEvent.onoffline({ deviceId: e.deviceId, state: e.connected ? "online" : "offline" }));
+    });
+  }
+
   ///获取蓝牙设备 connect:true,去连接,false,去对比
   getBluetoothDevices() {
     var that = this;
@@ -369,7 +378,7 @@ class BtHelper {
 
   async connect(device, onChanged) {
     var that = this;
-    await that.disconnect(device);
+    // await that.disconnect(device);
     clearTimeout(that.timer);
     that.timer = null;
     that.bleManager.stopSearch()

+ 9 - 0
devices/cmd_key_event.js

@@ -52,6 +52,7 @@ const EnumCmdEvent = {
     wallpaper: 'wallpaper',
     wallPaperData: 'wallPaperData',
     wallPaperMD5: 'wallPaperMD5',
+    onoffline: 'onoffline',
 };
 
 // 枚举定义
@@ -131,6 +132,8 @@ class CmdEvent {
         this.otaUrl = null;
         this.heiJiaoKind = null;
         this.wallpaper = null;
+        this.deviceId = null;
+        this.commonValue = null;
     }
 
     static eventName = "cmdEventNotification"
@@ -401,6 +404,12 @@ class CmdEvent {
         event.audioInfoId = audioInfoId;
         return event;
     }
+    static onoffline({ deviceId, state }) {
+        const event = new CmdEvent({ cmdEvent: EnumCmdEvent.onoffline });
+        event.commonValue = state;
+        event.deviceId = deviceId;
+        return event;
+    }
 
     static playStatus({ playStatus }) {
         const event = new CmdEvent({ cmdEvent: EnumCmdEvent.playStatus });

+ 5 - 0
pages/deviceDetail/detail.js

@@ -144,6 +144,11 @@ Page({
             powerOpen: (value ?? -1) > 0
           })
           break;
+        case EnumCmdEvent.onoffline:
+          console.log("详情页3:")
+          //目前只有下线
+          _this.data.device.state = "offline"
+          break;
       }
     }, this)
   },

+ 3 - 3
pages/deviceDetail/detail.wxml

@@ -2,7 +2,7 @@
 <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>
     <view class="img_section">
-        <image src="{{device.img}}" class="avatar"></image>
+        <image src="{{device.imageUrl}}" class="avatar"></image>
         <!-- <image src="https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20220909100711728016597.png" class="avatar"></image> -->
     </view>
     <view class="section">
@@ -11,13 +11,13 @@
             <!-- <text class="arrow">></text> -->
             <image class="arrow" src="../../images/common/icon_arrow.png"></image>
         </view>
-        <view class="item" bindtap="goToAccountSecurity">
+        <!-- <view class="item">
             <view class="left-content">
                 <text class="label">省电模式</text>
                 <image class="question" bind:tap="questionTap" src="../../images/common/icon_question.png"></image>
             </view>
             <switch class="switch" color="#6546A3" checked="{{powerOpen}}" bindchange="powerTap" />
-        </view>
+        </view> -->
         <view class="item" bindtap="goToOta">
             <view class="left-content">
                 <text class="label">固件信息</text>

+ 27 - 0
pages/index/index.js

@@ -22,6 +22,11 @@ import lexin_message from '../../utils/lexin/message.js';
 import {
   BtHelper
 } from '../../devices/bt_helper.js';
+import event_bus from '../../utils/event_bus.js';
+import {
+  EnumCmdEvent,
+  CmdEvent
+} from '../../devices/cmd_key_event';
 
 Page({
   data: {
@@ -745,6 +750,26 @@ Page({
       deviceListSelect: 0,
       autoConnected: true,
     });
+    event_bus.removeNotification(CmdEvent.eventName, that);
+    event_bus.addNotification(CmdEvent.eventName, function (event) {
+      if (event.cmdEvent == EnumCmdEvent.onoffline) {
+        if (tmp.connected != false) {
+          return
+        }
+        let disDevice = that.data.deviceList.find(item => {
+          return item.deviceId == event.deviceId
+        })
+        // that.data.deviceList.forEach(element => {
+        //   if (item.deviceId == tmp.deviceId) {
+
+        //   }
+        // });
+        disDevice.state = event.commonValue;
+        console.log("断开连接", disDevice)
+        that.updateDeviceList(that.data.deviceList, false, false);
+      }
+
+    });
   },
 
   // 新添加Wifi设备
@@ -1002,6 +1027,7 @@ Page({
   ///销毁蓝牙
   onUnload() {
     var that = this;
+    event_bus.removeNotification(CmdEvent.eventName, that)
     that.stopIntervalId1();
     that.stopIntervalId2();
     if (!strings.isEmpty(that.data.intervalId)) {
@@ -1015,5 +1041,6 @@ Page({
     app.globalData.client.end(true);
     app.globalData.client.end(true);
     app.globalData.client = null;
+
   },
 })

+ 52 - 27
pages/piano/cropper/cropper.js

@@ -189,9 +189,11 @@ Page({
               // let myMd5 = _this.getImgMd5(binData)
               // let my2Md5 = _this.getImg2Md5(binData)
               // let my3Md5 = _this.getImg3Md5(binData)
+              // todo 测试用
               wx.setClipboardData({
                 data: res2.digest,
               })
+
               _this.sliceDataIntoChunks(binData, 64);
 
               console.log("加载文件成功2:", binData.byteLength, binData.length)
@@ -265,6 +267,7 @@ Page({
           // 用户已授权访问相册
           console.log('用户已授权访问相册2');
           // 可以在这里执行访问相册的操作
+          _this.upload()
         }
       }
     });
@@ -321,6 +324,12 @@ Page({
       }
     });
   },
+  // 切分高位和低位
+  splitHighLowBytes(value) {
+    let highByte = (value >> 8) & 0xFF;
+    let lowByte = value & 0xFF;
+    return { highByte, lowByte };
+  },
   async sendImage(index) {
     let _this = this
 
@@ -332,6 +341,14 @@ Page({
     // let i = 0;
     // _this.data._timer = setInterval(async () => {
     if (index > chunks.length - 1) {
+      wx.showModal({
+        title: '壁纸上传完成md5:' + _this.data._imgMD5,
+        content: '最终发送数据大小:' + _this.data._imgNext + ',总大小:' + total + '',
+        showCancel: false,
+        success(res) {
+
+        }
+      })
       _this.endImage(0)
       return;
     }
@@ -339,7 +356,7 @@ Page({
     const chunk = chunks[index];
     _this.data._imgNext += (chunk.byteLength ?? chunk.length);
 
-    // console.log("发送壁纸数据1:", index, ":", _this.data._imgNext, ":", chunk.length, ":", chunk.byteLength, ":", total, chunks.length)
+    console.log("发送壁纸数据1:", index, ":", _this.data._imgNext, ":", chunk.length, ":", chunk.byteLength, ":", total, chunks.length)
 
     let res = await btHelper.wallPaperSyncData(chunk);
     // let res = true;
@@ -397,6 +414,29 @@ Page({
       });
     }
   },
+  successSend() {
+    wx.showModal({
+      title: '上传壁纸成功',
+      showCancel: false,
+      success(res) {
+        if (res.confirm) {
+          const pages = getCurrentPages();
+          // 获取上一级页面实例
+          const prevPage = pages[pages.length - 2];
+          // 传递参数
+          prevPage.setData({
+            topImg: {
+              "pic": _this.data._imgUrl,
+            }
+          });
+          wx.navigateBack({
+            delta: 1,
+          })
+        }
+      }
+    })
+
+  },
   failSend(showToast) {
     let _this = this
     _this.data._chunks = null
@@ -405,9 +445,14 @@ Page({
     _this.data._imgNext = 0
     wx.hideLoading()
     if (showToast) {
-      wx.showModal({
-        title: '壁纸上传失败了',
-        showCancel: false
+      // todo 测试注释的
+      // wx.showModal({
+      //   title: '壁纸上传失败了',
+      //   showCancel: false
+      // })
+      wx.showToast({
+        title: '发送失败',
+        icon: 'failure'
       })
     }
     _this.setData({
@@ -432,9 +477,9 @@ Page({
     this.cropper = this.selectComponent("#image-cropper");
     this.cropper.imgReset();
     let image = options.param
+    let json = JSON.parse(image)
     console.log("裁剪页:", image)
-    if (image.pic) {
-      let json = JSON.parse(image)
+    if (json.pic) {
       this.hasImage(json)
     } else {
       console.log("没有图片")
@@ -477,27 +522,7 @@ Page({
             _this.failSend(true)
           } else if (value === 0 && kind == 1) {
             // 发送完成
-            _this.failSend(false)
-            wx.showModal({
-              title: '上传壁纸成功',
-              showCancel: false,
-              success(res) {
-                if (res.confirm) {
-                  const pages = getCurrentPages();
-                  // 获取上一级页面实例
-                  const prevPage = pages[pages.length - 2];
-                  // 传递参数
-                  prevPage.setData({
-                    topImg: {
-                      "pic": _this.data._imgUrl,
-                    }
-                  });
-                  wx.navigateBack({
-                    delta: 1,
-                  })
-                }
-              }
-            })
+            _this.successSend()
           } else {
             // 发送失败
             _this.failSend(true)