mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-07 02:22:52 +00:00
6 lines
12 KiB
JavaScript
6 lines
12 KiB
JavaScript
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./tauri-serial.BP-n-twb.js","./scheduler.CXEVs2ap.js","./each.CypvCfon.js","./index.CTdcniaS.js"])))=>i.map(i=>d[i]);
|
|
import{w as u}from"./index.Lgv2TFSy.js";import{_ as I}from"./preload-helper.Dch09mLN.js";import{a9 as h}from"./scheduler.CXEVs2ap.js";function R(o){const e=new Uint8Array(o.length*2);let t=0;for(const s of o)s>255&&(e[t++]=s>>>8),e[t++]=s&255;return e.slice(0,t)}function v(o){const e=[];for(let t=0;t<o.length;t++){let s=o[t];s>0&&s<32&&t+1<o.length&&(s=s<<8|o[++t]),e.push(s)}return e}class T{chunks="";transform(e,t){this.chunks+=e;const s=this.chunks.split(`\r
|
|
`);this.chunks=s.pop();for(const r of s)t.enqueue(r)}flush(e){e.enqueue(this.chunks)}}class L{major=0;minor=0;patch=0;preRelease;meta;constructor(e){const t=/^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+))?$/.exec(e);if(!t)console.error("Invalid version string:",e);else{const[,s,r,i,a,n]=t;this.major=Number.parseInt(s??"NaN"),this.minor=Number.parseInt(r??"NaN"),this.patch=Number.parseInt(i??"NaN"),a&&(this.preRelease=a),n&&(this.meta=n)}}toString(){return`${this.major}.${this.minor}.${this.patch}`+(this.preRelease?`-${this.preRelease}`:"")+(this.meta?`+${this.meta}`:"")}}function y(o){return v(Uint8Array.from({length:o.length/2}).map((e,t)=>Number.parseInt(o.slice(t*2,t*2+2),16)))}function A(o){return[...R(o)].map(e=>e.toString(16).padStart(2,"0")).join("").toUpperCase()}function D(o){return _(BigInt(`0x${o}`))}function f(o){return k(o).toString(16).padStart(32,"0").toUpperCase()}function k(o){let e=0n;for(let t=1;t<=o.length;t++)e|=BigInt(o[o.length-t]&1023)<<BigInt((12-t)*10);return e}function _(o){const e=[];for(let t=0;t<12;t++){const s=Number(o&0x3ffn);e.push(s),o>>=10n}return e}var $={VITE_HOMEPAGE_URL:"https://github.com/CharaChorder/DeviceManager",VITE_DOCS_URL:"https://docs.charachorder.com",VITE_BUGS_URL:"https://github.com/CharaChorder/DeviceManager/issues",VITE_LEARN_URL:"https://www.iq-eq.io/",VITE_LATEST_FIRMWARE:"1.1.4",VITE_STORE_URL:"https://www.charachorder.com/",BASE_URL:"./",MODE:"production",DEV:!1,PROD:!0,SSR:!1};const S=new Map([["ONE M0",{usbProductId:32783,usbVendorId:9114}],["TWO S3",{usbProductId:86,usbVendorId:10374}],["LITE S2",{usbProductId:33070,usbVendorId:12346}],["LITE M0",{usbProductId:32796,usbVendorId:9114}],["X",{usbProductId:33163,usbVendorId:12346}]]),O={ONE:90,TWO:90,LITE:67,X:256};navigator.serial===void 0&&$.TAURI_FAMILY!==void 0&&await I(()=>import("./tauri-serial.BP-n-twb.js"),__vite__mapDeps([0,1,2,3]),import.meta.url);async function E(){return navigator.serial.getPorts().then(o=>o.filter(e=>{const{usbProductId:t,usbVendorId:s}=e.getInfo();for(const r of S.values())if(r.usbProductId===t&&r.usbVendorId===s)return!0;return!1}))}async function j(){return E().then(o=>o.length===1)}async function P(o,e){let t;return Promise.race([o,new Promise((s,r)=>{t=setTimeout(()=>r(new Error("Timeout")),e)})]).finally(()=>clearTimeout(t))}class N{constructor(e=115200){this.baudRate=e}port;reader;abortController1=new AbortController;abortController2=new AbortController;streamClosed;lock;suspendDebounce=100;suspendDebounceId;version;company;device;chipset;keyCount;get portInfo(){return this.port.getInfo()}async init(e=!1){try{const t=await E();this.port=!e&&t.length===1?t[0]:await navigator.serial.requestPort({filters:[...S.values()]}),await this.port.open({baudRate:this.baudRate});const s=this.port.getInfo();c.update(n=>(n.push({type:"system",value:`Connected; ID: 0x${s.usbProductId?.toString(16)}; Vendor: 0x${s.usbVendorId?.toString(16)}`}),n)),await this.port.close(),this.version=new L(await this.send(1,"VERSION").then(([n])=>n));const[r,i,a]=await this.send(3,"ID");this.company=r,this.device=i,this.chipset=a,this.keyCount=O[this.device]}catch(t){throw alert(t),console.error(t),t}}async suspend(){await this.reader.cancel(),await this.streamClosed.catch(()=>{}),this.reader.releaseLock(),await this.port.close(),c.update(e=>(e.push({type:"system",value:"Connection suspended"}),e))}async wake(){await this.port.open({baudRate:this.baudRate});const e=new TextDecoderStream;this.streamClosed=this.port.readable.pipeTo(e.writable,{signal:this.abortController1.signal}),this.reader=e.readable.pipeThrough(new TransformStream(new T),{signal:this.abortController2.signal}).getReader(),c.update(t=>(t.push({type:"system",value:"Connection resumed"}),t))}async internalRead(){try{const{value:e}=await P(this.reader.read(),5e3);return c.update(t=>(t.push({type:"output",value:e}),t)),e}catch(e){c.update(t=>(t.push({type:"output",value:`${e}`}),t))}}async internalSend(...e){const t=this.port.writable.getWriter();try{c.update(s=>(s.push({type:"input",value:e.join(" ")}),s)),await t.write(new TextEncoder().encode(`${e.join(" ")}\r
|
|
`))}finally{t.releaseLock()}}async forget(){await this.port.forget()}async runWith(e){for(;this.lock;)await this.lock;const t=this.internalSend.bind(this),s=this.internalRead.bind(this);let r;this.lock=new Promise(a=>{r=a});let i;try{this.suspendDebounceId?clearTimeout(this.suspendDebounceId):await this.wake(),i=await e(t,s)}finally{return delete this.lock,this.suspendDebounceId=setTimeout(()=>{console.assert(this.lock===void 0),this.lock=this.suspend().then(()=>(delete this.lock,delete this.suspendDebounceId,!0))},this.suspendDebounce),r(!0),i}}async send(e,...t){return this.runWith(async(s,r)=>{await s(...t);const i=t.join(" ").replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),a=await r();if(a===void 0)return console.error("No response"),Array(e).fill("NO_RESPONSE");const n=a.replace(new RegExp(`^${i} `),"").split(" ");return n.length<e?(console.error("Response too short"),n.concat(Array(e-n.length).fill("TOO_SHORT"))):n})}async getChordCount(){const[e]=await this.send(1,"CML C0");return Number.parseInt(e)}async getChord(e){const[t,s]=await this.send(2,`CML C1 ${e}`);return{actions:D(t),phrase:y(s)}}async getChordPhrase(e){const[t]=await this.send(1,`CML C2 ${f(e)}`);return t==="2"?void 0:y(t)}async setChord(e){const[t]=await this.send(1,"CML","C3",f(e.actions),A(e.phrase));t!=="0"&&console.error(`Failed with status ${t}`)}async deleteChord(e){const t=await this.send(1,`CML C4 ${f(e.actions)}`);if(t?.at(-1)!=="2"&&t?.at(-1)!=="0")throw new Error(`Failed with status ${t}`)}async setLayoutKey(e,t,s){const[r]=await this.send(1,`VAR B4 A${e} ${t} ${s}`);if(r!=="0")throw new Error(`Failed with status ${r}`)}async getLayoutKey(e,t){const[s,r]=await this.send(2,`VAR B3 A${e} ${t}`);if(r!=="0")throw new Error(`Failed with status ${r}`);return Number(s)}async commit(){const[e]=await this.send(1,"VAR B0");if(e!=="0")throw new Error(`Failed with status ${e}`)}async setSetting(e,t){const[s]=await this.send(1,`VAR B2 ${e.toString(16).toUpperCase()} ${t}`);if(s!=="0")throw new Error(`Failed with status ${s}`)}async getSetting(e){const[t,s]=await this.send(2,`VAR B1 ${e.toString(16).toUpperCase()}`);if(s!=="0")throw new Error(`Setting "0x${e.toString(16)}" doesn't exist (Status code ${s})`);return Number(t)}async reboot(){await this.send(0,"RST")}async bootloader(){await this.send(0,"RST BOOTLOADER")}async reset(e){await this.send(0,`RST ${e}`)}async getRamBytesAvailable(){return Number(await this.send(1,"RAM").then(([e])=>e))}}function p(o,e,t){{const s=localStorage.getItem(o),r=s!==null?u(JSON.parse(s)):u(e);return r.subscribe(i=>{(!t||t())&&localStorage.setItem(o,JSON.stringify(i))}),r}}const H=p("user-theme",{color:"#6D81C7",mode:"dark"}),d=p("user-preferences",{backup:!1,autoConnect:!1}),z=(o,e)=>{const t=d.subscribe(r=>{o.checked=r[e]});function s(){d.update(r=>(r[e]=o.checked,r))}return o.addEventListener("input",s),{destroy(){t(),o.removeEventListener("input",s)}}},C={settings:{1:{title:"Enable Serial Header",description:"boolean 0 or 1, default is 0"},2:{title:"Enable Serial Logging",description:"boolean 0 or 1, default is 0"},3:{title:"Enable Serial Debugging",description:"boolean 0 or 1, default is 0"},4:{title:"Enable Serial Raw",description:"boolean 0 or 1, default is 0"},5:{title:"Enable Serial Chord",description:"boolean 0 or 1, default is 0"},6:{title:"Enable Serial Keyboard",description:"boolean 0 or 1, default is 0"},7:{title:"Enable Serial Mouse",description:"boolean 0 or 1, default is 0"},17:{title:"Enable USB HID Keyboard",description:"boolean 0 or 1, default is 1"},18:{title:"Enable Character Entry",description:"boolean 0 or 1"},19:{title:"GUI-CTRL Swap Mode",description:"boolean 0 or 1; 1 swaps keymap 0 and 1. (CCL only)"},20:{title:"Key Scan Duration",description:"scan rate described in milliseconds; default is 2ms = 500Hz"},21:{title:"Key Debounce Press Duration",description:"debounce time in milliseconds; default is 7ms on the One and 20ms on the Lite"},22:{title:"Key Debounce Release Duration",description:"debounce time in milliseconds; default is 7ms on the One and 20ms on the Lite"},23:{title:"Keyboard Output Character Microsecond Delays",description:"delay time in microseconds (one delay for press and again for release); default is 480us; max is 10240us; increments of 40us"},33:{title:"Enable USB HID Mouse",description:"boolean 0 or 1; default is 1"},34:{title:"Slow Mouse Speed",description:"pixels to move at the mouse poll rate; default for CC1 is 5 = 250px/s"},35:{title:"Fast Mouse Speed",description:"pixels to move at the mouse poll rate; default for CC1 is 25 = 1250px/s"},36:{title:"Enable Active Mouse",description:"boolean 0 or 1; moves mouse back and forth every 60s"},37:{title:"Mouse Scroll Speed",description:"default is 1; polls at 1/4th the rate of the mouse move updates"},38:{title:"Mouse Poll Duration",description:"poll rate described in milliseconds; default is 20ms = 50Hz"},49:{title:"Enable Chording",description:"boolean 0 or 1"},50:{title:"Enable Chording Character Counter Timeout",description:"boolean 0 or 1; default is 1"},51:{title:"Chording Character Counter Timeout Timer",description:"0-255 deciseconds; default is 40 or 4.0 seconds"},52:{title:"Chord Detection Press Tolerance(ms)",description:"1-50 milliseconds"},53:{title:"Chord Detection Release Tolerance(ms)",description:"1-50 milliseconds"},65:{title:"Enable Spurring",description:"boolean 0 or 1; default is 1"},66:{title:"Enable Spurring Character Counter Timeout",description:"boolean 0 or 1; default is 1"},67:{title:"Spurring Character Counter Timeout Timer",description:"0-255 seconds; default is 240"},81:{title:"Enable Arpeggiates",description:"boolean 0 or 1; default is 1"},84:{title:"Arpeggiate Tolerance",description:"in milliseconds; default 800ms"},97:{title:"Enable Compound Chording (coming soon)",description:"boolean 0 or 1; default is 0"},100:{title:"Compound Tolerance",description:"in milliseconds; default 1500ms"},129:{title:"LED Brightness",description:"0-50 (CCL only); default is 5, which draws around 100 mA of current"},130:{title:"LED Color Code",description:"Color Codes to be listed (CCL only)"},131:{title:"Enable LED Key Highlight (coming soon)",description:"boolean 0 or 1 (CCL only)"},132:{title:"Enable LEDs",description:"boolean 0 or 1; default is 1 (CCL only)"},145:{title:"Operating System",description:"Operating system codes listed below"},146:{title:"Enable Realtime Feedback",description:"boolean 0 or 1; default is 1"},147:{title:"Enable CharaChorder Ready on startup",description:"boolean 0 or 1; default is 1"}}},g=u(),c=u([]),V=p("chord-library",[],()=>h(d).backup),M=p("layout",[[],[],[]],()=>h(d).backup),U=p("device-settings",[],()=>h(d).backup),w=u("done"),m=u(void 0);async function W(o=!1){const e=h(g)??new N;await e.init(o),g.set(e),await B()}async function B(){const o=h(g);if(!o)return;const e=await o.getChordCount();w.set("downloading");const t=Object.keys(C.settings).length+o.keyCount*3+e;let s=0;m.set({max:t,current:s});function r(){s++,m.set({max:t,current:s})}const i=[];for(const l in C.settings){try{i[Number.parseInt(l)]=await o.getSetting(Number.parseInt(l))}catch{}r()}U.set(i);const a=[[],[],[]];for(let l=1;l<=3;l++)for(let b=0;b<o.keyCount;b++)a[l-1][b]=await o.getLayoutKey(l,b),r();M.set(a);const n=[];for(let l=0;l<e;l++)n.push(await o.getChord(l)),r();V.set(n),w.set("done"),m.set(void 0)}export{c as a,M as b,R as c,v as d,w as e,U as f,V as g,m as h,W as i,B as j,j as k,p as l,z as p,g as s,H as t,d as u};
|
|
//# sourceMappingURL=connection.wgaIHNYB.js.map
|