From e47f2f7026d50096abd623a60fc2f6c10dce3a5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=AB=8B=E5=B8=AE?= <3294713004@qq.com> Date: Thu, 23 Oct 2025 12:43:29 +0800 Subject: [PATCH] =?UTF-8?q?feat(core):=20web=20usb=20mini=E4=B8=8B?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9endpoint=200=E7=9A=84=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=A4=84=E7=90=86=E9=98=B2=E6=AD=A2PC=E7=AB=AF?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/modules/mixly-modules/web/usb-mini.js | 64 +++++++++++--------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/common/modules/mixly-modules/web/usb-mini.js b/common/modules/mixly-modules/web/usb-mini.js index ef3ee28e..2a922740 100644 --- a/common/modules/mixly-modules/web/usb-mini.js +++ b/common/modules/mixly-modules/web/usb-mini.js @@ -116,7 +116,8 @@ class USBMini extends Serial { #defaultConfiguration_ = 1; #endpointIn_ = null; #endpointOut_ = null; - #interfaceNumber_ = 0; + #ctrlInterfaceNumber_ = -1; + #dataInterfaceNumber_ = -1; #dataLength_ = 64; constructor(port) { super(port); @@ -149,7 +150,7 @@ class USBMini extends Serial { recipient: 'interface', request: 0x01, value: 0x100, - index: this.#interfaceNumber_ + index: this.#dataInterfaceNumber_ }, 64); } return result?.data; @@ -164,7 +165,7 @@ class USBMini extends Serial { recipient: 'interface', request: 0x09, value: 0x200, - index: this.#interfaceNumber_ + index: this.#dataInterfaceNumber_ }, data); } } @@ -203,7 +204,7 @@ class USBMini extends Serial { if (!selectedInterface) { selectedInterface = interfaces[0]; } - this.#interfaceNumber_ = selectedInterface.interfaceNumber; + this.#dataInterfaceNumber_ = selectedInterface.interfaceNumber; const { endpoints } = selectedInterface.alternates[0]; for (const endpoint of endpoints) { if (endpoint.direction === 'in') { @@ -212,8 +213,13 @@ class USBMini extends Serial { this.#endpointOut_ = endpoint.endpointNumber; } } - await this.#device_.claimInterface(0); - await this.#device_.claimInterface(this.#interfaceNumber_); + try { + await this.#device_.claimInterface(0); + this.#ctrlInterfaceNumber_ = 0; + } catch (_) { + this.#ctrlInterfaceNumber_ = -1; + } + await this.#device_.claimInterface(this.#dataInterfaceNumber_); super.open(baud); await this.setBaudRate(baud); this.onOpen(); @@ -238,28 +244,30 @@ class USBMini extends Serial { if (!this.isOpened() || this.getRawBaudRate() === baud) { return; } - const dwDTERate = new Uint8Array([ - baud & 0xFF, - (baud >> 8) & 0xFF, - (baud >> 16) & 0xFF, - (baud >> 24) & 0xFF - ]); - const bCharFormat = 0x00; - const bParityType = 0x00; - const bDataBits = 0x08; - const lineCoding = new Uint8Array([ - ...dwDTERate, - bCharFormat, - bParityType, - bDataBits - ]); - await this.#device_.controlTransferOut({ - requestType: 'class', - recipient: 'interface', - request: 0x20, - value: 0x0000, - index: 0 - }, lineCoding); + if (this.#ctrlInterfaceNumber_ !== -1) { + const dwDTERate = new Uint8Array([ + baud & 0xFF, + (baud >> 8) & 0xFF, + (baud >> 16) & 0xFF, + (baud >> 24) & 0xFF + ]); + const bCharFormat = 0x00; + const bParityType = 0x00; + const bDataBits = 0x08; + const lineCoding = new Uint8Array([ + ...dwDTERate, + bCharFormat, + bParityType, + bDataBits + ]); + await this.#device_.controlTransferOut({ + requestType: 'class', + recipient: 'interface', + request: 0x20, + value: 0x0000, + index: this.#ctrlInterfaceNumber_ + }, lineCoding); + } await super.setBaudRate(baud); }