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

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

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