Jelajahi Sumber

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

Damon 8 bulan lalu
induk
melakukan
b274ca0994

+ 10 - 3
devices/ble_manager.js

@@ -183,11 +183,18 @@ class bleManager {
     // 发送数据到指定设备
     async sendData(data) {
         return new Promise((resolve, reject) => {
-            const buffer = new ArrayBuffer(data.length);
+            var buffer = null;
+            // todo 判断是否是buffer
+            // if (Buffer.isBuffer(data)) {
+            //     buffer = data;
+            // } else {
+            buffer = new ArrayBuffer(data.length);
             const view = new Uint8Array(buffer);
             for (let i = 0; i < data.length; i++) {
                 view[i] = data[i].toString(16);
             }
+            // }
+
             console.log('开始发送数据:', view);
             wx.writeBLECharacteristicValue({
                 deviceId: this.device.deviceId,
@@ -195,7 +202,7 @@ class bleManager {
                 characteristicId: this.device.characteristicId,
                 value: buffer,
                 success: (res) => {
-                    console.log('数据发送成功:');
+                    // console.log('数据发送成功:');
                     resolve(res);
                 },
                 fail: (err) => {
@@ -507,7 +514,7 @@ class bleManager {
     }
     // 监听特征值变化
     notifyCharacteristicValueChange(characteristicId, callback) {
-        console.log('监听特征值变化:', characteristicId);
+        console.log('监听特征值变化:', characteristicId, this.device.deviceId, this.device.serviceId);
         wx.notifyBLECharacteristicValueChange({
             deviceId: this.device.deviceId,  //设备mac   IOS和安卓系统不一样
             serviceId: this.device.serviceId,     //服务通道,这里主要是notify

+ 28 - 0
devices/bluetooth/bt_cmd.js

@@ -222,6 +222,28 @@ class BtCmd {
         return 0x01;
     }
 
+    /* 黑胶音箱的指令 */
+    // 壁纸指令 1开始, 0结束
+    static wallPaper(value) {
+        return this._build(CmdBase.wallPaper, [value]);
+    }
+    // 壁纸指令 
+    static wallPaperData(value) {
+        return this._build(CmdBase.wallPaperData, [value]);
+    }
+    // 背景图指令
+    static backgroudImg(value) {
+        return this._build(CmdBase.heijiaoBackImg, [value]);
+    }   // 背景图指令
+    static backgroudImgData(value) {
+        return this._build(CmdBase.heijiaoBackImgData, [value]);
+    }
+    // OTA指令
+    static OTA(value) {
+        return this._build(CmdBase.heiJiaoOta, [value]);
+    } static OtaData(value) {
+        return this._build(CmdBase.heiJiaoOtaData, [value]);
+    }
     // 生成命令(固定头部+版本号+命令总长度+命令类型+)
     static _build(cmdType, otherCmd = [], isWriteChildCmdLength = true) {
         const cmd = [];
@@ -298,6 +320,12 @@ const CmdBase = {
     switchLed: 0x39,
     queryVolume: 0x32,
     setVolume: 0x33,
+    wallPaper: 0x78,
+    wallPaperData: 0x79,
+    heiJiaoOta: 0x074,
+    heiJiaoOtaData: 0x075,
+    heijiaoBackImg: 0x76,
+    heijiaoBackImgData: 0x77,
     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,

+ 23 - 0
devices/bt_helper.js

@@ -426,6 +426,29 @@ class BtHelper {
         this.send(Uint8Array.from([0x54, 0x44, 0x44, 0x48, 0x01, 0x0a, 0x29, 0x02, 0x00, 0x01]));
         this.send(Uint8Array.from([0x54, 0x44, 0x44, 0x48, 0x01, 0x09, 0x39, 0x01, 0x00]));
     }
+
+    /* 黑胶音箱的指令 */
+    // 壁纸指令 1开始, 0结束
+    static wallPaper(value) {
+        this.send(BtCmd.wallPaper(value));
+    }
+    // 壁纸指令 
+    static wallPaperData(value) {
+        this.send(BtCmd.wallPaperData(value));
+    }
+    // 背景图指令
+    static backgroudImg(value) {
+        this.send(BtCmd.backgroudImg(value));
+    }   // 背景图指令
+    static backgroudImgData(value) {
+        this.send(BtCmd.backgroudImgData(value));
+    }
+    // OTA指令
+    static OTA(value) {
+        this.send(BtCmd.OTA(value));
+    } static OtaData(value) {
+        this.send(BtCmd.OtaData(value));
+    }
 }
 
 // 导出 BtHelper 类

+ 39 - 13
pages/deviceDetail/detail.js

@@ -1,6 +1,8 @@
 // pages/deviceDetail/detail.js
 
-const BtHelper = require('../../devices/bt_helper')
+const {
+  BtHelper
+} = require('../../devices/bt_helper');
 const { deviceVersion } = require('../../request/deviceListRequest')
 import { CmdEvent } from '../../devices/cmd_key_event';
 import EventManager from '../../utils/event_bus'
@@ -17,6 +19,8 @@ Page({
     device: {},
     btHelper: null,
     updateData: {},
+    powerOpen: false,
+
   },
   checkOtaVersion(device) {
     let _this = this;
@@ -47,7 +51,12 @@ Page({
       route_util.jumpParam('/pages/ota/ota', param)
     }
   },
-
+  powerTap(e) {
+    console.log(e)
+    this.setData({
+      powerOpen: !powerOpen
+    })
+  },
   /**
    * 生命周期函数--监听页面加载
    */
@@ -65,20 +74,37 @@ Page({
     const btHelper = BtHelper.getInstance();
     btHelper.getVersion()
 
-    EventManager.addNotification(CmdEvent.eventName, listenEvent, this)
+    let _this = this;
+    EventManager.addNotification(CmdEvent.eventName, function (event) {
+      let name = event.name;
+      console.log(event)
+      switch (name) {
+        case CmdEvent.version:
+          _this.data.device.version = event.version;
+          _this.checkOtaVersion(_this.data.device);
+          break;
+      }
+    }, this)
   },
-  listenEvent(event) {
-    let name = event.name;
-    console.log(event)
-    switch (name) {
-      case CmdEvent.version:
-        this.data.device.version = event.version;
-        this.checkOtaVersion(this.data.device);
-        break;
-    }
+
+  questionTap() {
+    wx.showModal({
+      title: '省电模式',
+      content: '开启省电模式,设备无蓝牙连接或内容播放20分钟后进入自动休眠,任意按键可唤醒。',
+      showCancel: false,
+      complete: (res) => {
+        if (res.cancel) {
+
+        }
+
+        if (res.confirm) {
+
+        }
+      }
+    })
   },
   onUnload() {
-    EventManager.removeNotification(CmdEvent.eventName, listenEvent, this)
+    EventManager.removeNotification(CmdEvent.eventName, this)
   },
 
 })

+ 2 - 2
pages/deviceDetail/detail.wxml

@@ -14,9 +14,9 @@
         <view class="item" bindtap="goToAccountSecurity">
             <view class="left-content">
                 <text class="label">省电模式</text>
-                <image class="question" src="../../images/common/icon_question.png"></image>
+                <image class="question" bind:tap="questionTap" src="../../images/common/icon_question.png"></image>
             </view>
-            <image class="arrow" src="../../images/common/icon_arrow.png"></image>
+            <switch class="switch" color="#6546A3" checked="{{powerOpen}}" bindchange="powerTap" />
         </view>
         <view class="item" bindtap="goToOta">
             <view class="left-content">

+ 6 - 0
pages/deviceDetail/detail.wxss

@@ -52,6 +52,12 @@
     margin-right: 16rpx;
 }
 
+.switch {
+    width: 88rpx;
+    height: 44rpx;
+    margin-right: 16rpx;
+}
+
 .red {
     width: 10rpx;
     height: 10rpx;

+ 10 - 1
pages/index/index.js

@@ -566,8 +566,12 @@ Page({
       return;
     }
 
+    console.log(item)
+    route_util.jumpParam('/pages/deviceDetail/detail', JSON.stringify(item))
+    return
     ///去蓝牙连接处理
     if (e.currentTarget.dataset.index === that.data.deviceListIndex) {
+      console.log(item)
       route_util.jumpParam('/pages/deviceDetail/detail', JSON.stringify(item))
     } else {
       that.addConnectBlueDevice({
@@ -724,7 +728,7 @@ Page({
     if (tempList && tempList.length > 0) {
       deviceList = deviceList.filter((v) => v.deviceId !== newDevice.deviceId);
     };
-
+    console.log("添加蓝牙设备:", newDevice);
     deviceList.unshift({
       /// 蓝牙ble连接
       connectType: 1,
@@ -823,6 +827,11 @@ Page({
     // 更新缓存
     wx.setStorageSync("devicelist", JSON.stringify(finalList));
 
+    finalList.forEach(element => {
+      if (element.connectType == 1) {
+        element.state = "online"
+      }
+    });
     that.setData({
       deviceList: finalList
     });

+ 4 - 3
pages/ota/ota.js

@@ -6,10 +6,10 @@ Page({
    */
   data: {
     nvabarData: {
-      showCapsule: 0, //是否显示左上角图标   1表示显示    0表示不显示
-      title: '固件信息', //导航栏 中间的标题
+      showCapsule: 1, //
+      title: '固件信息',
     },
-    device: getApp().globalData.device,
+    device: {},
     otaData: {},
     btHelper: null,
   },
@@ -182,6 +182,7 @@ Page({
    */
   onLoad(options) {
     let otaData = JSON.parse(options.param)
+    console.log(otaData)
     this.setData({
       otaData: otaData
     })

+ 1 - 0
pages/ota/ota.wxml

@@ -1,6 +1,7 @@
 <!-- pages/OTA/ota.wxml -->
 <view class="section">
     <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 style="height: 32rpx;"></view>
     <view class="item">
         <text class="label">制造商</text>
         <text class="arrow">{{device.man}}</text>

+ 97 - 12
pages/piano/wallpaper/wallpaper.js

@@ -1,5 +1,14 @@
 // pages/piano/wallpaper/wallpaper.js
 const { deviceWallPaper } = require('../../../request/deviceListRequest')
+// const sharp = require('sharp');
+// const fs = require('fs');
+const {
+  BtHelper
+} = require('../../../devices/bt_helper');
+const { BtCmd } = require('../../../devices/bluetooth/bt_cmd');
+
+// import EventManager from '../../utils/event_bus'
+
 
 Page({
 
@@ -44,6 +53,10 @@ Page({
       showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
       title: '壁纸设置', //导航栏 中间的标题
     },
+    src: '',
+    width: 250,//宽度
+    height: 250,//高度
+
   }, footerTap() {
     const that = this;
     wx.chooseImage({
@@ -53,25 +66,79 @@ Page({
       success: function (res) {
         const tempFilePaths = res.tempFilePaths;
         console.log('获取图片信息成功', res);
+        wx.cropImage({
+          src: tempFilePaths, // 图片路径
+          cropScale: '1:1', // 裁剪比例
+          success: (res) => {
 
-        wx.getImageInfo({
-          src: tempFilePaths[0],
-          success: function (imageInfo) {
-            console.log(imageInfo);
-            wx.navigateTo({
-              url: `/pages/crop/crop?path=${tempFilePaths[0]}&width=${imageInfo.width}&height=${imageInfo.height}`
-            });
-          },
-          fail: function (err) {
-            console.error('获取图片信息失败', err);
           }
-        });
+        })
+
+        // wx.getImageInfo({
+        //   src: tempFilePaths[0],
+        //   success: function (imageInfo) {
+        //     console.log(imageInfo);
+        //     //获取到image-cropper实例
+        //     //开始裁剪
+        //     // that.setData({
+        //     //   src: imageInfo.path,//要裁剪的图片
+        //     // })
+        //     // wx.navigateTo({
+        //     //   url: `/pages/crop/crop?path=${tempFilePaths[0]}&width=${imageInfo.width}&height=${imageInfo.height}`
+        //     // });
+        //   },
+        //   fail: function (err) {
+        //     console.error('获取图片信息失败', err);
+        //   }
+        // });
       },
       fail: function (err) {
         console.error('选择图片失败', err);
       }
     });
-  }, imageTap(e) {
+  },
+
+
+  async convertToRGB565(inputPath, outputPath) {
+    try {
+      // todo
+      let sharp = null
+      const metadata = await sharp(inputPath).metadata();
+      const { width, height } = metadata;
+
+      const buffer = await sharp(inputPath)
+        .raw()
+        .toBuffer();
+
+      const outputBuffer = Buffer.alloc(width * height * 2); // 2 bytes per pixel for RGB565
+
+      for (let y = 0; y < height; y++) {
+        for (let x = 0; x < width; x++) {
+          const index = (y * width + x) * 4; // RGBA
+          const r = buffer[index];
+          const g = buffer[index + 1];
+          const b = buffer[index + 2];
+
+          const r5 = (r >> 3) & 0x1F; // 5 bits for red
+          const g6 = (g >> 2) & 0x3F; // 6 bits for green
+          const b5 = (b >> 3) & 0x1F; // 5 bits for blue
+
+          const rgb565 = (r5 << 11) | (g6 << 5) | b5;
+
+          const outputIndex = (y * width + x) * 2;
+          outputBuffer[outputIndex] = (rgb565 >> 8) & 0xFF; // High byte
+          outputBuffer[outputIndex + 1] = rgb565 & 0xFF; // Low byte
+        }
+      }
+      _this.startImage()
+      // fs.writeFileSync(outputPath, outputBuffer);
+      console.log(`Conversion successful: ${outputPath}`);
+    } catch (error) {
+      console.error('Error converting image:', error);
+    }
+  },
+
+  imageTap(e) {
     console.log(e)
     // wxfile://tmp_d3e57489ead39c698676ff860df9cb8a37f66ee1a4777dbb.jpg
     let image = e.currentTarget.dataset.image;
@@ -92,10 +159,28 @@ Page({
     })
   },
 
+  startImage() {
+    let _this = this;
+    BtHelper.sendData(BtCmd.wallPaper(1));
+  },
+  sendImage(imageBuffer) {
+    let chunkSize = 20;
+    for (let i = 0; i < imageBuffer.length; i += chunkSize) {
+      const chunk = imageBuffer.slice(i, i + chunkSize);
+      // this.sendImage(chunk);
+      BtHelper.wallPaperData(chunk)
+    }
+  },
+  endImage() {
+    BtHelper.sendData(BtCmd.wallPaper(0));
+  },
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad(options) {
+    this.wallpaperList();
+
+    EventMan
 
   },
 

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

@@ -14,4 +14,8 @@
         <image src="../../../images/common/icon_add.png" mode="aspectFill" />
         <view>上传图片</view>
     </view>
+    <!-- <view wx:if="{{src}}" class='bottom'>
+        <button catchtap='updateImage'>更换照片</button>
+        <button type="primary" bindtap='submit'>确定裁剪</button>
+    </view> -->
 </view>

+ 25 - 1
pages/piano/wallpaper/wallpaper.wxss

@@ -13,6 +13,7 @@
     width: 533rpx;
     height: 400rpx;
     border-radius: 16rpx;
+    background-color: #F2F5F7;
     overflow: hidden;
 }
 
@@ -60,6 +61,7 @@
     margin-right: 8rpx;
     width: 48rpx;
     height: 48rpx;
+    margin-top: -16rpx;
 }
 
 .footer>view {
@@ -67,4 +69,26 @@
     width: 128rpx;
     font-weight: Medium;
     font-size: 32rpx;
-}
+    margin-top: -16rpx;
+
+}
+
+/* 
+.bottom {
+    display: flex;
+    justify-content: space-between;
+    align-items: center;
+    position: fixed;
+    bottom: 0;
+    left: 0;
+    right: 0;
+    padding: 0 32rpx;
+    box-sizing: border-box;
+}
+
+.bottom button {
+    flex: 1;
+    margin: 0 16rpx;
+    height: 88rpx;
+    font-size: 32rpx;
+} */

+ 1 - 5
request/deviceListRequest.js

@@ -25,11 +25,7 @@ module.exports = {
   },
   // 壁纸列表
   deviceWallPaper: () => {
-    return request("/mini/wx/config/wallpaperList", {
-      clientType: clientType,
-      type: type,
-      version: version,
-    }, "GET",)
+    return request("/mini/wx/config/wallpaperList", {}, "GET",)
   },
 
 }