12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <wxs module="utils">
- module.exports.max = function(n1, n2) {
- return Math.max(n1, n2)
- }
- module.exports.len = function(arr) {
- arr = arr || []
- return arr.length
- }
- </wxs>
- <button bindtap="openBluetoothAdapter">开始扫描</button>
- <button bindtap="stopBluetoothDevicesDiscovery">停止扫描</button>
- <button bindtap="closeBluetoothAdapter">结束流程</button>
-
- <view class="devices_summary">已发现 {{devices.length}} 个外围设备:</view>
- <scroll-view class="device_list" scroll-y scroll-with-animation>
- <view wx:for="{{devices}}" wx:key="index"
- data-device-id="{{item.deviceId}}"
- data-name="{{item.name || item.localName}}"
- data-mac="{{item.mac}}"
- data-index="{{index}}"
- bindtap="createBLEConnection"
- class="device_item"
- hover-class="device_item_hover">
- <view style="font-size: 16px; color: #333;">{{item.name}}</view>
- <view style="font-size: 10px">信号强度: {{item.RSSI}}dBm ({{utils.max(0, item.RSSI + 100)}}%)</view>
- <view style="font-size: 10px">mac地址: {{item.deviceId}}</view>
- <!-- <view style="font-size: 10px">Service数量: {{utils.len(item.advertisServiceUUIDs)}}</view> -->
- <view style="font-size: 14px">广播数据:{{item.analyzeDataText}}</view>
- </view>
- </scroll-view>
-
- <view class="connected_info" wx:if="{{connected}}">
- <view>
- <text>已连接到 {{name}}</text>
- <view class="operation">
- <!-- <button wx:if="{{canWrite}}" size="mini" bindtap="writeBLECharacteristicValue">写数据</button> -->
- <button size="mini" bindtap="showWriteInputView">写入指令</button>
- <button size="mini" bindtap="closeBLEConnection">断开连接</button>
- </view>
- </view>
- <view wx:for="{{chs}}" wx:key="index" style="font-size: 12px; margin-top: 10px;">
- <view>特性值: {{item.value}}</view>
- </view>
- </view>
- <view class="writeInputViewBg" wx:if="{{showWriteInput}}"></view>
- <view class="writeInputView" wx:if="{{showWriteInput}}">
- <view class="writeInput">
- <input bindinput="writingCmd"></input>
- </view>
- <view class="hint">请输入16进制数,Byte之间用空格或英文逗号分隔</view>
- <view class="btns">
- <button size="mini" bindtap="submitCmd">确定</button>
- <button size="mini" bindtap="hideWriteInputView">取消</button>
- </view>
- </view>
|