Commit 5b6815d5 authored by 曾思程's avatar 曾思程

重置连接时清空待发消息,增加onconnect开关

parent 10521084
......@@ -26,7 +26,7 @@ declare class JensenType {
init: () => Promise<boolean>;
getDeviceInfo: (time?: number) => Promise<DeviceInfo>;
listFiles: (time?: number) => Promise<FileInfo[]>;
tryconnect: () => Promise<boolean>;
tryconnect: (disableOnConnect?:boolean) => Promise<boolean>;
getFile: (
fileName: string,
length: number,
......
......@@ -98,9 +98,10 @@ function Jensen(log) {
self.versionNumber = null;
};
const setup = async function () {
const setup = async function (disableOnConnect) {
self.versionCode = null;
self.versionNumber = null;
commands.length = 0;
try {
await device.selectConfiguration(1);
await device.claimInterface(0);
......@@ -110,7 +111,7 @@ function Jensen(log) {
Logger.error('jensen', 'setup', String(e));
throw e;
}
_check_conn_status();
if (!disableOnConnect) _check_conn_status();
current = null;
recv = false;
ready = true;
......@@ -151,7 +152,7 @@ function Jensen(log) {
await self.connect();
};
this.tryconnect = async function () {
this.tryconnect = async function (disableOnConnect) {
await this.disconnect();
let devices = await navigator.usb.getDevices();
for (let i = 0; i < devices.length; i++) {
......@@ -160,7 +161,7 @@ function Jensen(log) {
Logger.debug('jensen', 'tryconnect', 'detected: ' + item.productName);
await item.open();
device = item;
await setup();
await setup(disableOnConnect);
return true;
}
}
......
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