feat: support JW_ device ID format in QR scan and BLE matching
- parseDeviceId accepts hex with spaces (e.g. "672B6D5A 4DCD861") - BLE scan does exact match on "JW_<device_id>" when target is known - Manual input placeholder updated to show new format
这个提交包含在:
@@ -52,6 +52,7 @@ Page({
|
||||
}, SCAN_TIMEOUT)
|
||||
|
||||
ble.startScan({
|
||||
targetDeviceId: self.data.deviceId,
|
||||
onFound: function (device) {
|
||||
clearTimeout(self._scanTimer)
|
||||
self.setData({ state: 'connecting' })
|
||||
|
||||
@@ -43,7 +43,9 @@ Page({
|
||||
},
|
||||
|
||||
parseDeviceId: function (content) {
|
||||
content = (content || '').trim()
|
||||
if (/^[0-9A-Fa-f]{16}$/.test(content)) return content
|
||||
if (/^[0-9A-Fa-f]+([ _-][0-9A-Fa-f]+)+$/.test(content)) return content
|
||||
try {
|
||||
var url = new URL(content)
|
||||
var id = url.searchParams.get('device_id') || url.searchParams.get('id')
|
||||
@@ -79,11 +81,11 @@ Page({
|
||||
wx.showModal({
|
||||
title: '手动输入设备号',
|
||||
editable: true,
|
||||
placeholderText: '请输入16位设备ID',
|
||||
placeholderText: '请输入设备ID,如 672B6D5A 4DCD861',
|
||||
success: function (res) {
|
||||
if (res.confirm && res.content) {
|
||||
var deviceId = res.content.trim()
|
||||
if (/^[0-9A-Fa-f]{16}$/.test(deviceId)) {
|
||||
var deviceId = self.parseDeviceId(res.content)
|
||||
if (deviceId) {
|
||||
self.bindDevice(deviceId)
|
||||
} else {
|
||||
wx.showToast({ title: '设备号格式不正确', icon: 'none' })
|
||||
|
||||
@@ -239,6 +239,7 @@ function discoverServices(deviceId, callbacks) {
|
||||
// --- scan & connect ---
|
||||
|
||||
function startScan(callbacks) {
|
||||
var targetName = callbacks.targetDeviceId ? ('JW_' + callbacks.targetDeviceId).toUpperCase() : ''
|
||||
wx.openBluetoothAdapter({
|
||||
success: function () {
|
||||
wx.startBluetoothDevicesDiscovery({
|
||||
@@ -251,10 +252,15 @@ function startScan(callbacks) {
|
||||
var d = devices[i]
|
||||
var name = (d.name || '').toUpperCase()
|
||||
var localName = (d.localName || '').toUpperCase()
|
||||
var matched = name.indexOf('JW_') !== -1 || localName.indexOf('JW_') !== -1 ||
|
||||
var matched = false
|
||||
if (targetName) {
|
||||
matched = name === targetName || localName === targetName
|
||||
} else {
|
||||
matched = name.indexOf('JW_') !== -1 || localName.indexOf('JW_') !== -1 ||
|
||||
name.indexOf('HOX') !== -1 || localName.indexOf('HOX') !== -1 ||
|
||||
name.indexOf('LIGHTMASK') !== -1 || localName.indexOf('LIGHTMASK') !== -1 ||
|
||||
name.indexOf('SIMPLE PERIPHERAL') !== -1 || localName.indexOf('SIMPLE PERIPHERAL') !== -1
|
||||
}
|
||||
if (matched) {
|
||||
wx.stopBluetoothDevicesDiscovery({})
|
||||
if (callbacks.onFound) callbacks.onFound(d)
|
||||
|
||||
在新工单中引用
屏蔽一个用户