esp-web-tools
Version:
Web tools for ESP devices
2 lines (1 loc) • 2.21 kB
JavaScript
const r=(r,e)=>{var t;return null===(t=r.configuration)||void 0===t?void 0:t.interfaces.find((r=>{var t;return(null===(t=r.alternates[0])||void 0===t?void 0:t.interfaceClass)===e}))},e=r=>{const e=r.alternates[0].endpoints.filter((r=>"bulk"===r.type)),t=e.find((r=>"in"===r.direction)),o=e.find((r=>"out"===r.direction));if(!t||!o)throw new Error(`Interface ${r.interfaceNumber} has no bulk IN and OUT endpoints`);return{in:t,out:o}},t=async(r,e,t)=>{const o=await r.controlTransferOut(e,t);if("ok"!==o.status)throw new Error(`USB control request 0x${e.request.toString(16)} failed: ${o.status}`)},o=async(r,e,t)=>{const o=await r.controlTransferIn(e,t);if("ok"!==o.status||!o.data)throw new Error(`USB control request 0x${e.request.toString(16)} failed: ${o.status}`);return o.data},a=[{name:"CP210x",filters:[6e4,60001,60003,60016,60017].map((r=>({vendorId:4292,productId:r}))),load:()=>import("./cp210x-CD3hAcBr.js").then((r=>r.createCp210xDriver))},{name:"CH340/CH341",filters:[{vendorId:6790,productId:29987},{vendorId:6790,productId:29986},{vendorId:6790,productId:21795},{vendorId:17224,productId:21795}],load:()=>import("./ch34x-O7hnS6Rn.js").then((r=>r.createCh34xDriver))},{name:"FTDI",filters:[24577,24592,24593,24596,24597].map((r=>({vendorId:1027,productId:r}))),load:()=>import("./ftdi-E6n0R6W9.js").then((r=>r.createFtdiDriver))},{name:"CDC-ACM",filters:[{classCode:2}],load:()=>import("./cdc-acm-CgpHa-zp.js").then((r=>r.createCdcAcmDriver))}],s=()=>a.flatMap((r=>r.filters)),n=r=>a.find((e=>((r,e)=>e.filters.some((e=>((r,e)=>(void 0===e.vendorId||e.vendorId===r.vendorId)&&(void 0===e.productId||e.productId===r.productId)&&(void 0===e.classCode||r.deviceClass===e.classCode||r.configurations.some((r=>r.interfaces.some((r=>r.alternates.some((r=>r.interfaceClass===e.classCode))))))))(r,e))))(r,e)));var i=Object.freeze({__proto__:null,findUsbSerialDriver:n,requestUsbSerialPort:async()=>{const r=await navigator.usb.requestDevice({filters:s()}),e=n(r);if(!e)throw new Error("Unsupported USB serial device");const[t,{UsbSerialPort:o}]=await Promise.all([e.load(),import("./port-3AmrEwYL.js")]);return new o(r,t)},usbSerialDrivers:a,usbSerialFilters:s});export{e as a,o as b,t as c,r as f,i};