esp-web-tools icon indicating copy to clipboard operation
esp-web-tools copied to clipboard

Allowing device filter in the manifest for request port

Open abishekmuthian opened this issue 3 years ago • 7 comments

Right now, The request port dialog is like this on Linux:

[Current esp-web-tools request port dialog gif] current-esp-web-tools

If the device filters are accepted i.e. with usbVendorId & usbProductId :

            const filters = [{usbVendorId: 0x1a86, usbProductId: 0x7523}];
            const port = await navigator.serial.requestPort({filters});

Request port dialog can be like this on Linux:

[esp-web-tools request port dialog with device filter gif] esp-web-tools-device-filter

This setting can be useful for developers who support specific models of boards as device/vendor id doesn't change for a particular model and can reduce confusion for the end user.

abishekmuthian avatar Mar 10 '22 02:03 abishekmuthian

Sounds good. Pull request welcome 👍

balloob avatar Mar 11 '22 17:03 balloob

Sure, I'm thinking about accepting another key filters as it has nothing to do with builds?

"filters": [
      {
        "parts": [
          { "vendor": 0x1a86, "product": 0x7523},
          ...
        ]
      }
],
"builds": []

abishekmuthian avatar Mar 12 '22 05:03 abishekmuthian

I would just call it requestPortOptions and pass that object as-is when calling requestPort.

Note, we don't currently have access to the manifest when connecting.

balloob avatar Mar 12 '22 21:03 balloob

I would just call it requestPortOptions and pass that object as-is when calling requestPort.

Upon further checking, it needs to be SerialPortFilter according to the w3c-web-serial type definitions (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/dc7cac7a165e9fe4d11c8db5db4eccbe41790e57/types/w3c-web-serial/index.d.ts#L76) being used in the project .

Note, we don't currently have access to the manifest when connecting.

Noted, Would review how it's being done during flashing and would try to implement the same during connect.

abishekmuthian avatar Mar 14 '22 05:03 abishekmuthian

Your type link references just an object with specific keys, it's not a specific class.

balloob avatar Mar 14 '22 05:03 balloob

I meant we'd stick with naming conventions of the web-serial package and pass serialPortFilter in serialPortRequestOptions object from the manifest?

Edit: camelCase in manifest.

abishekmuthian avatar Mar 14 '22 05:03 abishekmuthian

PR: https://github.com/esphome/esp-web-tools/pull/195

abishekmuthian avatar Mar 15 '22 03:03 abishekmuthian