bluetooth.wxml 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <import src="../../../common/head.wxml" />
  2. <import src="../../../common/foot.wxml" />
  3. <wxs module="utils">
  4. module.exports.max = function(n1, n2) {
  5. return Math.max(n1, n2)
  6. }
  7. module.exports.len = function(arr) {
  8. arr = arr || []
  9. return arr.length
  10. }
  11. </wxs>
  12. <view class="container">
  13. <template is="head" data="{{title: 'bluetooth'}}"/>
  14. <view class="page-body">
  15. <view class="page-section">
  16. <view class="page-body-info">
  17. <view class="devices_summary">已发现 {{devices.length}} 个外围设备:</view>
  18. <scroll-view class="device_list" scroll-y scroll-with-animation>
  19. <view wx:for="{{devices}}" wx:key="index"
  20. data-device-id="{{item.deviceId}}"
  21. data-name="{{item.name || item.localName}}"
  22. bindtap="createBLEConnection"
  23. class="device_item"
  24. hover-class="device_item_hover">
  25. <view style="font-size: 16px; color: #333;">{{item.name}}</view>
  26. <view style="font-size: 10px">信号强度: {{item.RSSI}}dBm ({{utils.max(0, item.RSSI + 100)}}%)</view>
  27. <view style="font-size: 10px">UUID: {{item.deviceId}}</view>
  28. <view style="font-size: 10px">Service数量: {{utils.len(item.advertisServiceUUIDs)}}</view>
  29. </view>
  30. </scroll-view>
  31. </view>
  32. <view class="btn-area">
  33. <button type="primary" bindtap="openBluetoothAdapter">开始扫描</button>
  34. <button bindtap="stopBluetoothDevicesDiscovery">停止扫描</button>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="connected_info" wx:if="{{connected}}">
  39. <view>
  40. <text>已连接到 {{name}}</text>
  41. <view class="operation">
  42. <button wx:if="{{canWrite}}" size="mini" bindtap="writeBLECharacteristicValue">写数据</button>
  43. <button size="mini" bindtap="closeBLEConnection">断开连接</button>
  44. </view>
  45. </view>
  46. <view wx:for="{{chs}}" wx:key="index" style="font-size: 12px; margin-top: 10px;">
  47. <view>特性UUID: {{item.uuid}}</view>
  48. <view>特性值: {{item.value}}</view>
  49. </view>
  50. </view>
  51. <template is="foot" />
  52. </view>