소스 검색

feature:增加OTA,壁纸的指令功能

zeng.chen 8 달 전
부모
커밋
3d799fee87

+ 6 - 1
app.js

@@ -1,5 +1,5 @@
 // app.ts
-import btHelper from './devices/bt_helper';
+import { BtHelper } from './devices/bt_helper';
 import mqtt from './utils/mqtt';
 import update from './utils/update';
 import strings from './utils/strings';
@@ -277,6 +277,11 @@ App({
       }
     })
   },
+  onUnload() {
+    console.log("小程序销毁")
+    btHelper = BtHelper.getInstance()
+    btHelper.disconnect()
+  },
 })
 
 

+ 14 - 7
devices/ble_manager.js

@@ -164,12 +164,18 @@ class bleManager {
     }
 
     // 断开与指定设备的连接
-    disconnect(deviceId) {
+    disconnect() {
+        let _this = this;
+        let device = _this.device ?? {};
+        let deviceId = device.deviceId ?? ""
+        if (deviceId.length === 0) {
+            return;
+        }
         return new Promise((resolve, reject) => {
             wx.closeBLEConnection({
-                deviceId: deviceId,
+                deviceId: _this.device.deviceId ?? "",
                 success: (res) => {
-                    this.device = null;
+                    _this.device = null;
                     console.log('断开连接成功:', res);
                     resolve(res);
                 },
@@ -183,6 +189,7 @@ class bleManager {
 
     // 发送数据到指定设备
     async sendData(data) {
+        let _this = this
         return new Promise((resolve, reject) => {
             var buffer = null;
             // todo 判断是否是buffer
@@ -199,9 +206,9 @@ class bleManager {
 
             console.log('开始发送数据:', data, buffer);
             wx.writeBLECharacteristicValue({
-                deviceId: this.device.deviceId,
-                serviceId: this.device.serviceId,
-                characteristicId: this.device.characteristicId,
+                deviceId: _this.device.deviceId,
+                serviceId: _this.device.serviceId,
+                characteristicId: _this.device.characteristicId,
                 value: buffer,
                 success: (res) => {
                     // console.log('数据发送成功:');
@@ -390,7 +397,7 @@ class bleManager {
                 fail: (err) => {
                     this.device = null
                     console.error('连接失败:', err);
-                    reject(false);
+                    resolve(false);
                 }
             });
         });

+ 11 - 15
devices/bluetooth/bt_cmd.js

@@ -232,21 +232,18 @@ class BtCmd {
     static wallPaperData(value) {
         return this._build(CmdBase.wallPaperData, [value]);
     }
-    // 背景图指令
+    // 背景图指令 1开始, 0结束
     static backgroudImg(value) {
         return this._build(CmdBase.heijiaoBackImg, [value]);
     }   // 背景图指令
     static backgroudImgData(value) {
         return this._build(CmdBase.heijiaoBackImgData, [value]);
     }
-    // OTA指令
-    static OTA(value) {
+    // OTA指令 1开始, 0结束
+    static otaCmd(value) {
         return this._build(CmdBase.heiJiaoOta, [value]);
-    } static OtaData(value) {
+    } static otaData(value) {
         return this._build(CmdBase.heiJiaoOtaData, [value]);
-    }  // OTA指令
-    static OTA(value) {
-        return this._build(CmdBase.heiJiaoOta, [value]);
     }
     /// 获取设备型号指令
     static getClientType() {
@@ -261,14 +258,6 @@ class BtCmd {
     }
 
 
-    /// 获取设备型号指令
-    //   static const int getClientType = 0x31;
-
-    //   ///获取设备mac地址
-    //   static const int getMac = 0x35;
-
-    //   ///获取手机是否连接了设备
-    //   static const int getIsConnect = 0x36;
     // 生成命令(固定头部+版本号+命令总长度+命令类型+)
     static _build(cmdType, otherCmd = [], isWriteChildCmdLength = true) {
         const cmd = [];
@@ -349,6 +338,13 @@ const CmdBase = {
     heiJiaoOtaData: 0x075,
     heijiaoBackImg: 0x76,
     heijiaoBackImgData: 0x77,
+    // 获取设备型号指令
+    getClientType: 0x31,
+    ///获取设备mac地址
+    getMac: 0x35,
+    ///获取手机是否连接了设备
+    getIsConnect: 0x36,
+
     newFlag: "MW-Mate X\\(4G_WIFI\\)|MW-2AX\\(WIFI-N\\)|MW-SR1\\(4G_WIFI\\)|MW-SR1\\(4G_WIFI_MEIZU01\\)",
     // volumeMax: (new RegExp(`^(${CmdBase.newFlag})$`, 'i').test(DeviceManager.instance.clientType || "")) ? 0x20 : 0xF,
     volumeMax: 15,

+ 53 - 5
devices/bluetooth/bt_parse.js

@@ -172,10 +172,6 @@ class BtParse {
         // mqttAddDebugCmd("收到蓝牙指令:" + cmd);
         console.log("收到控制指令:", cmd, type)
 
-        if (type === 0x31 || type === 0x35 || type === 0x36) {
-            console.log("收到新的控制指令:", cmd, type, value)
-        }
-
         switch (type) {
             // 校验设备
             case CmdBase.checkDeviceSuccess:
@@ -440,13 +436,65 @@ class BtParse {
                 const longC = cmd[10];
                 EventManager.fire(CmdEvent.ctrlStatus({ ctrlStatus: [singleC, doubleC, longC] }));
                 break;
+            case CmdBase.getMac:
+                {
+                    var values = []
+                    for (let i = 8; i < cmd.length; i++) {
+                        values.push(cmd[i]);
+                    }
+                    let str = this.hexArrayToString(values);
+                    // getMac===== ?MV-SR1(4G_WIFI)
+                    let device = getApp().globalData.mDeviceList[0] ?? {};
+                    device["trueMac"] = str;
+                    console.log("getMac=====", device)
+                    EventManager.fire(CmdEvent.btMac(str));
+
+                }
+                // [84, 68, 68, 72, 1, 23, 53, 16, 77, 86, 45, 83, 82, 49, 40, 52, 71, 95, 87, 73, 70, 73, 41]
+                break;
+            case CmdBase.getClientType:
+                {
+                    var values = []
+                    for (let i = 8; i < cmd.length; i++) {
+                        values.push(cmd[i]);
+                    }
+                    let str = this.hexArrayToString(values);
+                    let device = getApp().globalData.mDeviceList[0] ?? {};
+                    device["trueClientType"] = str;
+                    console.log("getClientType=====", device)
+                    EventManager.fire(CmdEvent.clientType(str));
+
+                }
+
+                //  [84, 68, 68, 72, 1, 14, 49, 7, 228, 159, 128, 9, 224, 236]
+                break;
+            case CmdBase.getIsConnect:
+                // [84, 68, 68, 72, 1, 10, 54, 2, 0, 1] 
+                let device = getApp().globalData.mDeviceList[0] ?? {};
+                device["isConnectMac"] = value;
+                console.log("getIsConnect=====", device)
 
+                break;
             default:
-                console.log("发送语音:默认发送2", cmd);
+                console.log("接收到语音:", cmd);
                 // _receiveRecordData(cmd);
                 break;
         }
     }
+
+    static hexArrayToString(hexArray) {
+        let str = '';
+        for (let i = 0; i < hexArray.length; i++) {
+            const charCode = hexArray[i];
+            if (charCode >= 32 && charCode <= 126) { // 可打印的ASCII字符范围
+                str += String.fromCharCode(charCode);
+            } else {
+                str += '?'; // 替换为问号或其他符号
+            }
+        }
+        return str;
+    }
+
 }
 
 // 导出类

+ 253 - 9
devices/bt_helper.js

@@ -4,7 +4,9 @@
 // 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 { EnumCmdEvent, CmdEvent } = require('./../devices/cmd_key_event');
+const { addNotification } = require('./../utils/event_bus');
 const BtParse = require('./../devices/bluetooth/bt_parse');
 // const VolumeUtil = require('./VolumeUtil');
 // const EventManager = require('./EventManager');
@@ -58,8 +60,245 @@ class BtHelper {
         this.queueManager.listenTask((task) => {
             _this.bleManager.sendData(task);
         });
-    }
 
+        addNotification(CmdEvent.eventName, function (event) {
+            console.log("蓝牙helper:", event)
+            let device = getApp().globalData.mDeviceList[0] ?? {};
+            if (device.connectType != 1 && device.state != "online") {
+                return;
+            }
+            _this.handleCommand(event, device);
+
+        }, this)
+    }
+
+    handleCommand(event, mDevice) {
+        let name = event.name;
+
+        switch (name) {
+            ///音量  设备控制手机
+            case EnumCmdEvent.volume:
+                var volume = event.volume;
+                // if (ProviderUtil.play.isSimulate) {
+                //   _isPhoneVolume = false;
+                //   await VolumeUtil.setVolume(volume);
+                //   Future.delayed(const Duration(milliseconds: 100), () {
+                //     _isPhoneVolume = true;
+                //   });
+                // }
+                mDevice.volume = volume;
+                break;
+
+            ///电量
+            case EnumCmdEvent.battery:
+                mDevice.kwh = event.kwh;
+                break;
+
+            ///低时延模式  低时延模式开启 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;
+                mDevice.kwhRight = event.kwhRight;
+                mDevice.kwhBox = event.kwhBox;
+                break;
+
+            ///是否支持TTS
+            case EnumCmdEvent.enableTTS:
+                mDevice.enableTTS = event.enableTTS;
+                break;
+
+            ///切换设备连接模式 0:未知 1:低功耗蓝牙 2:wifi类型 3:经典蓝牙(不做任何操作) 4:4G类型
+            case EnumCmdEvent.switchDeviceMode:
+                var deviceMode = event.deviceMode.index;
+                if (deviceMode != null) {
+                    L.d("switchDeviceMode======$deviceMode");
+                    mDevice.deviceMode = deviceMode;
+                }
+                break;
+
+            ///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;
+                mDevice.wakeHour = event.wakeHour;
+                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 ?? "";
+
+                ///验证设备首页固件升级图标
+                // getCheckOTAIndexProvider.refresh();
+
+                // // TODO 校验版本是否升级
+                // if (clientType.isNotEmpty) {
+                //     var response = await DeviceService.getDeviceDetail(
+                //         clientType: clientType,
+                //         version: event.version,
+                //         type: mDevice.deviceMode ?? EnumDeviceMode.ble.index,
+                //     );
+
+                //     if (response.isSuccess) {
+                //         DeviceDetailEntity ? updateData = response.data;
+                //         if (updateData != null) {
+                //             // mDevice.typeList = updateData.typeList;
+                //             // 是否强制升级0-无更新 1-是,2-否
+                //             var force = updateData.isEnforcement;
+                //             var hasNewVersion = force == 1 || force == 2;
+
+
+                //             // if (force == 1) {
+                //             //     EventManager.fire(OtaUpdateEvent(updateData: updateData));
+                //             // }
+                //         }
+                //     }
+                // }
+                break;
+
+            ///云小微授权
+            case EnumCmdEvent.auth:
+                var authInfo = event.authInfo;
+                mDevice.authInfo = authInfo;
+                // QQMusicManager.auth(authInfo: authInfo);
+                // CacheUtil.saveDSN(dsn: authInfo.dsn ?? "");
+                break;
+            case EnumCmdEvent.btMac:
+                var btMac = event.btMac;
+                mDevice.btMac = btMac;
+                // // 更新一下 imei
+                // getDeviceImei().then((e) {
+                //     mDevice.imei = e;
+                // });
+                break;
+
+            ///EQ音效
+            case EnumCmdEvent.eq:
+                mDevice.eqs = event.eqs;
+                break;
+
+            ///payId 充流量使用
+            case EnumCmdEvent.payId:
+                mDevice.payId = event.payId;
+                break;
+
+            ///QQ音乐使用dsn授权
+            case EnumCmdEvent.dsn:
+                var dsn = event.dsn;
+                mDevice.dsn = dsn;
+                // //存储设备的DSN
+                // await CacheUtil.saveDSN(dsn: dsn ?? "");
+                // ProviderUtil.twelvePublic.wifiDeviceConnected();
+                break;
+
+            ///自动切换 0,1不能
+            ///
+            case EnumCmdEvent.netModeAuto:
+                mDevice.netModeAuto = event.netModeAuto;
+                break;
+
+            ///解绑设备
+            case EnumCmdEvent.unbind:
+                //   let unbindAddress = event.item.address ?? "";
+                //     if (unbindAddress != mDevice.address) {
+                //         _resetList();
+                //         return;
+                //     }
+                //     _lastConnectAddress = null;
+                //     bondedDeviceData.remove(mDevice);
+                //     if (mDevice.address == event.item.address) {
+                //         mDevice = null;
+                //     }
+                //     _resetList();
+
+                break;
+
+            ///解绑设备
+            case EnumCmdEvent.ctrlStatus:
+                // List < int > ctrlList = event.ctrlStatus;
+                // if (ctrlList.length == 3) {
+                //     mDevice.singleClick = ctrlList[0];
+                //     mDevice.doubleClick = ctrlList[1];
+                //     mDevice.longPressClick = ctrlList[2];
+                // }
+                break;
+
+            case EnumCmdEvent.lowPowerOpen:
+                let lowPower = event.lowPowerOpen ?? 0;
+                mDevice.lowPowerOpen = lowPower;
+                break;
+
+            case EnumCmdEvent.authSleepStatus:
+                let pauseSleep = event.pauseSleep;
+                mDevice.pauseSleep = pauseSleep;
+
+                notifyListeners();
+                break;
+
+            ///设备信息
+            case EnumCmdEvent.getDeviceInfo:
+                //   List list = [];
+                //   String userId = ProviderUtil.user.userModel.uid ?? "";
+                //     for (var element in bondedDeviceData) {
+                //         list.add({
+                //             "clientType": element.clientType ?? "",
+                //             "userId": userId,
+                //             "deviceName": element.name ?? "",
+                //             "mac": element.address,
+                //             "deviceId": element.deviceId ?? 0,
+                //         });
+                //     }
+
+                //     MobClickEvent.mobClickEvent(EnumMobEvent.eventDevicesConnect, params: { "devices": list });
+                //     if (mDevice != null) {
+                //         mDevice.imei ??= await CacheUtil.getImei(address: mDevice.address ?? "");
+
+                //         /// 用户绑定设备
+                //         await CacheUtil.addDevice(item: mDevice!);
+
+                //         // String dsn = await CacheUtil.getDSN();
+                //         // if (dsn.isEmpty) {
+                //         // 获取设备dsn
+                //         DeviceManager.instance.auth();
+                //         // }
+                //         //延迟
+                //         var address = mDevice.address ?? "";
+                //     bool isSuccess = await ProviderUtil.twelve.questDeviceTwelveData(address);
+                //         if (isSuccess) {
+                //       bool showDevice = await DeviceChannelAllPage.presentPage();
+                //             if (!showDevice) {
+                //                 VipOpenAiTingDialogWidget.presentPage();
+                //             }
+                //         }
+                //     }
+                //     await CacheUtil.saveConnectedDevice(list: bondedDeviceData);
+
+                break;
+            default:
+                break;
+        }
+    }
 
     resetConnectState(connect) {
         // BtHelper._isConnecting = connect;
@@ -171,8 +410,8 @@ class BtHelper {
 
     }
 
-    async disconnect(data) {
-        this.bleManager.disconnect(data.deviceId)
+    async disconnect() {
+        this.bleManager.disconnect()
     }
 
     async dispose() {
@@ -323,7 +562,9 @@ class BtHelper {
     }
 
     async setSleep(open, hour, minutes) {
-        this.send(BtCmd.setSleep({ switchStatus: open, hour, minutes }));
+        let defaultMin = minutes ?? 10;
+        let defaultHour = hour ?? 0;
+        this.send(BtCmd.setSleep({ switchStatus: open, defaultHour, defaultMin }));
     }
 
     async setTime() {
@@ -401,6 +642,9 @@ class BtHelper {
     }
 
     async setLowDelayMode(open, mode) {
+        // 0 open,
+        // 1 close,
+        // mode 1:音乐 , 2: 游戏 , 3: movie
         this.send(BtCmd.setLowDelayMode({ open, mode }));
     }
 
@@ -450,10 +694,10 @@ class BtHelper {
         this.send(BtCmd.backgroudImgData(value));
     }
     // OTA指令
-    static OTA(value) {
-        this.send(BtCmd.OTA(value));
-    } static OtaData(value) {
-        this.send(BtCmd.OtaData(value));
+    static otaCmd(value) {
+        this.send(BtCmd.otaCmd(value));
+    } static otaData(value) {
+        this.send(BtCmd.otaData(value));
     }
 }
 

+ 20 - 1
devices/cmd_key_event.js

@@ -45,7 +45,9 @@ const EnumCmdEvent = {
     takeHandLight: 'takeHandLight',
     payId: 'payId',
     authSleepStatus: 'authSleepStatus',
-    btMac: 'btMac'
+    btMac: 'btMac',
+    otaCmd: 'otaCmd',
+    wallpaper: 'wallpaper'
 };
 
 // 枚举定义
@@ -120,6 +122,8 @@ class CmdEvent {
         this.payId = null;
         this.btMac = null;
         this.deviceMode = null;
+        this.otaCmd = null;
+        this.wallpaper = null;
     }
 
     static eventName = "cmdEventNotification"
@@ -317,6 +321,21 @@ class CmdEvent {
         event.btMac = btMac;
         return event;
     }
+    static clientType({ clientType }) {
+        const event = new CmdEvent({ cmdEvent: EnumCmdEvent.clientType });
+        event.clientType = clientType;
+        return event;
+    }
+    static otaCmd({ value }) {
+        const event = new CmdEvent({ cmdEvent: EnumCmdEvent.otaCmd });
+        event.otaCmd = value;
+        return event;
+    }
+    static wallpaper({ value }) {
+        const event = new CmdEvent({ cmdEvent: EnumCmdEvent.wallpaper });
+        event.wallpaper = value;
+        return event;
+    }
 
     static netModeAuto({ netModeAuto }) {
         const event = new CmdEvent({ cmdEvent: EnumCmdEvent.netModeAuto });

+ 1 - 1
pages/connectBle/connectBle.wxml

@@ -3,7 +3,7 @@
   <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;">
+  <view style="font-size: 28rpx; color: #666666; margin-top: 32rpx; display: flex; justify-content: center; align-items: center;margin-inline: 32rpx;">
     {{subTips}}
   </view>
   <view class="main_color connect_button" bind:tap="connectDeviceTap">{{buttonTips}}</view>

+ 18 - 9
pages/deviceDetail/detail.js

@@ -4,7 +4,7 @@ const {
   BtHelper
 } = require('../../devices/bt_helper');
 const { deviceVersion } = require('../../request/deviceListRequest')
-import { CmdEvent } from '../../devices/cmd_key_event';
+import { EnumCmdEvent } from '../../devices/cmd_key_event';
 import EventManager from '../../utils/event_bus'
 import route_util from '../../utils/route_util';
 
@@ -30,29 +30,34 @@ Page({
       let hasNewVersion = updateData.isEnforcement === 1 || updateData.isEnforcement === 2;
       _this.setData({
         hasNew: hasNewVersion,
+        updateData: updateData
       });
     })
   },
 
 
   goToWallpaper: function () {
-
-    wx.navigateTo({
-      url: '/pages/piano/wallpaper/wallpaper'
-    });
+    let newParam = JSON.stringify(this.data.device);
+    route_util.jumpParam('/pages/piano/wallpaper/wallpaper', newParam)
   },
 
   goToOta: function () {
     if (this.data.hasNew) {
-      let param = JSON.stringify(this.data.updateData) ?? {};
+      let param = {
+        "device": this.data.device,
+        "otaData": this.data.updateData,
+      }
+      let newParam = JSON.stringify(param);
       // wx.navigateTo({
       //   url: '/pages/ota/ota' + "?param=" + param
       // });
-      route_util.jumpParam('/pages/ota/ota', param)
+      route_util.jumpParam('/pages/ota/ota', newParam)
     }
   },
   powerTap(e) {
     console.log(e)
+    let btHelper = BtHelper.getInstance();
+    btHelper.setPauseSleep(powerOpen ? 60 * 20 : -1)
     this.setData({
       powerOpen: !powerOpen
     })
@@ -62,6 +67,7 @@ Page({
    */
   onLoad: function (options) {
     let device = JSON.parse(options.param);
+    console.log("设备详情", device)
     let isConnect = device.state === 'online'
     if (!isConnect) {
       // btHelper
@@ -70,6 +76,9 @@ Page({
       })
       return;
     }
+    this.setData({
+      device: device,
+    })
 
     const btHelper = BtHelper.getInstance();
     btHelper.getVersion()
@@ -77,9 +86,9 @@ Page({
     let _this = this;
     EventManager.addNotification(CmdEvent.eventName, function (event) {
       let name = event.name;
-      console.log(event)
+      console.log("详情页:", event)
       switch (name) {
-        case CmdEvent.version:
+        case EnumCmdEvent.version:
           _this.data.device.version = event.version;
           _this.checkOtaVersion(_this.data.device);
           break;

+ 109 - 29
pages/ota/ota.js

@@ -1,3 +1,6 @@
+const { BtHelper } = require("../../devices/bt_helper");
+import { EnumCmdEvent } from '../../devices/cmd_key_event';
+import EventManager from '../../utils/event_bus'
 // pages/OTA/ota.js
 Page({
 
@@ -12,8 +15,49 @@ Page({
     device: {},
     otaData: {},
     btHelper: null,
+    progress: 0, // 进度条初始值
+    otaStatus: 0,
+    buttonTips: "固件更新",
+    _chunks: [],
   },
+  setOtaStatus(status) {
+    switch (status) {
+      case 0:
+        this.setData({
+          otaStatus: 0,
+          buttonTips: "固件更新"
+        });
+        break;
+      case 1:
+        this.setData({
+          otaStatus: 1,
+          buttonTips: "下载升级包"
+        });
+        break;
+      case 2:
+        this.setData({
+          otaStatus: 2,
+          buttonTips: "开始更新"
+        });
+        break;
+      case 3:
+        this.setData({
+          otaStatus: 3,
+          buttonTips: "更新中..."
+        });
+        break;
 
+      case 4:
+        this.setData({
+          otaStatus: 4,
+          buttonTips: "更新失败,再试一次"
+        });
+        break;
+      default:
+        break;
+    }
+
+  },
   startOtaTap() {
     let connect = getApp().globalData.device.connect ?? false
     if (!connect) {
@@ -44,7 +88,6 @@ Page({
   },
   downloadFile(url) {
 
-
     urlPath = updateData.url ?? "";
     content = updateData.content ?? "暂无更新";
 
@@ -71,6 +114,7 @@ Page({
                 oldPath: filePath,
                 newPath: localFilePath,
                 success: () => {
+
                   // this.setData({
                   //   localFilePath: localFilePath
                   // });
@@ -120,8 +164,10 @@ Page({
       });
       return;
     }
+    this.setOtaStatus(2);
     const fs = wx.getFileSystemManager();
 
+    let _this = this;
     fs.readFile({
       filePath: localFilePath,
       encoding: 'base64', // 可以选择 'utf8' 或 'base64'
@@ -131,6 +177,7 @@ Page({
         //   btHelper.ota(localFilePath);
 
         // console.log('文件内容:', res.data);
+        _this.sendDataToBluetooth(res);
       },
       fail: (err) => {
         wx.showToast({
@@ -148,45 +195,78 @@ Page({
       chunks.push(data.slice(i, i + chunkSize));
     }
 
-    const sendNextChunk = (index) => {
-      if (index >= chunks.length) {
+    this.data._chunks = chunks;
+
+  },
+
+  updateProgress(newProgress) {
+    this.setData({
+      progress: newProgress,
+    });
+  },
+
+  // 示例:模拟进度更新
+  simulateProgressUpdate() {
+    let currentProgress = 0;
+    const interval = setInterval(() => {
+      if (currentProgress >= 100) {
+        clearInterval(interval);
         wx.showToast({
-          title: '文件发送完成',
+          title: '升级完成',
         });
-        return;
+      } else {
+        currentProgress += 10;
+        this.updateProgress(currentProgress);
       }
-
-      const chunk = chunks[index];
-
-      // wx.writeBLECharacteristicValue({
-      //   deviceId: deviceId,
-      //   serviceId: 'yourServiceId', // 替换为实际的服务ID
-      //   characteristicId: 'yourCharacteristicId', // 替换为实际的特征值ID
-      //   value: new Uint8Array(Buffer.from(chunk, 'base64')),
-      //   success: () => {
-      //     setTimeout(() => {
-      //       sendNextChunk(index + 1);
-      //     }, 100); // 延迟100毫秒发送下一个数据块
-      //   },
-      //   fail: (err) => {
-      //     wx.showToast({
-      //       title: '文件发送失败',
-      //     });
-      //     console.error('文件发送失败:', err);
-      //   }
-      // });
-    }
+    }, 500);
   },
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad(options) {
-    let otaData = JSON.parse(options.param)
-    console.log(otaData)
+    let param = JSON.parse(options.param)
+    console.log(param)
+    let otaData = param.otaData
+    let device = param.device
+    device.clientType = device.clientType ?? device.ProdModel
     this.setData({
-      otaData: otaData
+      otaData: otaData,
+      device: device
     })
 
+    let _this = this;
+    EventManager.addNotification(CmdEvent.eventName, function (event) {
+      let name = event.name;
+      console.log("OTA页:", event)
+      switch (name) {
+        case EnumCmdEvent.otaCmd:
+          let otaCmd = event.otaCmd;
+          if (otaCmd === 1) {
+            _this.sendDataToBluetooth()
+
+          } else {
+
+          }
+          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);
+
+    }
+
   },
 
   /**

+ 10 - 2
pages/ota/ota.wxml

@@ -4,7 +4,7 @@
     <view style="height: 32rpx;"></view>
     <view class="item">
         <text class="label">制造商</text>
-        <text class="arrow">{{device.man}}</text>
+        <text class="arrow">AirSmart</text>
     </view>
     <view class="item">
         <text class="label">产品型号</text>
@@ -14,5 +14,13 @@
         <text class="label">MAC地址</text>
         <text class="arrow">{{device.mac}}</text>
     </view>
-    <view class="button main_color" bind:tap="startOtaTap">固件更新</view>
+    <view class="button main_color" bind:tap="startOtaTap">{{buttonTips}}</view>
+</view>
+<view wx:if="{{otaStatus === 3}}" class="container">
+    <view class="background"></view>
+    <view class="content">
+        <view class="progress-bar-container">
+            <view class="progress-bar" style="width: {{progress}}%;"></view>
+        </view>
+    </view>
 </view>

+ 37 - 2
pages/ota/ota.wxss

@@ -20,8 +20,6 @@
 }
 
 .arrow {
-	width: 20px;
-	height: 20px;
 	margin-right: 16rpx;
 }
 
@@ -37,4 +35,41 @@
 	text-align: center;
 	border-radius: 44rpx;
 	height: 88rpx;
+}
+
+
+.background {
+	position: absolute;
+	top: 0;
+	left: 0;
+	width: 100%;
+	height: 100%;
+	background-color: rgba(0, 0, 0, 0.7);
+	/* 半透明黑色背景 */
+}
+
+.content {
+	width: 450rpx;
+	height: 450rpx;
+	background-color: white;
+	border-radius: 20rpx;
+	display: flex;
+	justify-content: center;
+	align-items: center;
+	box-shadow: 0 0 20rpx rgba(0, 0, 0, 0.3);
+}
+
+.progress-bar-container {
+	width: 90%;
+	height: 20rpx;
+	background-color: #e0e0e0;
+	border-radius: 10rpx;
+	overflow: hidden;
+}
+
+.progress-bar {
+	height: 100%;
+	background-color: #4caf50;
+	/* 进度条颜色 */
+	transition: width 0.3s ease-in-out;
 }

+ 6 - 1
pages/piano/wallpaper/wallpaper.js

@@ -70,7 +70,11 @@ Page({
           src: tempFilePaths[0], // 图片路径
           cropScale: '1:1', // 裁剪比例
           success: (res) => {
+            console.log('裁剪成功', res);
 
+            that.setData({
+              src: res.tempFilePath
+            })
           }
         })
 
@@ -178,9 +182,10 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad(options) {
+    let param = JSON.parse(options.param)
+    console.log(param)
     this.wallpaperList();
 
-    EventMan
 
   },
 

+ 2 - 1
pages/piano/wallpaper/wallpaper.json

@@ -1,5 +1,6 @@
 {
   "usingComponents": {
-    "nav-bar": "./../../components/navbar/navbar"
+    "nav-bar": "./../../components/navbar/navbar",
+    "image-cropper": "./../../components/imageCrop/index"
   }
 }

+ 1 - 0
pages/piano/wallpaper/wallpaper.wxml

@@ -14,6 +14,7 @@
         <image src="../../../images/common/icon_add.png" mode="aspectFill" />
         <view>上传图片</view>
     </view>
+    <image-cropper wx:if="{{scr}}" src="{{src}}" bind:cropSuccess="cropSuccess" bind:cropCancel="cropCancel" bind:cropClose="cropClose" :showCropper="showCropper" :cropRatio="cropRatio" :cropWidth="cropWidth" :cropHeight="cropHeight" :cropTop="cropTop" :cropLeft="cropLeft" :cropBgColor="cropBgColor" :cropBgImage></image-cropper>
     <!-- <view wx:if="{{src}}" class='bottom'>
         <button catchtap='updateImage'>更换照片</button>
         <button type="primary" bindtap='submit'>确定裁剪</button>