Browse Source

feature:修改OTA,壁纸的流程指令

zeng.chen 8 tháng trước cách đây
mục cha
commit
83deecf819

+ 6 - 1
devices/bluetooth/bt_cmd.js

@@ -122,7 +122,12 @@ class BtCmd {
     }
 
     static setSleepAfterPlayPause(time) {
-        return this._build(CmdRtc.setSleepAfterPlayPause, [time]);
+        const hours = Math.floor(time / (1000 * 60 * 60));
+        const minutes = Math.floor((time % (1000 * 60 * 60)) / (1000 * 60));
+        const seconds = Math.floor((time % (1000 * 60)) / 1000);
+        console.log(`${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`);
+
+        return this._build(CmdRtc.setSleepAfterPlayPause, [hours, minutes, seconds]);
     }
 
     // 设置休眠

+ 19 - 0
devices/bluetooth/bt_parse.js

@@ -475,6 +475,25 @@ class BtParse {
                 console.log("getIsConnect=====", device)
 
                 break;
+
+            case CmdBase.heiJiaoOta:
+                // [84, 68, 68, 72, 1, 10, 54, 2, 0, 1] 
+                {
+                    let kind = cmd[8]
+                    EventManager.fire(CmdEvent.otaCmd({ value: value, kind: kind }));
+
+                }
+
+                break;
+            case CmdBase.heijiaoBackImg:
+                // [84, 68, 68, 72, 1, 10, 54, 2, 0, 1] 
+                {
+                    let kind = cmd[8]
+                    EventManager.fire(CmdEvent.otaCmd({ value: value, kind: kind }));
+
+                }
+
+                break;
             default:
                 console.log("接收到语音:", cmd);
                 // _receiveRecordData(cmd);

+ 3 - 3
devices/bt_helper.js

@@ -515,12 +515,12 @@ class BtHelper {
         this.getAlert();
         this.send(BtCmd.queryRGB());
         this.getVolume();
-        this.setVolume(8)
+        // this.setVolume(8)
         this.getPauseSleep();
 
-        this.send(BtCmd.getClientType());
+        // this.send(BtCmd.getClientType());
         this.send(BtCmd.getIsConnect());
-        this.send(BtCmd.getMac());
+        // this.send(BtCmd.getMac());
 
         // }
     }

+ 5 - 2
devices/cmd_key_event.js

@@ -123,6 +123,7 @@ class CmdEvent {
         this.btMac = null;
         this.deviceMode = null;
         this.otaCmd = null;
+        this.heiJiaoKind = null;
         this.wallpaper = null;
     }
 
@@ -326,14 +327,16 @@ class CmdEvent {
         event.clientType = clientType;
         return event;
     }
-    static otaCmd({ value }) {
+    static otaCmd({ value, Kind }) {
         const event = new CmdEvent({ cmdEvent: EnumCmdEvent.otaCmd });
         event.otaCmd = value;
+        event.heiJiaoKind = Kind;
         return event;
     }
-    static wallpaper({ value }) {
+    static wallpaper({ value, Kind }) {
         const event = new CmdEvent({ cmdEvent: EnumCmdEvent.wallpaper });
         event.wallpaper = value;
+        event.heiJiaoKind = Kind;
         return event;
     }
 

+ 19 - 4
pages/connectBle/connectBle.js

@@ -21,7 +21,8 @@ Page({
     searchTips: "正在搜索设备,请保持开机状态…",
     subTips: "确认手机蓝牙已打开",
     buttonTips: "正在搜索设备",
-    btHelper: null
+    btHelper: null,
+    deviceImg: null,
   },
 
   onLoad(options) {
@@ -64,6 +65,10 @@ Page({
     var subTips = ""
     var buttonTips = ""
     let name = this.data.connectDevice.name;
+    let typeList = this.data.connectDevice.typeList ?? []
+    let bleTypes = typeList.find(v => v.connectType == 1)
+    let deviceLinkResp = bleTypes.deviceLinkResp ?? {}
+
     console.log("搜索状态", bleType)
     switch (bleType) {
       case 0:
@@ -71,30 +76,37 @@ Page({
         searchTips = "正在搜索设备,请保持开机状态…"
         subTips = "确认手机蓝牙已打开"
         buttonTips = "正在搜索设备"
+        deviceImg = deviceLinkResp.icon1
         break;
       case 1:
         // 搜索失败
         searchTips = "未搜索到" + name
         subTips = "请检查设备是否被其他手机连接,或在手机蓝牙忽略掉原来的蓝牙连接重新连接。"
         buttonTips = "重新搜索"
+        deviceImg = deviceLinkResp.icon1
+
         break;
       case 2:
         // 搜索到
         searchTips = "搜索到" + name
         subTips = ""
         buttonTips = "连接"
+        deviceImg = deviceLinkResp.icon2
+
         break;
       case 3:
         // 连接成功
         searchTips = "连接到" + name
         subTips = ""
         buttonTips = "连接成功"
+        deviceImg = deviceLinkResp.icon2
         break;
       case 4:
         // 连接失败
         searchTips = "未连接到" + name
         subTips = "请检查设备是否被其他手机连接,或在手机蓝牙忽略掉原来的蓝牙连接重新连接。"
         buttonTips = "重新搜索"
+        deviceImg = deviceLinkResp.icon1
         break;
     }
 
@@ -102,7 +114,8 @@ Page({
       searchTips: searchTips,
       subTips: subTips,
       buttonTips: buttonTips,
-      connectStatus: bleType
+      connectStatus: bleType,
+      deviceImg: deviceImg
     })
   },
 
@@ -161,7 +174,7 @@ Page({
         console.log('已连接的蓝牙设备:', element);
         _this.didFindDevice(element)
       });
-    } else {}
+    } else { }
     return connectedDevices;
   },
 
@@ -194,7 +207,9 @@ Page({
     if (
       // deviceId.includes("D8:24:07:89:31") ||
       // // 2axk
-      element.deviceId.includes("F5:A5:43:70:C8:F1") ||
+      // element.deviceId.includes("F5:A5:43:70:C8:F1") ||
+      /// sr1
+      element.deviceId.includes("E4:9F:80:09:40:EC") ||
       // 黑色2x
       // element.deviceId.includes("F6:61:D8:24:E5:98")
       // /// mac: D7:92:84:87:09:7D

+ 1 - 1
pages/connectBle/connectBle.wxml

@@ -1,7 +1,7 @@
 <!-- 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" />
+  <image class="device_pic" src="{{deviceImg}}" 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;margin-inline: 32rpx;">
     {{subTips}}

+ 8 - 5
pages/deviceDetail/detail.js

@@ -4,7 +4,7 @@ const {
   BtHelper
 } = require('../../devices/bt_helper');
 const { deviceVersion } = require('../../request/deviceListRequest')
-import { EnumCmdEvent } from '../../devices/cmd_key_event';
+import { EnumCmdEvent, CmdEvent } from '../../devices/cmd_key_event';
 import EventManager from '../../utils/event_bus'
 import route_util from '../../utils/route_util';
 
@@ -14,7 +14,7 @@ Page({
       showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
       title: '设备详情', //导航栏 中间的标题
     },
-    hasNew: true,
+    hasNew: false,
     // 页面数据
     device: {},
     btHelper: null,
@@ -57,9 +57,9 @@ Page({
   powerTap(e) {
     console.log(e)
     let btHelper = BtHelper.getInstance();
-    btHelper.setPauseSleep(powerOpen ? 60 * 20 : -1)
+    btHelper.setPauseSleep(this.data.powerOpen ? 60 * 20 : -1)
     this.setData({
-      powerOpen: !powerOpen
+      powerOpen: !this.data.powerOpen
     })
   },
   /**
@@ -82,6 +82,7 @@ Page({
 
     const btHelper = BtHelper.getInstance();
     btHelper.getVersion()
+    btHelper.getPauseSleep()
 
     let _this = this;
     EventManager.addNotification(CmdEvent.eventName, function (event) {
@@ -107,7 +108,9 @@ Page({
         }
 
         if (res.confirm) {
-
+          // setSleepAfterPlayPause
+          const btHelper = BtHelper.getInstance();
+          btHelper.setPauseSleep(1200)
         }
       }
     })

+ 22 - 23
pages/ota/ota.js

@@ -177,7 +177,7 @@ Page({
         //   btHelper.ota(localFilePath);
 
         // console.log('文件内容:', res.data);
-        _this.sendDataToBluetooth(res);
+        _this.startSend();
       },
       fail: (err) => {
         wx.showToast({
@@ -187,7 +187,7 @@ Page({
       }
     });
   },
-  sendDataToBluetooth(data) {
+  startSend() {
     const chunkSize = 20; // 每次发送的数据块大小
     const chunks = [];
 
@@ -196,7 +196,18 @@ Page({
     }
 
     this.data._chunks = chunks;
-
+    const btHelper = BtHelper.getInstance();
+    btHelper.otaCmd(1)
+  },
+  sendOtaData() {
+    const btHelper = BtHelper.getInstance();
+    this.data._chunks.forEach(element => {
+      btHelper.otaData(element)
+    });
+  },
+  endEnd() {
+    const btHelper = BtHelper.getInstance();
+    btHelper.otaCmd(0)
   },
 
   updateProgress(newProgress) {
@@ -241,31 +252,19 @@ Page({
       switch (name) {
         case EnumCmdEvent.otaCmd:
           let otaCmd = event.otaCmd;
-          if (otaCmd === 1) {
-            _this.sendDataToBluetooth()
-
-          } else {
-
+          let kind = event.kind;
+          if (otaCmd === 1 && kind == 1) {
+            // 开始发送
+            _this.sendOtaData()
+          } else if (otaCmd === 0 && kind == 1) {
+            // 发送结束
+            _this.endEnd()
           }
           break;
       }
     }, this)
 
-    btHelper = BtHelper.getInstance();
-    const sendNextChunk = (index) => {
-      if (index >= chunks.length) {
-        wx.showToast({
-          title: '文件发送完成,设备开始升级',
-        });
-        btHelper.otaCmd(0);
-
-        return;
-      }
 
-      const chunk = chunks[index];
-      btHelper.otaData(chunk);
-
-    }
 
   },
 
@@ -294,7 +293,7 @@ Page({
    * 生命周期函数--监听页面卸载
    */
   onUnload() {
-
+    EventManager.removeNotification(CmdEvent.eventName, this);
   },
 
   /**

+ 33 - 4
pages/piano/wallpaper/wallpaper.js

@@ -6,6 +6,7 @@ const {
   BtHelper
 } = require('../../../devices/bt_helper');
 const { BtCmd } = require('../../../devices/bluetooth/bt_cmd');
+import EventManager from '../../../utils/event_bus'
 
 // import EventManager from '../../utils/event_bus'
 
@@ -56,6 +57,7 @@ Page({
     src: '',
     width: 250,//宽度
     height: 250,//高度
+    _imageBuffer: null,
 
   }, footerTap() {
     const that = this;
@@ -134,6 +136,7 @@ Page({
           outputBuffer[outputIndex + 1] = rgb565 & 0xFF; // Low byte
         }
       }
+      _this.data._imageBuffer = outputBuffer;
       _this.startImage()
       // fs.writeFileSync(outputPath, outputBuffer);
       console.log(`Conversion successful: ${outputPath}`);
@@ -153,11 +156,19 @@ Page({
     let _this = this;
     deviceWallPaper().then(res => {
       console.log("壁纸列表", res);
-      topImg = res.data[0];
+      let data = res.data ?? []
+      if (data.length == 0) {
+        _this.setData({
+          imageList: [],
+          topImg: {},
+        })
+        return;
+      }
+      topImg = data[0];
 
       _this.setData({
-        imageList: res.data ?? [],
-        topImg: res.data[0] ?? {}
+        imageList: data ?? [],
+        topImg: data[0] ?? {}
       })
 
     })
@@ -186,6 +197,24 @@ Page({
     console.log(param)
     this.wallpaperList();
 
+    let _this = this;
+    EventManager.addNotification(CmdEvent.eventName, function (event) {
+      let name = event.name;
+      console.log("OTA页:", event)
+      switch (name) {
+        case EnumCmdEvent.wallPaper:
+          let otaCmd = event.wallPaper;
+          let kind = event.kind;
+          if (otaCmd === 1 && kind == 1) {
+            // 开始发送
+            _this.sendOtaData()
+          } else if (otaCmd === 0 && kind == 1) {
+            // 发送结束
+            _this.endEnd()
+          }
+          break;
+      }
+    }, this)
 
   },
 
@@ -214,7 +243,7 @@ Page({
    * 生命周期函数--监听页面卸载
    */
   onUnload() {
-
+    EventManager.removeNotification(CmdEvent.eventName, this);
   },
 
   /**