Pārlūkot izejas kodu

feature:更新壁纸的流程

zeng.chen 6 mēneši atpakaļ
vecāks
revīzija
3ab93fb5ae
3 mainītis faili ar 60 papildinājumiem un 63 dzēšanām
  1. 7 3
      devices/bluetooth/bt_cmd.js
  2. 40 52
      pages/ota/ota.js
  3. 13 8
      pages/piano/cropper/cropper.js

+ 7 - 3
devices/bluetooth/bt_cmd.js

@@ -185,8 +185,12 @@ class BtCmd {
         // return [115, 109, 97, 114, 116, 95, 65, 50, 70]
         // return [115, 109, 97, 114, 116, 95, 65, 50, 70]
         // 73 6D 61 72 74 5F 41 32 46
+        if (!text) {
+            return []
+        }
+        console.log("stringToUint8Array", text)
         let code = Array.from(text).map(char => char.charCodeAt(0));
-        console.log("stringToUint8Array", text, code)
+        console.log("stringToUint8Array", code)
         return code
     }
     static listInt2String(data) {
@@ -290,7 +294,7 @@ class BtCmd {
             result.splice(i, 0, pwdList[j++]);
         }
 
-        console.log("发送wifi账号密码:", result.toString());
+        console.log("发送转换拼接数据:", result.toString());
         return result;
     }
 
@@ -298,7 +302,7 @@ class BtCmd {
     // 壁纸指令 1开始, 0结束
     static wallPaper(value) {
         let cmd = this._build(CmdBase.wallPaper, [value]);
-        console.log("结束图片上传:", cmd);
+        console.log("图片上传:", cmd);
         return cmd;
     }
     static wallPaperMD5(value) {

+ 40 - 52
pages/ota/ota.js

@@ -126,16 +126,6 @@ Page({
     let url = this.data.otaData.url ?? ""
     let codeUrl = BtCmd.stringToUint8Array(url)
     BtHelper.getInstance().otaUrl(codeUrl);
-    wx.showModal({
-      title: '发送成功',
-      content: '开始升级OTA,请等待设备升级成功',
-      showCancel: false,
-      success: (res) => {
-        if (res.confirm) {
-          route_util.goBack()
-        }
-      }
-    })
   },
 
   // 读取文件废弃代码
@@ -350,6 +340,36 @@ Page({
       });
     }
   },
+  otaSuccess() {
+    wx.hideLoading();
+    // 流程成功
+    wx.showModal({
+      title: '设备开始升级中',
+      showCancel: false,
+      success: function (res) {
+        if (res.confirm) {
+          wx.navigateBack({
+            delta: 3
+          })
+        }
+      }
+    })
+  },
+  otaFailure() {
+    wx.hideLoading();
+    // 流程失败
+    wx.showModal({
+      title: '设备升级失败了',
+      showCancel: false,
+      success: function (res) {
+        if (res.confirm) {
+          wx.navigateBack({
+            delta: 3
+          })
+        }
+      }
+    })
+  },
   addNotification() {
     let _this = this;
     EventManager.addNotification(CmdEvent.eventName, function (event) {
@@ -372,67 +392,35 @@ Page({
             // 去设置wifi界面
             _this.goToWifi()
           } else if (otaCmd === 0 && kind == 3) {
-            wx.hideLoading();
-            // 流程失败
-            wx.showModal({
-              title: '设备升级失败了',
-              showCancel: false,
-              success: function (res) {
-                if (res.confirm) {
-                  wx.navigateBack({
-                    delta: 2
-                  })
-                }
-              }
-            })
+            _this.otaFailure()
           } else if (otaCmd === 0 && kind == 1) {
-            wx.hideLoading();
-            // 流程成功
-            wx.showModal({
-              title: '设备开始升级中',
-              showCancel: false,
-              success: function (res) {
-                if (res.confirm) {
-                  wx.navigateBack({
-                    delta: 2
-                  })
-                }
-              }
-            })
+            _this.otaSuccess()
           }
           else if (kind == 0) {
-            wx.hideLoading()
-            wx.showModal({
-              title: 'WIFI连接失败了',
-              showCancel: false
-            })
+
           }
           break;
         case EnumCmdEvent.otaUrl:
           // 小程序发:0x75,  0
           if (otaCmd === 1 && kind == 1) {
-            _this.sendOtaCmd(0)
+            // _this.sendOtaCmd(0)
+            _this.otaSuccess()
             // BtHelper.getInstance().otaUrl(BtCmd.stringToUint8Array(_this.data.otaData.url))
           } else {
-            wx.hideLoading()
-            // wifi失败
-            wx.showModal({
-              title: 'OTA升级失败了',
-              showCancel: false
-            })
+            _this.otaFailure()
+
           }
           break;
         case EnumCmdEvent.otaWifi:
+          //0x76 
           wx.hideLoading()
           // 0x76, 发送wifi成功
           if (otaCmd === 1 && kind == 1) {
             _this.sendUrlData()
           } else {
             // wifi失败
-            wx.showModal({
-              title: 'OTA升级失败了',
-              showCancel: false
-            })
+            _this.otaFailure()
+
           }
           break;
       }

+ 13 - 8
pages/piano/cropper/cropper.js

@@ -173,7 +173,7 @@ Page({
 
         fs.getFileInfo({
           "filePath": url, "digestAlgorithm": "md5", success: (res) => {
-            console.log("md5:", res.digest)
+            console.log("md5:", res)
             console.log("加载文件成功:", obj.data.byteLength, obj.data.length, obj.getFileInfo)
 
             let binData = obj.data;
@@ -186,6 +186,7 @@ Page({
               title: '开始传输壁纸',
             })
             _this.data._imgMD5 = res.digest
+            console.log("md5 2:", _this.data._imgMD5)
             _this.startImage()
           }
         })
@@ -234,7 +235,7 @@ Page({
           console.log("加载文件成功:", obj.data.byteLength, obj.data.length)
 
           fs.getFileInfo({
-            "filePath": url, "digestAlgorithm": "md5", success: (res) => {
+            "filePath": _this.data._imgUrl, "digestAlgorithm": "md5", success: (res) => {
               console.log("md5:", res)
               console.log("加载文件成功:", obj.data.byteLength, obj.data.length, obj.getFileInfo)
 
@@ -247,8 +248,12 @@ Page({
               wx.showLoading({
                 title: '开始传输壁纸',
               })
+              _this.data._imgMD5 = res.digest
+              console.log("md5 2:", _this.data._imgMD5)
               _this.startImage()
-            }
+            }, fail: (err) => {
+              console.error('getFileInfo失败:', err);
+            },
           })
 
         },
@@ -350,7 +355,7 @@ Page({
     });
   },
   async startImage() {
-
+    console.log("开始发送壁纸数据: 0x78",)
     BtHelper.sendCallBack(BtCmd.wallPaper(1), function (res) {
       if (!res) {
         wx.hideLoading()
@@ -379,10 +384,10 @@ Page({
     this.data._chunks = chunks;
   },
   sendImageMD5() {
-    let md5Code = BtCmd.stringToUint8Array(this.data._imgMD5)
-    let lengthCode = BtCmd.intToHex(this.data.length)
-    let value = BtCmd.sendWiFiInfo(md5Code, lengthCode)
-
+    let lengthCode = this.data._chunks.length
+    console.log("发送壁纸MD5 1:", lengthCode, this.data._imgMD5)
+    let value = BtCmd.sendWiFiInfo("99", this.data._imgMD5)
+    console.log("发送壁纸MD5 2:", value)
     BtHelper.sendCallBack(BtCmd.wallPaperMD5(value), function (res) {
       if (!res) {
         wx.hideLoading()