kindring 1 年之前
父節點
當前提交
f33c105842

+ 3 - 3
app.json

@@ -1,9 +1,9 @@
 {
   "pages":[
     "pages/index/index",
-    "pages/old/index",
+    "pages/camera/camera",
     "pages/light/light",
-    "pages/tools/tools"
+    "pages/ble/ble"
   ],
   "tabBar": {
     "list": [
@@ -13,7 +13,7 @@
             "selectedIconPath": "icons/png/index-active.png"
         },
         {
-          "pagePath": "pages/old/index",
+          "pagePath": "pages/camera/camera",
           "iconPath": "icons/png/cam.png",
           "selectedIconPath": "icons/png/cam-active.png"
         },

+ 313 - 0
pages/ble/ble.js

@@ -0,0 +1,313 @@
+// pages/light/light.js
+import { connectStateMap, connectStateTypes } from '../../data/devType.js'
+import { MAX_COLOR_TEMPERATURE, MIN_COLOR_TEMPERATURE, COLOR_TEMPERATURE_STEP, bleInfo } from '../../data/lampType.js'
+import { handle } from '../../utils/mjs_handle.js'
+import { calculateColor } from '../../utils/mjs_color.js'
+import light_cmd from '../../utils/light_cmd.js'
+import { _curry } from '../../utils/mjs_curry.js'
+import BLE from '../../utils/mjs_wxble.js'
+console.log(BLE);
+const ble = new BLE();
+/** mock 数据 */
+const mock_bleDevs = [
+    {
+        id: 1,
+        name: "123",
+        deviceId: "1234"
+    },
+    {
+        id: 2,
+        name: "设备2",
+        deviceId: "23456"
+    }
+]
+const mock_bleServices = [
+  {
+    uuid: "123",
+    isPrimary: true,
+    characteristics: [
+      {
+        uuid: "123",
+        properties: {
+          read: true,
+          write: true,
+          notify: true,
+          indicate: true,
+        }
+      }
+    ]
+  },
+  {
+    uuid: "1234",
+    characteristics: [
+      {
+        uuid: "12345",
+        properties: {
+          read: true,
+          write: true,
+          notify: true,
+          indicate: true,
+        }
+      },
+      {
+        uuid: "123456",
+        properties: {
+          read: true,
+          write: true,
+          notify: true,
+          indicate: true,
+        }
+      }
+    ]
+  }
+]
+
+// 蓝牙模块连接对象信息参数
+const connectBleParams = [];
+// 蓝牙服务信息
+let bleServices = [];
+Page({
+    /**
+     * 页面的初始数据
+     */
+    data: {
+        // unConnect scaning connecting connected
+        connectStateTypes: connectStateTypes,
+        ble: {
+            state: connectStateTypes.unConnect,
+            devName: "123",
+            deviceId: "",
+            init: false,
+            // 控制uuid
+            controlUuid: "",
+            // 监听数据uuid
+            notifyUuid: "",
+        },
+        bleDevs: mock_bleDevs,
+        bleServices: mock_bleServices,
+    },
+
+    searchDeviceHandle() {
+      this.excuteSearchDevice();
+    },
+    disconnectHandle(){
+      this.excuteDisconnect();
+    },
+
+    async excuteDisconnect(){
+      console.log('断开连接');
+      if(this.data.ble.state !== connectStateTypes.connected){
+        return this.bleFail('断开连接失败', '当前未连接设备');
+      }
+      let err,res;
+      [err,res] = ble.disconnectDev(this.data.ble.deviceId);
+      if(err){
+        return this.bleFail('断开连接失败', err.errMsg);
+      }
+      wx.showToast({title: `断开连接成功`, })
+      this.initPageInfo();
+    },
+    // 获取蓝牙发送数据对象
+    excuteBleSend(data){
+      console.log('获取蓝牙发送数据对象');
+      // 固定值
+      let controlUuid = bleInfo.controlUuid;
+      let characteristicFirstUuid = bleInfo.characteristicFirstUuid;
+
+      let deviceId = this.data.ble.deviceId;
+      let serverUuid = '';
+      let characteristicUuid = '';
+      let characteristic;
+      let server = bleServices.find(s=>{
+        console.log(`服务uuid ${s.uuid}`);
+        console.log(s);
+        return s.uuid.startsWith(controlUuid);
+      });
+      if(!server)
+      {
+        serverUuid = bleInfo.controlUuid;
+      }else
+      {
+        serverUuid = server.uuid;
+        characteristic = server.characteristics.find(c=>
+          c.uuid.startsWith(characteristicFirstUuid)
+        );
+      }
+
+      //获取
+      
+      
+      if(!characteristic)
+      {
+        // return bleFail('获取服务失败', '该设备不支持该程序');
+        characteristicUuid = bleInfo.controlUuid;
+      }
+      else
+      {
+        characteristicUuid = characteristic.uuid;
+      }
+      console.log(`服务uuid ${serverUuid} 特征uuid ${characteristicUuid}`);
+
+      return ble.sendData(deviceId, serverUuid, characteristicUuid, data);
+    },
+    
+    initPageInfo(){
+      this.setData({
+        ble: {...this.data.ble, 
+          state: connectStateTypes.unConnect, 
+          init: false,
+          devName: "",
+          deviceId: "",
+        },
+        bleDevs: [],
+        bleServices: []
+      });
+      bleServices = [];
+    },
+    // 连接失败
+    bleFail(title,msg){
+      wx.showModal({
+        title: title,
+        content: msg,
+        success: (res) =>{ 
+          this.initPageInfo();
+        }
+      });
+    },
+
+    
+    
+    async excuteSearchDevice(){
+        console.log("搜索 蓝牙设备");
+        let err,res;
+        if(!this.data.ble.init){
+          [err,res] = await handle(ble.initBle());
+          if(err){
+            return this.bleFail('蓝牙初始化失败', err.errMsg);
+          }
+          ble.onSearch = this.onSearchHandle;
+        }
+        this.setData({
+          ble: {...this.data.ble, 
+            state: connectStateTypes.scaning, 
+            init: true
+          },
+          bleDevs: []
+        });
+        ble.search(this.onSearchHandle);
+    },
+    // 搜索到设备基础函数
+    onSearchHandle(device){
+      console.log('搜索到设备');
+      if(this.data.bleDevs.find(dev=>dev.deviceId === device.deviceId )){
+        return console.log('设备再次被搜索到');
+      }
+      console.log(device);
+      device.id = device.deviceId;
+      let arr = this.data.bleDevs;
+      arr.push(device);
+      this.setData({
+        bleDevs: arr
+      })
+    },
+    // 连接设备
+    async connectDevHandle(e) {
+      console.log("click connectDev")
+      let err,res;
+      let dev = e.detail;
+      console.log(dev);
+      this.setData({
+        ble: {...this.data.ble,state: connectStateTypes.connecting, 
+          devName: dev.name, 
+          deviceId: dev.deviceId
+        },
+      });
+      // 停止搜索
+      [err,res] = await handle(ble.stopSearch());
+      if(err){
+        return this.bleFail('停止搜索失败', err.errMsg);
+      }
+      wx.showToast({title: `连接${dev.name}中...`, })
+      // 连接至设备
+      [err,res] = await handle(ble.connectDev(dev.deviceId));
+      if(err){  return this.bleFail('连接失败', err.errMsg);}
+      // 连接成功
+      this.setData({
+        ble:{...this.data.ble, state:connectStateTypes.connected }
+      });
+      // 设备服务管理
+      this.connectServices(dev.deviceId);
+  },
+
+  async connectServices(deviceId){
+      let [err,res] = await handle(ble.getBleServices(deviceId));
+      if(err){ return this.bleFail('获取服务失败', err.errMsg);}
+      // 保存服务信息;
+      bleServices = res;
+      this.setData({
+        bleServices: res
+      })
+  },
+
+
+
+      
+    /**
+     * 生命周期函数--监听页面加载
+     */
+    onLoad(options) {
+  
+    },
+  
+    /**
+     * 生命周期函数--监听页面初次渲染完成
+     */
+    onReady() {
+  
+    },
+  
+    /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow() {
+    // 配置导航栏
+    wx.setNavigationBarTitle({
+      title: '蓝牙工具箱'
+    })
+  },
+  
+    /**
+     * 生命周期函数--监听页面隐藏
+     */
+    onHide() {
+  
+    },
+  
+    /**
+     * 生命周期函数--监听页面卸载
+     */
+    onUnload() {
+  
+    },
+  
+    /**
+     * 页面相关事件处理函数--监听用户下拉动作
+     */
+    onPullDownRefresh() {
+  
+    },
+  
+    /**
+     * 页面上拉触底事件的处理函数
+     */
+    onReachBottom() {
+  
+    },
+  
+    /**
+     * 用户点击右上角分享
+     */
+    onShareAppMessage() {
+  
+    }
+  })

+ 8 - 0
pages/ble/ble.json

@@ -0,0 +1,8 @@
+{
+    "usingComponents": {
+        "fnState": "/components/fnState/fnState",
+        "scanHandle": "/components/scanHandle/scanHandle",
+        "tabList": "/components/tabList/tabList"
+    },
+    "disableScroll":true
+}

+ 74 - 0
pages/ble/ble.wxml

@@ -0,0 +1,74 @@
+<!--pages/light/light.wxml-->
+<view class="lamp" hover-class="none" hover-stop-propagation="false">
+    <view class="lamp_header">
+        <scanHandle 
+            state="{{ble.state}}" 
+            dev-name="{{ble.devName}}"
+            bindsearchDevice="searchDeviceHandle"
+            />
+    </view>
+    
+
+    <view class="lamp__content" style="background-color:{{lamp.bgc}}">
+        <tabList
+        wx:if="{{ble.state === connectStateTypes.scaning || ble.state === connectStateTypes.connecting}}"
+        ble-devs="{{ bleDevs }}"
+        bindconnectDev="connectDevHandle">
+        </tabList>
+
+        <view class="lampControl" 
+        wx:if="{{ble.state === connectStateTypes.connected}}"
+        >
+
+            <!-- 设备名称 -->
+            <view class="lampControl__device_name">
+                <view class="deviceName">
+                设备名称: {{ble.devName}}
+                </view>
+                <div class="action">
+                    <view class="btn" hover-class="none" hover-stop-propagation="false" bindtap="disconnectHandle">
+                        断开连接
+                    </view>
+                </div>
+            </view>
+            <div class="service_items">
+                <!-- 服务控制 -->
+                <view class="service_item" wx:for="{{bleServices}}" 
+                wx:key="i" 
+                wx:for-item="item">
+                    <!-- 服务主信息 -->
+                    <view class="service_title">
+                        <view class="title_name">
+                            {{item.uuid}}
+                        </view>
+                        <view class="table_icon">
+                            {{item.isPrimary ? '主服务' : '次服务'}}
+                        </view>
+                    </view>
+                    
+                    <!-- 子服务列表 -->
+                    <view 
+                    class="service_characteristics" 
+                    wx:for="{{item.characteristics}}" 
+                    wx:key="j"
+                    wx:for-item="characteristic" >
+                        {{characteristic.uuid}}
+                    </view>
+
+                </view>
+            </div>
+            
+        </view>
+
+
+        <!-- 开始扫描按钮 -->
+        <view class="lampControl lampControl__scan"
+        wx:if="{{ble.state === connectStateTypes.unConnect}}"
+        >
+            <view class="scanBtn" hover-class="none" hover-stop-propagation="false" bindtap="searchDeviceHandle">
+                开始扫描
+            </view>
+        </view>
+
+    </view>
+</view>

+ 183 - 0
pages/ble/ble.wxss

@@ -0,0 +1,183 @@
+.lamp{
+    width: 100vw;
+    height: 100vh;
+    position: relative;
+    background-color: #3b3b3b;
+}
+.lamp_header{
+    width: 100%;
+    height: 40px;
+    background-color: #fff;
+    box-sizing: border-box;
+}
+.lamp__content{
+    width: 100%;
+    min-height: 100vh;
+    position: relative;
+    height: calc(100% - 40px);
+    /* 暗灰 */
+    background-color: #3b3b3b;
+    box-sizing: border-box;
+    padding-bottom: 40px;
+    overflow: hidden;
+}
+
+.lampControl{
+    width: 100%;
+    height: auto;
+    padding: 5px 20px;
+    box-sizing: border-box;
+}
+.lampControl .lampControl__device_name{
+    width: 100%;
+    height: 40px;
+    margin-bottom: 5px;
+    padding: 0 20px;
+    /* box-sizing: border-box; */
+    margin-left: -20px;
+    margin-top: -5px;
+    display: flex;
+    align-items: center;
+    justify-content: space-between;
+    background-color: #fff;
+    /* border-radius: 5px; */
+}
+.deviceName{
+    font-size: 18px;
+    font-weight: bold;
+}
+
+.service_items{
+    width: 100%;
+    height: calc(100% - 40px);
+    padding: 5px 20px;
+    box-sizing: border-box;
+    overflow: auto;
+}
+.service_item{
+    width: 100%;
+    height: auto;
+    margin-bottom: 5px;
+    background-color: #fff;
+    border-radius: 5px;
+    padding: 5px 10px;
+    box-sizing: border-box;
+}
+
+.service_item .service_title{
+    font-size: 18px;
+    font-weight: bold;
+    margin-bottom: 5px;
+    display: flex;
+    align-items: center;
+    justify-content: space-between;
+    padding: 5px;
+    box-sizing: border-box;
+    border-bottom: #00a790 1px solid;
+}
+
+.service_characteristics{
+    width: 100%;
+    height: auto;
+    padding: 5px;
+    margin-top: 5px;
+    box-sizing: border-box;
+    display: flex;
+    flex-wrap: wrap;
+    justify-content: space-between;
+}
+
+.lampControl__switch{
+    width: 30px;
+    height: 30px;
+    border-radius: 50%;
+    background-color: #3b3b3b;
+    align-items: center;
+    padding: 5px;
+    box-sizing: border-box;
+}
+
+.switch-open{
+    background-color: #f58505;
+}
+
+.lampControl__switch image{
+    width: 100%;
+    height: 100%;
+}
+
+.lampControl__switch-text{
+    font-size: 18px;
+    margin-left: 10px;
+}
+
+
+.lampControl_title{
+    font-size: 18px;
+    font-weight: bold;
+    margin-bottom: 10px;
+    display: flex;
+    align-items: center;
+}
+.lampControl_title .subTitle{
+    font-size: 14px;
+    font-weight: normal;
+    margin-left: 10px;
+}
+
+.lampControl_slider{
+    width: 100%;
+    height: 50px;
+}
+
+.lampControl__scan{
+    width: 100%;
+    height: calc(100% - 40px);
+    border-radius: 5px;
+    box-shadow: 0 0 1px 0px #3b3b3b;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    box-sizing: border-box;
+}
+
+.lampControl__scan .scanBtn{
+    width: 130px;
+    height: 130px;
+    border-radius: 50%;
+    background-color: #f58505;
+    color:#fff;
+    padding: 5px;
+    font-size: larger;
+    box-sizing: border-box;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    box-shadow: 0 0 1px 0px #3b3b3b;
+}
+
+.scanBtn:active{
+    background-color: #f78e16;
+    box-shadow: 0 0 3px 0px #858484;
+}
+
+
+
+.btn{
+    display: flex;
+    justify-content: center;
+    align-items: center;
+    box-sizing: border-box;
+    border-radius: 3px;
+    background-color: #00a790;
+    color: white;
+    padding: 5px 25px;
+    width: auto;
+    height: auto;
+    box-shadow: 1px 1px 5px rgb(119, 119, 119);
+  }
+  
+  .btn:active{
+    background-color: #00a790;
+    box-shadow: 1px 1px 3px black;
+  }

+ 278 - 0
pages/camera/camera.js

@@ -0,0 +1,278 @@
+// pages/light/light.js
+import { connectStateMap, connectStateTypes } from '../../data/devType.js'
+import { MAX_COLOR_TEMPERATURE, MIN_COLOR_TEMPERATURE, COLOR_TEMPERATURE_STEP, bleInfo } from '../../data/lampType.js'
+import { handle } from '../../utils/mjs_handle.js'
+import { calculateColor } from '../../utils/mjs_color.js'
+import light_cmd from '../../utils/light_cmd.js'
+import { _curry } from '../../utils/mjs_curry.js'
+import BLE from '../../utils/mjs_wxble.js'
+console.log(BLE);
+const ble = "";
+// new BLE(null, ["bleLight"]);
+const tmpDevs = [
+    {
+        id: 1,
+        name: "123",
+        deviceId: "1234"
+    },
+    {
+        id: 2,
+        name: "设备2",
+        deviceId: "23456"
+    }
+]
+// 蓝牙模块连接对象信息参数
+const connectBleParams = [];
+// 蓝牙服务信息
+let bleServices = [];
+Page({
+
+    /**
+     * 页面的初始数据
+     */
+    data: {
+        // unConnect scaning connecting connected
+        connectStateTypes: connectStateTypes,
+        ble: {
+            state: connectStateTypes.unConnect,
+            devName: "",
+            deviceId: "",
+            init: false,
+            // 控制uuid
+            controlUuid: "",
+            // 监听数据uuid
+            notifyUuid: "",
+        },
+        lamp: {
+            // 信息相关
+            temp_max: MAX_COLOR_TEMPERATURE,
+            temp_min: MIN_COLOR_TEMPERATURE,
+            temp_step: COLOR_TEMPERATURE_STEP,
+            // 开关状态
+            switch: false,
+            // 全开状态(无色温调节)
+            fullOpen: false,
+            // 亮度
+            brightness: 50,
+            // 色温
+            colorTemperature: MAX_COLOR_TEMPERATURE,
+            // 色彩
+            bgc: "#3b3b3b"
+        },
+        bleDevs: tmpDevs,
+    },
+    // 切换设备handle
+    switchCameraHandle(e){
+      let deviceCode = e.currentTarget.dataset.dev;
+      this.excuteSwitchCamera(deviceCode);
+    },
+
+
+    /**
+     * 切换控制的设备
+     * @param {*} deviceCode 
+     */
+    excuteSwitchCamera(deviceCode){
+        // 使用策略模式
+    },
+
+    // 获取蓝牙发送数据对象
+    excuteBleSend(data){
+      console.log('获取蓝牙发送数据对象');
+      // 固定值
+      let controlUuid = bleInfo.controlUuid;
+      let characteristicFirstUuid = bleInfo.characteristicFirstUuid;
+
+      let deviceId = this.data.ble.deviceId;
+      let serverUuid = '';
+      let characteristicUuid = '';
+      let characteristic;
+      let server = bleServices.find(s=>{
+        console.log(`服务uuid ${s.uuid}`);
+        console.log(s);
+        return s.uuid.startsWith(controlUuid);
+      });
+      if(!server)
+      {
+        serverUuid = bleInfo.controlUuid;
+      }else
+      {
+        serverUuid = server.uuid;
+        characteristic = server.characteristics.find(c=>
+          c.uuid.startsWith(characteristicFirstUuid)
+        );
+      }
+
+      //获取
+      
+      
+      if(!characteristic)
+      {
+        // return bleFail('获取服务失败', '该设备不支持该程序');
+        characteristicUuid = bleInfo.controlUuid;
+      }
+      else
+      {
+        characteristicUuid = characteristic.uuid;
+      }
+      console.log(`服务uuid ${serverUuid} 特征uuid ${characteristicUuid}`);
+
+      return ble.sendData(deviceId, serverUuid, characteristicUuid, data);
+    },
+    
+    bleFail(title,msg){
+      wx.showModal({
+        title: title,
+        content: msg,
+        success (res) { 
+          this.setData({
+            ble: {...this.data.ble, 
+              state: connectStateTypes.unConnect, 
+              init: false,
+              devName: "",
+              deviceId: "",
+            },
+            bleDevs: []
+          });
+          bleServices = [];
+        }
+      });
+    },
+    // 蓝牙控制板块
+    searchDeviceHandle() {
+        // 开始搜索设备
+        this.excuteSearchDevice();
+    },
+    
+    async excuteSearchDevice(){
+        console.log("搜索 蓝牙设备");
+        let err,res;
+        if(!this.data.ble.init){
+          [err,res] = await handle(ble.initBle());
+          if(err){
+            return this.bleFail('蓝牙初始化失败', err.errMsg);
+          }
+          ble.onSearch = this.onSearchHandle;
+        }
+        this.setData({
+          ble: {...this.data.ble, 
+            state: connectStateTypes.scaning, 
+            init: true
+          },
+          bleDevs: []
+        });
+        ble.search(this.onSearchHandle);
+    },
+    // 搜索到设备基础函数
+    onSearchHandle(device){
+      console.log('搜索到设备');
+      if(this.data.bleDevs.find(dev=>dev.deviceId === device.deviceId )){
+        return console.log('设备再次被搜索到');
+      }
+      console.log(device);
+      device.id = device.deviceId;
+      let arr = this.data.bleDevs;
+      arr.push(device);
+      this.setData({
+        bleDevs: arr
+      })
+    },
+    // 连接设备
+    async connectDevHandle(e) {
+      console.log("click connectDev")
+      let err,res;
+      let dev = e.detail;
+      console.log(dev);
+      this.setData({
+        ble: {...this.data.ble,state: connectStateTypes.connecting, 
+          devName: dev.name, 
+          deviceId: dev.deviceId
+        },
+      });
+      // 停止搜索
+      [err,res] = await handle(ble.stopSearch());
+      if(err){
+        return this.bleFail('停止搜索失败', err.errMsg);
+      }
+      wx.showToast({title: `连接${dev.name}中...`, })
+      // 连接至设备
+      [err,res] = await handle(ble.connectDev(dev.deviceId));
+      if(err){  return this.bleFail('连接失败', err.errMsg);}
+      // 连接成功
+      this.setData({
+        ble:{...this.data.ble, state:connectStateTypes.connected }
+      });
+      // 设备服务管理
+      this.connectServices(dev.deviceId);
+    },
+    // 获取蓝牙服务
+    async connectServices(deviceId){
+        // uuid FF01
+        let [err,res] = await handle(ble.getBleServices(deviceId));
+        if(err){ return this.bleFail('获取服务失败', err.errMsg);}
+        // 保存服务信息;
+        bleServices = res;
+    },
+
+
+
+      
+    /**
+     * 生命周期函数--监听页面加载
+     */
+    onLoad(options) {
+  
+    },
+  
+    /**
+     * 生命周期函数--监听页面初次渲染完成
+     */
+    onReady() {
+  
+    },
+  
+    /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow() {
+    // 配置导航栏
+    wx.setNavigationBarTitle({
+      title: '相机控制器'
+    })
+  },
+  
+    /**
+     * 生命周期函数--监听页面隐藏
+     */
+    onHide() {
+  
+    },
+  
+    /**
+     * 生命周期函数--监听页面卸载
+     */
+    onUnload() {
+  
+    },
+  
+    /**
+     * 页面相关事件处理函数--监听用户下拉动作
+     */
+    onPullDownRefresh() {
+  
+    },
+  
+    /**
+     * 页面上拉触底事件的处理函数
+     */
+    onReachBottom() {
+  
+    },
+  
+    /**
+     * 用户点击右上角分享
+     */
+    onShareAppMessage() {
+  
+    }
+  })

+ 8 - 0
pages/camera/camera.json

@@ -0,0 +1,8 @@
+{
+    "usingComponents": {
+        "fnState": "/components/fnState/fnState",
+        "scanHandle": "/components/scanHandle/scanHandle",
+        "tabList": "/components/tabList/tabList"
+    },
+    "disableScroll":true
+}

+ 113 - 0
pages/camera/camera.wxml

@@ -0,0 +1,113 @@
+<!--pages/light/light.wxml-->
+<view class="lamp" hover-class="none" hover-stop-propagation="false">
+    <view class="lamp_header">
+        <scanHandle 
+            state="{{ble.state}}" 
+            dev-name="{{ble.devName}}"
+            bindsearchDevice="searchDeviceHandle"
+            />
+    </view>
+    
+
+    <view class="lamp__content" style="background-color:{{lamp.bgc}}">
+        <!-- 设备列表 -->
+        <tabList
+        wx:if="{{ble.state === connectStateTypes.scaning || ble.state === connectStateTypes.connecting}}"
+        ble-devs="{{ bleDevs }}"
+        bindconnectDev="connectDevHandle">
+        </tabList>
+
+
+
+        <!-- 灯光控制 -->
+        <view class="lampControl" 
+        wx:if="{{ble.state === connectStateTypes.connected}}"
+        
+        >
+            <!-- 占位块 -->
+            <view class="lampControl__placeholder"></view>
+            <!-- 开关 -->
+            <view class="lampControl_chunk lampControl_title lampControl__switch"
+            bindtap="switchHandle"
+            >
+                <!-- icon -->
+                <view class="{{lamp.switch?'lampControl__switch switch-open':'lampControl__switch'  }}">
+                    <image src="/icons/png/switch.png" />
+                </view>
+                <!-- 文字 -->
+                <view class="lampControl__switch-text">
+                    <text>{{lamp.switch ? '关闭' : '打开'}}</text>
+                </view>
+            </view>
+
+            <!-- 亮度 -->
+            <view class="lampControl_chunk lampControl__brightness">
+                <!-- 文字 -->
+                <view class="lampControl_title">
+                    <text>亮度</text>
+                    <!-- 值 -->
+                    <text class="subTitle">{{lamp.brightness}}%</text>
+                </view>
+                <!-- 滑块 -->
+                <view class="lampControl_slider">
+                    <slider 
+                    value="{{lamp.brightness}}" 
+                    min="0" 
+                    max="100" 
+                    disabled="{{!lamp.switch}}"
+                    bindchange="brightnessChangeHandle"
+                    />
+                </view>
+            </view>
+
+            <!-- 色温 -->
+            <view class="lampControl_chunk lampControl__color">
+                <!-- 文字 -->
+                <view class="lampControl_title">
+                    <text>色温</text>
+                    <!-- 分隔装饰 -->
+                    <!-- 值 -->
+                    <text class="subTitle">{{lamp.colorTemperature}}K</text>
+                </view>
+                <!-- 滑块 -->
+                <view class="lampControl_slider">
+                    <slider 
+                    value="{{lamp.colorTemperature}}" 
+                    min="{{lamp.temp_min}}" 
+                    max="{{lamp.temp_max}}" 
+                    step="{{lamp.temp_step}}" 
+                    disabled="{{!lamp.switch || lamp.fullOpen}}"
+                    bindchange="colorChangeHandle"
+                    />
+                </view>
+            </view>
+
+            <view class="lampControl_chunk lampControl_title lampControl__color"
+            bindtap="fullModeSwitchHandle"
+            >
+            <!-- icon -->
+                <view class="{{lamp.fullOpen?'lampControl__switch switch-open':'lampControl__switch'  }}">
+                    <image src="/icons/png/switch.png" />
+                </view>
+                <!-- 文字 -->
+                <view class="lampControl__switch-text">
+                    <text>{{lamp.fullOpen ? '关闭' : '全开模式'}}</text>
+                </view>
+            </view>
+
+            <!-- todo: 更多自定义模式 -->
+
+        </view>
+
+        <!-- 开始扫描按钮 -->
+        <view class="lampControl lampControl__scan"
+        wx:if="{{ble.state === connectStateTypes.unConnect}}"
+        
+        >
+            <view class="lampControl__item" data-dev="{{'sony-a7c'}}" bindtap="switchCameraHandle">
+                <text>查找 SONY A7C 设备</text>
+            </view>
+        </view>
+
+    </view>
+</view>

+ 124 - 0
pages/camera/camera.wxss

@@ -0,0 +1,124 @@
+.lamp{
+    width: 100vw;
+    height: 100vh;
+    position: relative;
+    background-color: #3b3b3b;
+}
+.lamp_header{
+    width: 100%;
+    height: 40px;
+    background-color: #fff;
+    box-sizing: border-box;
+}
+.lamp__content{
+    width: 100%;
+    height: auto;
+    min-height: 100vh;
+    position: relative;
+    height: calc(100% - 40px);
+    /* 暗灰 */
+    background-color: #3b3b3b;
+    box-sizing: border-box;
+    padding-bottom: 40px;
+}
+
+.lampControl{
+    width: 100%;
+    height: auto;
+    padding: 5px 20px;
+    box-sizing: border-box;
+}
+
+.lampControl .lampControl__placeholder{
+    width: 100%;
+    height: 180px;
+}
+
+.lampControl .lampControl_chunk{
+    width: 100%;
+    border-radius: 5px;
+    background-color: #fff;
+    padding: 5px 10px;
+    margin-top: 20px;
+    box-sizing: border-box;
+    box-shadow: 0 0 1px 0px #3b3b3b;
+}
+.lampControl .lampControl_title{
+    height: 40px;
+    font-size: 18px;
+    font-weight: bold;
+    margin-bottom: 5px;
+    display: flex;
+    align-items: center;
+}
+
+.lampControl__switch{
+    width: 30px;
+    height: 30px;
+    border-radius: 50%;
+    background-color: #3b3b3b;
+    align-items: center;
+    padding: 5px;
+    box-sizing: border-box;
+}
+
+.switch-open{
+    background-color: #f58505;
+}
+
+.lampControl__switch image{
+    width: 100%;
+    height: 100%;
+}
+
+.lampControl__switch-text{
+    font-size: 18px;
+    margin-left: 10px;
+}
+
+
+.lampControl_title{
+    font-size: 18px;
+    font-weight: bold;
+    margin-bottom: 10px;
+    display: flex;
+    align-items: center;
+}
+.lampControl_title .subTitle{
+    font-size: 14px;
+    font-weight: normal;
+    margin-left: 10px;
+}
+
+.lampControl_slider{
+    width: 100%;
+    height: 50px;
+}
+
+.lampControl__scan{
+    width: 100%;
+    height: calc(100% - 40px);
+    box-shadow: 0 0 1px 0px #3b3b3b;
+    box-sizing: border-box;
+    padding: 10px;
+}
+
+.lampControl__scan .lampControl__item{
+    width: 100%;
+    height: auto;
+    border-radius: 5px;
+    background-color: #fff;
+    padding: 15px 10px;
+    font-size: larger;
+    box-sizing: border-box;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    box-shadow: 0 0 1px 0px #3b3b3b;
+}
+
+.lampControl__item:active{
+    background-color: #f78e16;
+    box-shadow: 0 0 3px 0px #858484;
+    color: #fff;
+}

+ 7 - 2
pages/index/index.js

@@ -20,11 +20,16 @@ Page({
           url: '/pages/light/light',
         })
         break;
-      case 'sony':
+      case 'camera':
           wx.switchTab({
-            url: '/pages/old/index',
+            url: '/pages/camera/camera',
           })
           break;
+      case 'bleTool':
+        wx.navigateTo({
+          url: '/pages/ble/ble',
+        })
+        break;
       default:
         wx.showToast({
           title: '该页面正在开发中',

+ 2 - 2
pages/index/index.wxml

@@ -35,7 +35,7 @@
 
 <!-- 居中路由按钮. 实现立即跳转至对应页面-->
         <view class="c-btn" >
-            <view class="btn" data-dev="{{'sony'}}" bindtap="openPageHandle" >立即使用</view>
+            <view class="btn" data-dev="{{'camera'}}" bindtap="openPageHandle" >立即使用</view>
         </view>
         </view>
     </view>
@@ -50,7 +50,7 @@
             </text>
         </view>
         <view class="c-btn">
-            <view class="btn">立即使用</view>
+            <view class="btn" data-dev="{{'bleTool'}}" bindtap="openPageHandle">立即使用</view>
         </view>
     </view>
 

+ 1 - 2
pages/light/light.wxml

@@ -101,9 +101,8 @@
         <!-- 开始扫描按钮 -->
         <view class="lampControl lampControl__scan"
         wx:if="{{ble.state === connectStateTypes.unConnect}}"
-        bindtap="searchDeviceHandle"
         >
-            <view class="scanBtn" hover-class="none" hover-stop-propagation="false">
+            <view class="scanBtn" hover-class="none" hover-stop-propagation="false" bindtap="searchDeviceHandle">
                 开始扫描
             </view>
         </view>

+ 1 - 0
pages/light/light.wxss

@@ -20,6 +20,7 @@
     background-color: #3b3b3b;
     box-sizing: border-box;
     padding-bottom: 40px;
+    overflow: hidden;
 }
 
 .lampControl{

+ 0 - 66
pages/tools/tools.js

@@ -1,66 +0,0 @@
-// pages/tools/tools.js
-Page({
-
-  /**
-   * 页面的初始数据
-   */
-  data: {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面加载
-   */
-  onLoad(options) {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面初次渲染完成
-   */
-  onReady() {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面显示
-   */
-  onShow() {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面隐藏
-   */
-  onHide() {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面卸载
-   */
-  onUnload() {
-
-  },
-
-  /**
-   * 页面相关事件处理函数--监听用户下拉动作
-   */
-  onPullDownRefresh() {
-
-  },
-
-  /**
-   * 页面上拉触底事件的处理函数
-   */
-  onReachBottom() {
-
-  },
-
-  /**
-   * 用户点击右上角分享
-   */
-  onShareAppMessage() {
-
-  }
-})

+ 0 - 3
pages/tools/tools.json

@@ -1,3 +0,0 @@
-{
-  "usingComponents": {}
-}

+ 0 - 2
pages/tools/tools.wxml

@@ -1,2 +0,0 @@
-<!--pages/tools/tools.wxml-->
-<text>pages/tools/tools.wxml</text>

+ 0 - 2
pages/tools/tools.wxss

@@ -1,2 +0,0 @@
-/* pages/tools/tools.wxss */
-

+ 14 - 1
utils/mjs_wxble.js

@@ -255,7 +255,20 @@ class BLE{
       });
     })
   }
-  // 
+  // 断开与设备的连接
+  disconnectDev(devId){
+    return new Promise((resolve,reject)=>{
+      wx.closeBLEConnection({
+        deviceId: devId,
+        success(res) {
+          resolve(res);
+        },
+        fail(err){
+          reject(err);
+        }
+      })
+    })
+  }
 }
 
 export default BLE;