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)
|
}, SCAN_TIMEOUT)
|
||||||
|
|
||||||
ble.startScan({
|
ble.startScan({
|
||||||
|
targetDeviceId: self.data.deviceId,
|
||||||
onFound: function (device) {
|
onFound: function (device) {
|
||||||
clearTimeout(self._scanTimer)
|
clearTimeout(self._scanTimer)
|
||||||
self.setData({ state: 'connecting' })
|
self.setData({ state: 'connecting' })
|
||||||
|
|||||||
@@ -43,7 +43,9 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
parseDeviceId: function (content) {
|
parseDeviceId: function (content) {
|
||||||
|
content = (content || '').trim()
|
||||||
if (/^[0-9A-Fa-f]{16}$/.test(content)) return content
|
if (/^[0-9A-Fa-f]{16}$/.test(content)) return content
|
||||||
|
if (/^[0-9A-Fa-f]+([ _-][0-9A-Fa-f]+)+$/.test(content)) return content
|
||||||
try {
|
try {
|
||||||
var url = new URL(content)
|
var url = new URL(content)
|
||||||
var id = url.searchParams.get('device_id') || url.searchParams.get('id')
|
var id = url.searchParams.get('device_id') || url.searchParams.get('id')
|
||||||
@@ -79,11 +81,11 @@ Page({
|
|||||||
wx.showModal({
|
wx.showModal({
|
||||||
title: '手动输入设备号',
|
title: '手动输入设备号',
|
||||||
editable: true,
|
editable: true,
|
||||||
placeholderText: '请输入16位设备ID',
|
placeholderText: '请输入设备ID,如 672B6D5A 4DCD861',
|
||||||
success: function (res) {
|
success: function (res) {
|
||||||
if (res.confirm && res.content) {
|
if (res.confirm && res.content) {
|
||||||
var deviceId = res.content.trim()
|
var deviceId = self.parseDeviceId(res.content)
|
||||||
if (/^[0-9A-Fa-f]{16}$/.test(deviceId)) {
|
if (deviceId) {
|
||||||
self.bindDevice(deviceId)
|
self.bindDevice(deviceId)
|
||||||
} else {
|
} else {
|
||||||
wx.showToast({ title: '设备号格式不正确', icon: 'none' })
|
wx.showToast({ title: '设备号格式不正确', icon: 'none' })
|
||||||
|
|||||||
@@ -239,6 +239,7 @@ function discoverServices(deviceId, callbacks) {
|
|||||||
// --- scan & connect ---
|
// --- scan & connect ---
|
||||||
|
|
||||||
function startScan(callbacks) {
|
function startScan(callbacks) {
|
||||||
|
var targetName = callbacks.targetDeviceId ? ('JW_' + callbacks.targetDeviceId).toUpperCase() : ''
|
||||||
wx.openBluetoothAdapter({
|
wx.openBluetoothAdapter({
|
||||||
success: function () {
|
success: function () {
|
||||||
wx.startBluetoothDevicesDiscovery({
|
wx.startBluetoothDevicesDiscovery({
|
||||||
@@ -251,10 +252,15 @@ function startScan(callbacks) {
|
|||||||
var d = devices[i]
|
var d = devices[i]
|
||||||
var name = (d.name || '').toUpperCase()
|
var name = (d.name || '').toUpperCase()
|
||||||
var localName = (d.localName || '').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('HOX') !== -1 || localName.indexOf('HOX') !== -1 ||
|
||||||
name.indexOf('LIGHTMASK') !== -1 || localName.indexOf('LIGHTMASK') !== -1 ||
|
name.indexOf('LIGHTMASK') !== -1 || localName.indexOf('LIGHTMASK') !== -1 ||
|
||||||
name.indexOf('SIMPLE PERIPHERAL') !== -1 || localName.indexOf('SIMPLE PERIPHERAL') !== -1
|
name.indexOf('SIMPLE PERIPHERAL') !== -1 || localName.indexOf('SIMPLE PERIPHERAL') !== -1
|
||||||
|
}
|
||||||
if (matched) {
|
if (matched) {
|
||||||
wx.stopBluetoothDevicesDiscovery({})
|
wx.stopBluetoothDevicesDiscovery({})
|
||||||
if (callbacks.onFound) callbacks.onFound(d)
|
if (callbacks.onFound) callbacks.onFound(d)
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户