Commit 302baabc authored by martin hou's avatar martin hou

feat: 增加WebUSB写超时设置

parent bf440ad5
......@@ -304,6 +304,12 @@ declare class Jensen {
// 更新设备UAC固件
updateUAC: (data: Uint8Array, seconds?: number) => Promise<ReturnStruct['common']>;
// 设置WebUSB超时时间
setWebUSBTimeout: (timeout: number, seconds?: number) => Promise<ReturnStruct['common']>;
// 获取WebUSB超时时间
getWebUSBTimeout: (seconds?: number) => Promise<{ timeout: number }>;
dump: (void);
}
......
......@@ -259,6 +259,20 @@ export function Home() {
else alert('Something went wrong...');
}
const setWebUSBTimeout = async () => {
let ts = prompt('Please Input the Timeout (ms):', '10000');
if (ts === undefined || ts === null) return;
let timeout = parseInt(ts);
if (isNaN(timeout) || timeout <= 0) return alert('Please Input the Correct Timeout');
await jensen.setWebUSBTimeout(timeout, 30);
alert('Set Timeout Success');
}
const getWebUSBTimeout = async () => {
let rst = await jensen.getWebUSBTimeout(5);
alert(JSON.stringify(rst));
}
return (
<>
<div style={{ display: 'flex', flexDirection: 'row', gap: '16px', padding: '16px', alignItems: 'center', flexWrap: 'wrap' }}>
......@@ -272,6 +286,8 @@ export function Home() {
<button onClick={disconnectBTDevice}>Bluetooth Disconnect</button>
<button onClick={updateDeviceTone}>Update Tone</button>
<button onClick={updateUAC}>Update UAC</button>
<button onClick={setWebUSBTimeout}>Set Timeout</button>
<button onClick={getWebUSBTimeout}>Get Timeout</button>
</div>
<div id="files" style={{ padding: '0px 0px 0px 30px', marginBottom: '20px' }}>
<h3>Files: </h3>
......
......@@ -39,6 +39,8 @@ const BLUETOOTH_STATUS = 0x1003;
const TEST_SN_WRITE = 0xf007;
const RECORD_TEST_START = 0xf008;
const RECORD_TEST_END = 0xf009;
const WRITE_WEBUSB_TIMEOUT = 0xf010;
const READ_WEBUSB_TIMEOUT = 0xf011;
const COMMAND_NAMES = {
[INVAILD]: 'invalid-0',
......@@ -764,6 +766,16 @@ Jensen.prototype.getBluetoothStatus = async function (seconds) {
return this.send(new Command(BLUETOOTH_STATUS), seconds);
};
Jensen.prototype.setWebUSBTimeout = async function (timeout, seconds)
{
return this.send(new Command(WRITE_WEBUSB_TIMEOUT).body([timeout]), seconds);
};
Jensen.prototype.getWebUSBTimeout = async function (seconds)
{
return this.send(new Command(READ_WEBUSB_TIMEOUT), seconds);
};
Jensen.prototype.listFiles = async function () {
let tag = 'filelist-' + this.serialNumber;
if (this[tag] != null) return null;
......@@ -1580,5 +1592,11 @@ Jensen.registerHandler(REQUEST_UAC_UPDATE, (msg) => {
return { code : rst, result : txt };
});
Jensen.registerHandler(UAC_UPDATE, commonMessageParser);
Jensen.registerHandler(WRITE_WEBUSB_TIMEOUT, commonMessageParser);
Jensen.registerHandler(READ_WEBUSB_TIMEOUT, (msg) => {
let timeout = ((msg.body[0] & 0xff) << 24) | ((msg.body[1] & 0xff) << 16) | ((msg.body[2] & 0xff) << 8) | (msg.body[3] & 0xff);
return { timeout: timeout };
});
export { Jensen };
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