Files
DeviceManager/apps/manager/build/_app/immutable/chunks/connection.5cd615cd.js

4 lines
10 KiB
JavaScript

import{w as c}from "./index.c76aaf45.js";import{_ as v}from "./preload-helper.a4192956.js";import{r as p}from "./scheduler.f5cfe514.js";function L(i){const e=new Uint8Array(i.length*2);let t=0;for(const s of i)s>255&&(e[t++]=s>>>8),e[t++]=s&255;return e.slice(0,t)}function R(i){const e=[];for(let t=0; t<i.length; t++){let s=i[t];s>0&&s<32&&(s=s<<8|i[++t]),e.push(s)}return e}class ${chunks="";transform(e,t){this.chunks+=e;const s=this.chunks.split(`\r
`);this.chunks=s.pop();for(const o of s)t.enqueue(o)}flush(e){e.enqueue(this.chunks)}}class k{major;minor;patch;preRelease;meta;constructor(e){const[,t,s,o,n,a]=/^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+))?$/.exec(e);this.major=Number.parseInt(t),this.minor=Number.parseInt(s),this.patch=Number.parseInt(o),n&&(this.preRelease=n),a&&(this.meta=a)}toString(){return`${this.major}.${this.minor}.${this.patch}`+(this.preRelease?`-${this.preRelease}`:"")+(this.meta?`+${this.meta}`:"")}}function w(i){return R(Uint8Array.from({length:i.length/2}).map((e,t)=>Number.parseInt(i.slice(t*2,t*2+2),16)))}function A(i){return[...L(i)].map(e=>e.toString(16).padStart(2,"0")).join("").toUpperCase()}function T(i){return P(BigInt(`0x${i}`))}function b(i){return D(i).toString(16).padStart(32,"0").toUpperCase()}function D(i){let e=0n;for(let t=1;t<=i.length;t++)e|=BigInt(i[i.length-t]&1023)<<BigInt((12-t)*10);return e}function P(i){const e=[];for(let t=0;t<12;t++){const s=Number(i&0x3ffn);s!==0&&e.push(s),i>>=10n}return e}const E=new Map([["ONE M0",{usbProductId:32783,usbVendorId:9114}],["LITE S2",{usbProductId:33070,usbVendorId:12346}],["LITE M0",{usbProductId:32796,usbVendorId:9114}],["X",{usbProductId:33163,usbVendorId:12346}]]);navigator.serial===void 0&&{}.TAURI_FAMILY!==void 0&&await v(()=>import("./tauri-serial.32a5689f.js"),["./tauri-serial.32a5689f.js","./scheduler.f5cfe514.js","./each.94f093eb.js","./index.c2fc59c9.js"],import.meta.url);async function I(){return navigator.serial.getPorts().then(i=>i.filter(e=>{const{usbProductId:t,usbVendorId:s}=e.getInfo();for(const o of E.values())if(o.usbProductId===t&&o.usbVendorId===s)return!0;return!1}))}async function j(){return I().then(i=>i.length===1)}class M{constructor(e=115200){this.baudRate=e}port;reader;abortController1=new AbortController;abortController2=new AbortController;streamClosed;lock;version;company;device;chipset;keyCount;async init(e=!1){const t=await I();this.port=!e&&t.length===1?t[0]:await navigator.serial.requestPort({filters:[...E.values()]}),await this.port.open({baudRate:this.baudRate});const s=this.port.getInfo();f.update(l=>(l.push({type:"system",value:`Connected; ID: 0x${s.usbProductId?.toString(16)}; Vendor: 0x${s.usbVendorId?.toString(16)}`}),l)),await this.port.close(),this.version=new k(await this.send("VERSION").then(([l])=>l));const[o,n,a]=await this.send("ID");this.company=o,this.device=n,this.chipset=a,this.keyCount=this.device==="ONE"?90:67}async suspend(){await this.reader.cancel(),await this.streamClosed.catch(()=>{}),this.reader.releaseLock(),await this.port.close()}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 $),{signal:this.abortController2.signal}).getReader()}async internalRead(){const{value:e}=await this.reader.read();return f.update(t=>(t.push({type:"output",value:e}),t)),e}async internalSend(...e){const t=this.port.writable.getWriter();try{f.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),o=new Promise(async n=>{let a;try{await this.wake(),a=await e(t,s)}finally{await this.suspend(),this.lock=void 0,n(a)}});return this.lock=o.then(()=>!0),o}async send(...e){return this.runWith(async(t,s)=>{await t(...e);const o=e.join(" ").replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");return s().then(n=>n.replace(new RegExp(`^${o} `),"").split(" "))})}async getChordCount(){const[e]=await this.send("CML C0");return Number.parseInt(e)}async getChord(e){const[t,s]=await this.send(`CML C1 ${e}`);return{actions:T(t),phrase:w(s)}}async getChordPhrase(e){const[t]=await this.send(`CML C2 ${b(e)}`);return t==="2"?void 0:w(t)}async setChord(e){const[t]=await this.send("CML","C3",b(e.actions),A(e.phrase));if(t!=="0")throw new Error(`Failed with status ${t}`)}async deleteChord(e){const t=await this.send(`CML C4 ${b(e.actions)}`);if(console.log(t),t.at(-1)!=="2")throw new Error(`Failed with status ${t}`)}async setLayoutKey(e,t,s){const[o]=await this.send(`VAR B4 A${e} ${t} ${s}`);if(console.log(o),o!=="0")throw new Error(`Failed with status ${o}`)}async getLayoutKey(e,t){const[s,o]=await this.send(`VAR B3 A${e} ${t}`);if(o!=="0")throw new Error(`Failed with status ${o}`);return Number(s)}async commit(){const[e]=await this.send("VAR B0");if(e!=="0")throw new Error(`Failed with status ${e}`)}async setSetting(e,t){const[s]=await this.send(`VAR B2 ${e} ${t}`);if(s!=="0")throw new Error(`Failed with status ${s}`)}async getSetting(e){const[t,s]=await this.send(`VAR B1 ${e}`);if(s!=="0")throw new Error(`Setting "${e}" doesn't exist (Status code ${s})`);return Number(t)}async reboot(){await this.send("RST")}async bootloader(){await this.send("RST BOOTLOADER")}async getRamBytesAvailable(){return Number(await this.send("RAM"))}}function u(i,e,t){{const s=localStorage.getItem(i),o=s!==null?c(JSON.parse(s)):c(e);return o.subscribe(n=>{(!t||t())&&localStorage.setItem(i,JSON.stringify(n))}),o}}const F=u("user-theme",{color:"#6D81C7",mode:"dark"}),d=u("user-preferences",{backup:!1,autoConnect:!0}),K=(i,e)=>{const t=d.subscribe(o=>{i.checked=o[e]});function s(){d.update(o=>(o[e]=i.checked,o))}return i.addEventListener("input",s),{destroy(){t(),i.removeEventListener("input",s)}}},y={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"},11:{title:"Enable USB HID Keyboard",description:"boolean 0 or 1, default is 1"},12:{title:"Enable Character Entry",description:"boolean 0 or 1"},13:{title:"GUI-CTRL Swap Mode",description:"boolean 0 or 1; 1 swaps keymap 0 and 1. (CCL only)"},14:{title:"Key Scan Duration",description:"scan rate described in milliseconds; default is 2ms = 500Hz"},15:{title:"Key Debounce Press Duration",description:"debounce time in milliseconds; default is 7ms on the One and 20ms on the Lite"},16:{title:"Key Debounce Release Duration",description:"debounce time in milliseconds; default is 7ms on the One and 20ms on the Lite"},17:{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"},21:{title:"Enable USB HID Mouse",description:"boolean 0 or 1; default is 1"},22:{title:"Slow Mouse Speed",description:"pixels to move at the mouse poll rate; default for CC1 is 5 = 250px/s"},23:{title:"Fast Mouse Speed",description:"pixels to move at the mouse poll rate; default for CC1 is 25 = 1250px/s"},24:{title:"Enable Active Mouse",description:"boolean 0 or 1; moves mouse back and forth every 60s"},25:{title:"Mouse Scroll Speed",description:"default is 1; polls at 1/4th the rate of the mouse move updates"},26:{title:"Mouse Poll Duration",description:"poll rate described in milliseconds; default is 20ms = 50Hz"},31:{title:"Enable Chording",description:"boolean 0 or 1"},32:{title:"Enable Chording Character Counter Timeout",description:"boolean 0 or 1; default is 1"},33:{title:"Chording Character Counter Timeout Timer",description:"0-255 deciseconds; default is 40 or 4.0 seconds"},34:{title:"Chord Detection Press Tolerance(ms)",description:"1-50 milliseconds"},35:{title:"Chord Detection Release Tolerance(ms)",description:"1-50 milliseconds"},41:{title:"Enable Spurring",description:"boolean 0 or 1; default is 1"},42:{title:"Enable Spurring Character Counter Timeout",description:"boolean 0 or 1; default is 1"},43:{title:"Spurring Character Counter Timeout Timer",description:"0-255 seconds; default is 240"},51:{title:"Enable Arpeggiates",description:"boolean 0 or 1; default is 1"},54:{title:"Arpeggiate Tolerance",description:"in milliseconds; default 800ms"},61:{title:"Enable Compound Chording (coming soon)",description:"boolean 0 or 1; default is 0"},64:{title:"Compound Tolerance",description:"in milliseconds; default 1500ms"},81:{title:"LED Brightness",description:"0-50 (CCL only); default is 5, which draws around 100 mA of current"},82:{title:"LED Color Code",description:"Color Codes to be listed (CCL only)"},83:{title:"Enable LED Key Highlight (coming soon)",description:"boolean 0 or 1 (CCL only)"},84:{title:"Enable LEDs",description:"boolean 0 or 1; default is 1 (CCL only)"},91:{title:"Operating System",description:"Operating system codes listed below"},92:{title:"Enable Realtime Feedback",description:"boolean 0 or 1; default is 1"},93:{title:"Enable CharaChorder Ready on startup",description:"boolean 0 or 1; default is 1"}}},C=c(),f=c([]),V=u("chord-library",[],()=>p(d).backup),x=u("layout",[[],[],[]],()=>p(d).backup),N=u("device-settings",[],()=>p(d).backup),S=c("done"),m=c(void 0);async function U(i=!1){const e=p(C)??new M;await e.init(i),C.set(e);const t=await e.getChordCount();S.set("downloading");const s=Object.keys(y.settings).length+e.keyCount*3+t;let o=0;m.set({max:s,current:o});function n(){o++,m.set({max:s,current:o})}const a=[];for(const r in y.settings){try{a[Number.parseInt(r)]=await e.getSetting(Number.parseInt(r))}catch{}n()}N.set(a);const l=[[],[],[]];for(let r=1;r<=3;r++)for(let h=0;h<e.keyCount;h++)l[r-1][h]=await e.getLayoutKey(r,h),n();x.set(l);const g=[];for(let r=0;r<t;r++)g.push(await e.getChord(r)),n();V.set(g),S.set("done"),m.set(void 0)}export{S as a,V as b,x as c,N as d,m as e,u as f,j as g,R as h,U as i,L as j,f as k,K as p,C as s,F as t,d as u};