UNPKG

esp-web-tools

Version:
2 lines (1 loc) • 1.23 kB
import{c as e,f as t,b as i,a}from"./index-rScOpSrP.js";const r=48e6,n=(e,t)=>1<<12-3*e-t,s=[0,1,2,3].map((e=>Math.floor(r/(512*n(e,1))))),o=e=>{const t=Math.min(Math.max(e,46),3e6);let i=1,a=3;for(;a>0&&t<=s[a];)a--;let o=n(a,i),c=Math.floor(r/(o*t));return(c<9||c>255)&&(c=Math.floor(c/2),o*=2,i=0),768e6/(o*c)-16*t>=16*t-768e6/(o*(c+1))&&c++,1===i&&c%2==0&&(c/=2,i=0),256-c<<8|i<<2|a},c=e=>{let t=192|e.dataBits-5;return"none"!==e.parity&&(t|=8,"even"===e.parity&&(t|=16)),2===e.stopBits&&(t|=4),t},u=(e,t)=>65535&~((e?32:0)|(t?64:0));class d{constructor(e){this._device=e}_out(t,i,a){return e(this._device,{requestType:"vendor",recipient:"device",request:t,value:i,index:a})}async open(){const e=t(this._device,255);if(!e)throw new Error("No vendor specific interface found");return await this._device.claimInterface(e.interfaceNumber),await i(this._device,{requestType:"vendor",recipient:"device",request:95,value:0,index:0},2),await this._out(161,0,0),a(e)}async setLineConfig(e){await this._out(154,4882,128|o(e.baudRate)),await this._out(154,9496,c(e))}setSignals(e,t){return this._out(164,u(e,t),0)}}const h=e=>new d(e);export{o as ch34xBaudDivisor,c as ch34xLineControl,u as ch34xModemControl,h as createCh34xDriver};