Commit a1ed6bce authored by martin hou's avatar martin hou

feat: 增加清空已配对设备列表的指令实现与测试

parent 1bc6b6dc
...@@ -287,6 +287,9 @@ declare class Jensen { ...@@ -287,6 +287,9 @@ declare class Jensen {
// 获取已配对的蓝牙设备列表 // 获取已配对的蓝牙设备列表
getPairedDevices: (seconds?: number) => Promise<BluetoothDevice[]>; getPairedDevices: (seconds?: number) => Promise<BluetoothDevice[]>;
// 清空已配对的蓝牙设备列表
clearPairedDevices: (seconds?: number) => Promise<ReturnStruct['common']>;
// 设备回连 // 设备回连
reconnectDevice: (mac: string, seconds?: number) => Promise<ReturnStruct['common']>; reconnectDevice: (mac: string, seconds?: number) => Promise<ReturnStruct['common']>;
......
...@@ -435,6 +435,13 @@ export function Home() { ...@@ -435,6 +435,13 @@ export function Home() {
Logger.info('jensen', 'bluetooth', 'Paired Devices: ' + JSON.stringify(devices)); Logger.info('jensen', 'bluetooth', 'Paired Devices: ' + JSON.stringify(devices));
} }
const clearPairedDevices = async () => {
let jensen = getJensen();
if (jensen == null) return;
let rst = await jensen.clearPairedDevices(5);
Logger.info('jensen', 'bluetooth', 'Clear Paired Devices: ' + JSON.stringify(rst));
}
return ( return (
<> <>
<div className="btn-container" style={{ display: 'flex', flexDirection: 'row', gap: '16px', padding: '16px', alignItems: 'center', flexWrap: 'wrap' }}> <div className="btn-container" style={{ display: 'flex', flexDirection: 'row', gap: '16px', padding: '16px', alignItems: 'center', flexWrap: 'wrap' }}>
...@@ -449,6 +456,7 @@ export function Home() { ...@@ -449,6 +456,7 @@ export function Home() {
<button onClick={stopBluetoothScan}>Stop Scan</button> <button onClick={stopBluetoothScan}>Stop Scan</button>
<button onClick={getScanResults}>Scan Results</button> <button onClick={getScanResults}>Scan Results</button>
<button onClick={getPairedDevices}>Paired Devices</button> <button onClick={getPairedDevices}>Paired Devices</button>
<button onClick={clearPairedDevices}>Clear Paired</button>
{ {
/* /*
<button onClick={reconnectDevice}>Connect Device</button> <button onClick={reconnectDevice}>Connect Device</button>
......
...@@ -39,6 +39,7 @@ const BLUETOOTH_STATUS = 0x1003; ...@@ -39,6 +39,7 @@ const BLUETOOTH_STATUS = 0x1003;
const BT_SCAN = 0x1005; const BT_SCAN = 0x1005;
const BT_DEV_LIST = 0x1006; const BT_DEV_LIST = 0x1006;
const BT_GET_PAIRED_DEV_LIST = 0x1007; const BT_GET_PAIRED_DEV_LIST = 0x1007;
const BT_REMOVE_PAIRED_DEV = 0x1008;
const TEST_SN_WRITE = 0xf007; const TEST_SN_WRITE = 0xf007;
const RECORD_TEST_START = 0xf008; const RECORD_TEST_START = 0xf008;
...@@ -734,6 +735,12 @@ Jensen.prototype.getPairedDevices = async function (seconds) { ...@@ -734,6 +735,12 @@ Jensen.prototype.getPairedDevices = async function (seconds) {
return this.send(new Command(BT_GET_PAIRED_DEV_LIST), seconds); return this.send(new Command(BT_GET_PAIRED_DEV_LIST), seconds);
}; };
// 清空已配对的蓝牙设备列表
Jensen.prototype.clearPairedDevices = async function (seconds) {
if (this.model.indexOf('hidock-p1') == -1) return null;
return this.send(new Command(BT_REMOVE_PAIRED_DEV).body([0x00]), seconds);
}
// 设备回连 // 设备回连
Jensen.prototype.reconnectDevice = async function (mac, seconds) { Jensen.prototype.reconnectDevice = async function (mac, seconds) {
if (this.model.indexOf('hidock-p1') == -1) return null; if (this.model.indexOf('hidock-p1') == -1) return null;
...@@ -1609,6 +1616,7 @@ Jensen.registerHandler(READ_WEBUSB_TIMEOUT, (msg) => { ...@@ -1609,6 +1616,7 @@ Jensen.registerHandler(READ_WEBUSB_TIMEOUT, (msg) => {
}); });
Jensen.registerHandler(BT_SCAN, commonMessageParser); Jensen.registerHandler(BT_SCAN, commonMessageParser);
Jensen.registerHandler(BT_REMOVE_PAIRED_DEV, commonMessageParser);
Jensen.registerHandler(BT_DEV_LIST, (msg) => { Jensen.registerHandler(BT_DEV_LIST, (msg) => {
// console.log('bluetooth-scan', msg); // console.log('bluetooth-scan', msg);
if (msg.body.length == 0) return []; if (msg.body.length == 0) return [];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment