led-matrix-controllers 0.2.4 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- const t=9,e=34,a=12972,r=[50,172],i=32,n=[0,32],s=Object.freeze([0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,5,5,5,5,6,6,6,6,6,7,7,7,7,8,8,8,9,9,9,10,10,10,11,11,11,12,12,12,13,13,14,14,14,15,15,16,16,17,17,17,18,18,19,19,20,20,21,22,22,23,23,24,24,25,26,26,27,27,28,29,29,30,31,32,32,33,34,34,35,36,37,38,38,39,40,41,42,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,66,67,68,69,70,71,73,74,75,76,78,79,80,82,83,84,86,87,88,90,91,93,94,96,97,99,100,102,103,105,106,108,110,111,113,115,116,118,120,121,123,125,127,128,130,132,134,136,138,140,141,143,145,147,149,151,153,155,157,159,161,164,166,168,170,172,174,177,179,181,183,186,188,190,193,195,197,200,202,205,207,210,212,215,217,220,222,225,228,230,233,236,238,241,244,247,249,252,255]),o=[],c=[{usbVendorId:a,usbProductId:32}];class l extends Error{constructor(){super("User cancelled port selection."),this.name=this.constructor.name,this.date=new Date}}class d extends Error{constructor(){super("Selected port already in use."),this.name=this.constructor.name,this.date=new Date}}async function w(){try{if(o&&o.length>0)return o.pop();if(o.push(...await navigator.serial.getPorts()),o&&o.length>0)return o.pop();if(o.push(...await navigator.serial.requestPort({filters:c})),o&&o.length>0)return o.pop()}catch(t){throw"NotFoundError"==t.name?new l:"InvalidStateError"==t.name?new d:t}}async function u(t){try{await t.close()}catch(t){if("InvalidStateError"!=t.name&&"Failed to execute 'close' on 'SerialPort': The port is already closed."!=t.message)throw t}}class p{constructor(t){this.#t=`port-mutex-${Math.random().toString()}`,this.#e=new Map,this.#a=t}async acquire(t){const e=new Error("created bad cb").stack;await this.#r(async()=>{try{await t(this.#a)}catch(t){console.error("Error occured in anonymous callback."),console.error("Original error:",t),console.error("--- This callback was created at ---\n",e)}})}async acquireIdempotent(t,e){const a=new Error("created bad cb").stack;this.#e.has(t)&&console.info(`"${t}" request coalesced.`),this.#e.set(t,async()=>{try{await e(this.#a)}catch(t){console.error("Error occured in anonymous callback."),console.error("Original error:",t),console.error("--- This callback was created at ---\n",a)}}),await this.#r(()=>this.#i(t))}async#r(t){return navigator.locks.request(this.#t,t)}async#i(t){if(this.#e.has(t)){const e=this.#e.get(t);this.#e.delete(t),await e()}}#t;#e;#a}class h{constructor(t){this.#n=t}async rx(t,e=3e3){if(null===this.#n)throw new Error("attempted RX before port initialization.");if(this.#n.readable.locked)throw new Error("attempted RX while port locked.");const a=[],r=this.#n.readable.getReader(),i=setTimeout(()=>r.cancel(),e);try{for(;a.length<t;){const{value:t,done:e}=await r.read();if(a.push(...t??[]),e||!t)break}}finally{clearTimeout(i),r.releaseLock()}return a}async tx(t){if(null===this.#n)throw new Error("attempted TX before port initialization.");if(this.#n.writable.locked)throw new Error("attempted TX while port locked.");const e=this.#n.writable.getWriter();try{await e.write(new Uint8Array(t))}finally{await e.close()}}#n}const y=Object.freeze({ANIMATE:4,BRIGHTNESS:0,BOOTLOADER:2,DRAW:6,DRAW_GREY_COL_BUFFER:8,GAME_CTRL:17,GAME_STATUS:18,PANIC:5,PATTERN:1,SLEEP:3,STAGE_GREY_COL:7,START_GAME:16,VERSION:32});let E=class{constructor(t=null){this.portMutex=t}async bootloader(){await this.portMutex.acquire(async t=>{await t.tx([...r,y.BOOTLOADER])})}async brightness(t){await this.portMutex.acquire(async e=>{await e.tx([...r,y.BRIGHTNESS,t])})}async draw(t){let e=0,a=new Uint8Array(39).fill(0);for(let r=0;r<34;r++)for(let i=0;i<9;i++)t[r][i]&&(a[e>>3]|=1<<e%8),e++;await this.portMutex.acquireIdempotent("drawMatrix",async t=>{await t.tx([...r,y.DRAW,...a])})}async drawGrayscale(t){const e=Array.from({length:9},(e,a)=>new Array({length:34},(e,r)=>GAMMA[Math.floor(255*(t[r][a]??0))]));await this.portMutex.acquireIdempotent("drawMatrix",async t=>{for(let a=0;a<9;a++)await t.tx([...r,y.STAGE_GREY_COL,a,...e[a]]);await t.tx([...r,y.DRAW_GREY_COL_BUFFER])})}async asleep(){let t=!1;return await this.portMutex.acquire(async e=>{await e.tx([...r,y.SLEEP]),t=await e.rx(32),t=0!=t[0]}),t}async sleep(){await this.portMutex.acquire(async t=>{await t.tx([...r,y.SLEEP,1])})}async wake(){await this.portMutex.acquire(async t=>{await t.tx([...r,y.SLEEP])})}async pattern(t){await this.portMutex.acquireIdempotent("drawMatrix",async e=>{await e.tx([...r,y.PATTERN,t])})}async percent(t){await this.portMutex.acquireIdempotent("drawMatrix",async e=>{await e.tx([...r,y.PATTERN,Pattern.PERCENTAGE,t])})}async version(){let t={};return await this.portMutex.acquire(async e=>{await e.tx([...r,y.VERSION]);const a=await e.rx(32);t.major=a[0],t.minor=a[1]>>4,t.patch=15&a[1],t.preRelease=1==a[2]}),t}};class x extends E{async bootloader(){return super.bootloader()}async connect(){const t=await w();t?.connected&&(await u(t),await t.open({baudRate:115200}),this.portMutex=new p(new h(t)))}async draw(t){switch(this.#s){case BitDepth.GRAY_8BIT:super.drawGrayscale(t);break;case BitDepth.MONO_1BIT:super.draw(t)}}async verifyFirmware(){try{const t=await super.version();return t&&null!=t.major&&null!=t.minor&&null!=t.patch&&null!=t.preRelease}catch{return!1}}async version(){return super.version()}#s}const _=Object.freeze({NOOP:0,ANIMATION_DIAMOND:100,ANIMATION_FIRE:98,ANIMATION_FIREPLACE:102,ANIMATION_GEAR:103,ANIMATION_RING:114,ANIMATION_STARTUP:97,ANIMATION_STARTUP_ONCE:65,BOOTLOADER:101,DRAW_PWM:109,DRAW_PWM_BLOCKING:77,DRAW_SCALE:110,DRAW_SCALE_BLOCKING:78,FLUSH_CMD_QUEUE:99,TEST_PATTERN:116,SET_CONST_PWM:119,SET_CONST_SCALE:115,SET_PX_PWM:112,SET_PX_SCALE:113,IDENTITY_STRING:127}),A=/^Sig\sFW\sLED\sMatrix\sFW\sV(\d+)\.(\d+)$/;class m{constructor(t=null){this.portMutex=t}async bootloader(){await this.portMutex.acquire(async t=>{await t.tx([_.BOOTLOADER])})}async identityString(){let t=null;return await this.portMutex.acquire(async e=>{await e.tx([_.IDENTITY_STRING]),t=await e.rx(25)}),String.fromCharCode(...t)}async setPixelPwm(t,e,a){await this.portMutex.acquire(async r=>{await r.tx([_.SET_PX_PWM,e,t,a])})}async setGlobalPwm(t){await this.portMutex.acquire(async e=>{await e.tx([_.SET_CONST_PWM,t])})}async setMatrixPwm(t){await this.portMutex.acquireIdempotent("drawMatrix",async e=>{await e.tx([_.DRAW_PWM].concat(t.flat().map(t=>s[Math.floor(255*(t??0))])))})}async setPixelAnalog(t,e,a){await this.portMutex.acquire(async r=>{await r.tx([_.SET_PX_SCALE,e,t,a])})}async setGlobalAnalog(t){await this.portMutex.acquire(async e=>{await e.tx([_.SET_CONST_SCALE,t])})}async setMatrixAnalog(t){await this.portMutex.acquireIdempotent("drawMatrix",async e=>{await e.tx([_.DRAW_SCALE].concat(t.flat().map(t=>s[Math.floor(255*(t??0))])))})}}class f extends m{async bootloader(){await super.bootloader()}async connect(){const t=await w();t?.connected&&(await u(t),await t.open({baudRate:115200}),this.portMutex=new p(new h(t)))}async draw(t){this.#o||(await super.setGlobalAnalog(32),this.#o=!0),await super.setMatrixPwm(t)}async verifyFirmware(){return null!=await this.version()}async version(){const t=(await super.identityString()).match(A);return t&&3==t.length?{major:t[1],minor:t[2]}:null}#o}const M=[],T=[{vendorId:a,productId:32}];class g extends Error{constructor(){super("User cancelled device selection."),this.name=this.constructor.name,this.date=new Date}}class b{constructor(t){this.#c=t}async send(t,e){if(e.length<t.bytes)e=function(t,e,a=0){return t.concat(new Array(e-t.length).fill(a))}(e,t.bytes);else if(e.length>t.bytes)throw new Error("Unable to send report: too many bytes");const a=new Uint8Array(e).buffer;t.feature?await this.#c.sendFeatureReport(t.id,a):await this.#c.sendReport(t.id,a)}async request(t){let e=[];if(!t.feature)throw new Error("Invalid operation");if(e=await this.#c.receiveFeatureReport(t.id),e.byteLength!=t.bytes){const a=t.bytes,r=e.byteLength;console.error(`reply length=${r} (expected ${a})`)}return e}#c}const v={id:1,bytes:307,feature:!0},S={id:2,bytes:16,feature:!0},I={id:4,bytes:306,feature:!0},R=0,O=1,N=2,P=3,D=5,U=0;class q{constructor(t=null){this.device=t}async info(){const t=await this.device.request(v);return{sleep_pin:t.getUint8(1),dip1_pin:t.getUint8(2),intb_pin:t.getUint8(3),state_flags:t.getUint8(4),id_reg:t.getUint8(5),config_reg:t.getUint8(6),global_brightness:t.getUint8(7),display_width:t.getUint8(8),display_height:t.getUint8(9),timeout_ms:t.getUint32(10),version_major:t.getUint8(14),version_minor:t.getUint8(15)}}async wake(){await this.device.send(S,[O,!1])}async sleep(){await this.device.send(S,[O,!0])}async disableSleep(){await this.device.send(S,[P,255,255,255,255])}async disableDeepSleep(){await this.device.send(S,[N,1])}async disableSleepTimer(){await this.device.send(S,[P,0,0,0,0])}async enableDeepSleep(){await this.device.send(S,[N,0])}async enableSleepTimer(t){const e=new DataView(new ArrayBuffer(4));e.setInt32(0,t,!1),await this.device.send(S,[P,e.getUint8(0),e.getUint8(1),e.getUint8(2),e.getUint8(3)])}async reboot(t){await this.device.send(S,[R,t])}async drawMatrix(t){await this.device.send(I,t.flat().map(t=>s[Math.floor(255*(t??0))]))}async drawPixel(t,e,a){await this.device.send(S,[D,e,t,a])}async drawLine({r1:t,c1:e},{r2:a,c2:r},i){await this.device.send(S,[D,t,e,a,r,i])}device}class L extends q{async bootloader(){await super.reboot(U)}async connect(){const t=await async function(){if(M&&M.length>0)return M.pop();if(M.push(...await navigator.hid.getDevices()),M&&M.length>0)return M.pop();if(M.push(...await navigator.hid.requestDevice({filters:T})),M&&M.length>0)return M.pop();throw new g}();t&&(await t.open(),this.device=new b(t))}async draw(t){await super.drawMatrix(t)}async verifyFirmware(){try{const t=await super.info();return 34==t.display_height&&9==t.display_width}catch{return!1}}async version(){const t=await super.info();return null!=t.version_major&&null!=t.version_minor&&(t.version_major>0||t.version_minor>0)?{major:t.version_major,minor:t.version_minor}:{major:1,minor:0}}}class G{static async detectSerial(){const t=new x,e=new f;return await t.connect(),await t.verifyFirmware()?t:(await e.connect(),await e.verifyFirmware()?e:null)}static async detectHID(){const t=new L;return await t.connect(),await t.verifyFirmware()?t:null}}export{x as DefaultController,s as GAMMA,e as HEIGHT,G as HardwareControllerFactory,i as PID,n as PID_ARR,f as SigrootController,L as SparkleController,a as VID,r as VID_ARR,t as WIDTH};
1
+ const t=9,e=34,a=12972,r=[50,172],i=32,n=[0,32],s=Object.freeze([0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,5,5,5,5,6,6,6,6,6,7,7,7,7,8,8,8,9,9,9,10,10,10,11,11,11,12,12,12,13,13,14,14,14,15,15,16,16,17,17,17,18,18,19,19,20,20,21,22,22,23,23,24,24,25,26,26,27,27,28,29,29,30,31,32,32,33,34,34,35,36,37,38,38,39,40,41,42,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,66,67,68,69,70,71,73,74,75,76,78,79,80,82,83,84,86,87,88,90,91,93,94,96,97,99,100,102,103,105,106,108,110,111,113,115,116,118,120,121,123,125,127,128,130,132,134,136,138,140,141,143,145,147,149,151,153,155,157,159,161,164,166,168,170,172,174,177,179,181,183,186,188,190,193,195,197,200,202,205,207,210,212,215,217,220,222,225,228,230,233,236,238,241,244,247,249,252,255]),o=[{usbVendorId:a,usbProductId:32}];class c extends Error{constructor(){super("User cancelled port selection."),this.name=this.constructor.name,this.date=new Date}}class u extends Error{constructor(){super("Selected port already in use."),this.name=this.constructor.name,this.date=new Date}}async function l(){try{return navigator.serial.requestPort?await navigator.serial.requestPort({filters:o}):null}catch(t){switch(t.name){case"NotFoundError":throw new c;case"InvalidStateError":throw new u;case"SecurityError":return null;default:throw t}}}const d=new class{used=new Set;unused=[];async getOrFetchUnused(){let t=this.unused.pop();if(!t){const e=await navigator.serial.getPorts({filters:o});this.#t(e),t=this.unused.pop()}if(!t){const e=await l();this.#t([e]),t=this.unused.pop()}return t&&this.used.add(t),t}#t(t){if(t)for(const e of t)!e||this.used.has(e)||this.unused.includes(e)||this.unused.push(e)}};async function w(){await l()}async function h(){return await d.getOrFetchUnused()}async function p(t){try{await t.close()}catch(t){if("InvalidStateError"!=t.name&&t.message.includes("The port is already closed"))throw t}}class y{constructor(t){this.#e=`port-mutex-${Math.random().toString()}`,this.#a=new Map,this.#r=t}async acquire(t){const e=new Error("created bad cb").stack;await this.#i(async()=>{try{await t(this.#r)}catch(t){console.error("Error occured in anonymous callback."),console.error("Original error:",t),console.error("--- This callback was created at ---\n",e)}})}async acquireIdempotent(t,e){const a=new Error("created bad cb").stack;this.#a.has(t)&&console.info(`"${t}" request coalesced.`),this.#a.set(t,async()=>{try{await e(this.#r)}catch(t){console.error("Error occured in anonymous callback."),console.error("Original error:",t),console.error("--- This callback was created at ---\n",a)}}),await this.#i(()=>this.#n(t))}async#i(t){return navigator.locks.request(this.#e,t)}async#n(t){if(this.#a.has(t)){const e=this.#a.get(t);this.#a.delete(t),await e()}}#e;#a;#r}class f{constructor(t){this.#s=t}async rx(t,e=3e3){if(null===this.#s)throw new Error("attempted RX before port initialization.");if(this.#s.readable.locked)throw new Error("attempted RX while port locked.");const a=[],r=this.#s.readable.getReader(),i=setTimeout(()=>r.cancel(),e);try{for(;a.length<t;){const{value:t,done:e}=await r.read();if(a.push(...t??[]),e||!t)break}}finally{clearTimeout(i),r.releaseLock()}return a}async tx(t){if(null===this.#s)throw new Error("attempted TX before port initialization.");if(this.#s.writable.locked)throw new Error("attempted TX while port locked.");const e=this.#s.writable.getWriter();try{await e.write(new Uint8Array(t))}finally{await e.close()}}#s}const E=Object.freeze({ANIMATE:4,BRIGHTNESS:0,BOOTLOADER:2,DRAW:6,DRAW_GREY_COL_BUFFER:8,GAME_CTRL:17,GAME_STATUS:18,PANIC:5,PATTERN:1,SLEEP:3,STAGE_GREY_COL:7,START_GAME:16,VERSION:32}),_=Object.freeze({GRAY_8BIT:"8-bit",MONO_1BIT:"1-bit"});let x=class{constructor(t=null){this.portMutex=t}async bootloader(){await this.portMutex.acquire(async t=>{await t.tx([...r,E.BOOTLOADER])})}async brightness(t){await this.portMutex.acquire(async e=>{await e.tx([...r,E.BRIGHTNESS,t])})}async draw(t){let e=0,a=new Uint8Array(39).fill(0);for(let r=0;r<34;r++)for(let i=0;i<9;i++)t[r][i]&&(a[e>>3]|=1<<e%8),e++;await this.portMutex.acquireIdempotent("drawMatrix",async t=>{await t.tx([...r,E.DRAW,...a])})}async drawGrayscale(t){const e=Array.from({length:9},(e,a)=>Array.from({length:34},(e,r)=>s[Math.floor(255*(t[r][a]??0))]));await this.portMutex.acquireIdempotent("drawMatrix",async t=>{for(let a=0;a<9;a++)await t.tx([...r,E.STAGE_GREY_COL,a,...e[a]]);await t.tx([...r,E.DRAW_GREY_COL_BUFFER])})}async asleep(){let t=!1;return await this.portMutex.acquire(async e=>{await e.tx([...r,E.SLEEP]),t=await e.rx(32),t=0!=t[0]}),t}async sleep(){await this.portMutex.acquire(async t=>{await t.tx([...r,E.SLEEP,1])})}async wake(){await this.portMutex.acquire(async t=>{await t.tx([...r,E.SLEEP])})}async pattern(t){await this.portMutex.acquireIdempotent("drawMatrix",async e=>{await e.tx([...r,E.PATTERN,t])})}async percent(t){await this.portMutex.acquireIdempotent("drawMatrix",async e=>{await e.tx([...r,E.PATTERN,Pattern.PERCENTAGE,t])})}async version(){let t={};return await this.portMutex.acquire(async e=>{await e.tx([...r,E.VERSION]);const a=await e.rx(32);t.major=a[0],t.minor=a[1]>>4,t.patch=15&a[1],t.preRelease=1==a[2]}),t}};class m extends x{async bootloader(){return super.bootloader()}async connect(){const t=await h();if(!t?.connected)throw new Error("No Port Found");await p(t),await t.open({baudRate:115200}),this.portMutex=new y(new f(t))}async draw(t){switch(this.bitDepth??_.MONO_1BIT){case _.GRAY_8BIT:super.drawGrayscale(t);break;case _.MONO_1BIT:super.draw(t);break;default:console.error(`Unsupported bitdepth: ${this.bitDepth}`)}}async verifyFirmware(){try{const t=await super.version();return t&&null!=t.major&&null!=t.minor&&null!=t.patch&&null!=t.preRelease}catch{return!1}}async version(){return super.version()}}const A=Object.freeze({NOOP:0,ANIMATION_DIAMOND:100,ANIMATION_FIRE:98,ANIMATION_FIREPLACE:102,ANIMATION_GEAR:103,ANIMATION_RING:114,ANIMATION_STARTUP:97,ANIMATION_STARTUP_ONCE:65,BOOTLOADER:101,DRAW_PWM:109,DRAW_PWM_BLOCKING:77,DRAW_SCALE:110,DRAW_SCALE_BLOCKING:78,FLUSH_CMD_QUEUE:99,TEST_PATTERN:116,SET_CONST_PWM:119,SET_CONST_SCALE:115,SET_PX_PWM:112,SET_PX_SCALE:113,IDENTITY_STRING:127}),T=/^Sig\sFW\sLED\sMatrix\sFW\sV(\d+)\.(\d+)$/;class b{constructor(t=null){this.portMutex=t}async bootloader(){await this.portMutex.acquire(async t=>{await t.tx([A.BOOTLOADER])})}async identityString(){let t=null;return await this.portMutex.acquire(async e=>{await e.tx([A.IDENTITY_STRING]),t=await e.rx(25)}),String.fromCharCode(...t)}async setPixelPwm(t,e,a){await this.portMutex.acquire(async r=>{await r.tx([A.SET_PX_PWM,e,t,a])})}async setGlobalPwm(t){await this.portMutex.acquire(async e=>{await e.tx([A.SET_CONST_PWM,t])})}async setMatrixPwm(t){await this.portMutex.acquireIdempotent("drawMatrix",async e=>{await e.tx([A.DRAW_PWM].concat(t.flat().map(t=>s[Math.floor(255*(t??0))])))})}async setPixelAnalog(t,e,a){await this.portMutex.acquire(async r=>{await r.tx([A.SET_PX_SCALE,e,t,a])})}async setGlobalAnalog(t){await this.portMutex.acquire(async e=>{await e.tx([A.SET_CONST_SCALE,t])})}async setMatrixAnalog(t){await this.portMutex.acquireIdempotent("drawMatrix",async e=>{await e.tx([A.DRAW_SCALE].concat(t.flat().map(t=>s[Math.floor(255*(t??0))])))})}}class g extends b{async bootloader(){await super.bootloader()}async connect(){const t=await h();t?.connected&&(await p(t),await t.open({baudRate:115200}),this.portMutex=new y(new f(t)))}async draw(t){if(this.#o)throw new Error("No Port Found");await super.setGlobalAnalog(32),this.#o=!0,await super.setMatrixPwm(t)}async verifyFirmware(){return null!=await this.version()}async version(){const t=(await super.identityString()).match(T);return t&&3==t.length?{major:t[1],minor:t[2]}:null}#o}const M=[{vendorId:a,productId:32}];class v extends Error{constructor(){super("User cancelled device selection."),this.name=this.constructor.name,this.date=new Date}}async function S(){try{return navigator.serial.requestPort?await navigator.serial.requestDevice({filters:M}):null}catch(t){switch(t.name){case"NotFoundError":throw new v;case"SecurityError":return null;default:throw t}}}const O=new class{used=new Set;unused=[];async getOrFetchUnused(){let t=this.unused.pop();if(!t){const e=await navigator.hid.getDevices({filters:M});this.#t(e),t=this.unused.pop()}if(!t){const e=await S();this.#t([e]),t=this.unused.pop()}return t&&this.used.add(t),t}#t(t){if(t)for(const e of t)!e||this.used.has(e)||this.unused.includes(e)||this.unused.push(e)}};async function I(){await S()}async function R(){return await O.getOrFetchUnused()}class N{constructor(t){this.#c=t}async send(t,e){if(e.length<t.bytes)e=function(t,e,a=0){return t.concat(new Array(e-t.length).fill(a))}(e,t.bytes);else if(e.length>t.bytes)throw new Error("Unable to send report: too many bytes");const a=new Uint8Array(e).buffer;t.feature?await this.#c.sendFeatureReport(t.id,a):await this.#c.sendReport(t.id,a)}async request(t){let e=[];if(!t.feature)throw new Error("Invalid operation");if(e=await this.#c.receiveFeatureReport(t.id),e.byteLength!=t.bytes){const a=t.bytes,r=e.byteLength;console.error(`reply length=${r} (expected ${a})`)}return e}#c}const q={id:1,bytes:307,feature:!0},U={id:2,bytes:16,feature:!0},P={id:4,bytes:306,feature:!0},D=0,L=1,F=2,C=3,G=5,k=0;class W{constructor(t=null){this.device=t}async info(){const t=await this.device.request(q);return{sleep_pin:t.getUint8(1),dip1_pin:t.getUint8(2),intb_pin:t.getUint8(3),state_flags:t.getUint8(4),id_reg:t.getUint8(5),config_reg:t.getUint8(6),global_brightness:t.getUint8(7),display_width:t.getUint8(8),display_height:t.getUint8(9),timeout_ms:t.getUint32(10),version_major:t.getUint8(14),version_minor:t.getUint8(15)}}async wake(){await this.device.send(U,[L,!1])}async sleep(){await this.device.send(U,[L,!0])}async disableSleep(){await this.device.send(U,[C,255,255,255,255])}async disableDeepSleep(){await this.device.send(U,[F,1])}async disableSleepTimer(){await this.device.send(U,[C,0,0,0,0])}async enableDeepSleep(){await this.device.send(U,[F,0])}async enableSleepTimer(t){const e=new DataView(new ArrayBuffer(4));e.setInt32(0,t,!1),await this.device.send(U,[C,e.getUint8(0),e.getUint8(1),e.getUint8(2),e.getUint8(3)])}async reboot(t){await this.device.send(U,[D,t])}async drawMatrix(t){await this.device.send(P,t.flat().map(t=>s[Math.floor(255*(t??0))]))}async drawPixel(t,e,a){await this.device.send(U,[G,e,t,a])}async drawLine({r1:t,c1:e},{r2:a,c2:r},i){await this.device.send(U,[G,t,e,a,r,i])}device}class B extends W{async bootloader(){await super.reboot(k)}async connect(){const t=await R();if(!t)throw new Error("No Device Found");await t.open(),this.device=new N(t)}async draw(t){await super.drawMatrix(t)}async verifyFirmware(){try{const t=await super.info();return 34==t.display_height&&9==t.display_width}catch{return!1}}async version(){const t=await super.info();return null!=t.version_major&&null!=t.version_minor&&(t.version_major>0||t.version_minor>0)?{major:t.version_major,minor:t.version_minor}:{major:1,minor:0}}}class j{static async detectSerial(){const t=new m,e=new g;return await t.connect(),await t.verifyFirmware()?t:(await e.connect(),await e.verifyFirmware()?e:null)}static async detectHID(){const t=new B;return await t.connect(),await t.verifyFirmware()?t:null}}export{m as DefaultController,v as DeviceSelectionCancelled,s as GAMMA,e as HEIGHT,j as HardwareControllerFactory,i as PID,n as PID_ARR,c as PortSelectionCancelled,u as PortUnavailable,g as SigrootController,B as SparkleController,a as VID,r as VID_ARR,t as WIDTH,p as close,R as getUnusedDevice,h as getUnusedPort,I as reqestDeviceForWorker,w as requestPortForWorker};
2
2
  //# sourceMappingURL=led-matrix-controllers.browser.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"led-matrix-controllers.browser.mjs","sources":["../src/hardware-constants.js","../src/web-serial/port.js","../src/web-serial/PortMutex.js","../src/web-serial/PortOperations.js","../src/supported-firmware/FrameworkComputer/inputmodule-rs/commands.js","../src/supported-firmware/FrameworkComputer/inputmodule-rs/CommandAbstractionLayer.js","../src/supported-firmware/FrameworkComputer/inputmodule-rs/DefaultController.js","../src/supported-firmware/sigroot/FW_LED_Matrix_Firmware/commands.js","../src/supported-firmware/sigroot/FW_LED_Matrix_Firmware/CommandAbstractionLayer.js","../src/supported-firmware/sigroot/FW_LED_Matrix_Firmware/SigrootController.js","../src/web-hid/device.js","../src/web-hid/HIDOperations.js","../src/web-hid/util.js","../src/supported-firmware/vddCore/sparkle-fw16/reports.js","../src/supported-firmware/vddCore/sparkle-fw16/ReportAbstractionLayer.js","../src/supported-firmware/vddCore/sparkle-fw16/SparkleController.js","../src/HardwareControllerFactory.js"],"sourcesContent":["export const WIDTH = 9;\nexport const HEIGHT = 34;\nexport const VID = 0x32AC;\nexport const VID_ARR = [0x32, 0xAC];\nexport const PID = 0x0020;\nexport const PID_ARR = [0x00, 0x20];\n\nexport const GAMMA = Object.freeze([\n 0, 0, 0, 0, 0, 0, 0, 1, \n 1, 1, 1, 1, 1, 1, 1, 1, \n 1, 1, 1, 1, 1, 1, 1, 1, \n 1, 1, 1, 1, 1, 1, 1, 1, \n 1, 1, 1, 2, 2, 2, 2, 2, \n 2, 2, 2, 2, 3, 3, 3, 3, \n 3, 3, 3, 4, 4, 4, 4, 4, \n 4, 5, 5, 5, 5, 6, 6, 6, \n 6, 6, 7, 7, 7, 7, 8, 8, \n 8, 9, 9, 9, 10, 10, 10, 11, \n 11, 11, 12, 12, 12, 13, 13, 14, \n 14, 14, 15, 15, 16, 16, 17, 17, \n 17, 18, 18, 19, 19, 20, 20, 21, \n 22, 22, 23, 23, 24, 24, 25, 26, \n 26, 27, 27, 28, 29, 29, 30, 31, \n 32, 32, 33, 34, 34, 35, 36, 37, \n 38, 38, 39, 40, 41, 42, 42, 43, \n 44, 45, 46, 47, 48, 49, 50, 51, \n 52, 53, 54, 55, 56, 57, 58, 59, \n 60, 61, 62, 63, 64, 66, 67, 68, \n 69, 70, 71, 73, 74, 75, 76, 78, \n 79, 80, 82, 83, 84, 86, 87, 88, \n 90, 91, 93, 94, 96, 97, 99, 100, \n 102, 103, 105, 106, 108, 110, 111, 113, \n 115, 116, 118, 120, 121, 123, 125, 127, \n 128, 130, 132, 134, 136, 138, 140, 141, \n 143, 145, 147, 149, 151, 153, 155, 157, \n 159, 161, 164, 166, 168, 170, 172, 174, \n 177, 179, 181, 183, 186, 188, 190, 193, \n 195, 197, 200, 202, 205, 207, 210, 212, \n 215, 217, 220, 222, 225, 228, 230, 233, \n 236, 238, 241, 244, 247, 249, 252, 255\n]);\n","import { PID, VID } from '../hardware-constants.js';\n\nconst extraPorts = [];\n\nconst filters = [\n {\n usbVendorId: VID,\n usbProductId: PID,\n }\n];\n\nexport class PortSelectionCancelled extends Error {\n constructor() {\n super('User cancelled port selection.');\n this.name = this.constructor.name;\n this.date = new Date();\n }\n}\n\nexport class PortUnavailable extends Error {\n constructor() {\n super('Selected port already in use.');\n this.name = this.constructor.name;\n this.date = new Date();\n }\n}\n\nexport async function getPort() {\n try {\n if (extraPorts && extraPorts.length > 0) {\n return extraPorts.pop();\n }\n\n extraPorts.push(...(await navigator.serial.getPorts()));\n if (extraPorts && extraPorts.length > 0) {\n return extraPorts.pop();\n }\n\n extraPorts.push(...(await navigator.serial.requestPort({ filters })));\n if (extraPorts && extraPorts.length > 0) {\n return extraPorts.pop();\n }\n\n } catch (e) {\n if (e.name == 'NotFoundError') {\n throw new PortSelectionCancelled();\n } else if (e.name == 'InvalidStateError') {\n throw new PortUnavailable();\n } else {\n throw e;\n }\n }\n}\n\nexport async function close(port) {\n try {\n await port.close();\n } catch(e) {\n if (e.name != 'InvalidStateError') {\n if (e.message != \"Failed to execute 'close' on 'SerialPort': The port is already closed.\") {\n throw e;\n }\n }\n }\n}\n","export class PortMutex {\n constructor(portOperations) {\n this.#lockName = `port-mutex-${Math.random().toString()}`;\n this.#deduper = new Map();\n this.#portOps = portOperations;\n }\n\n async acquire(fn) {\n const trace = new Error('created bad cb').stack;\n\n await this.#enqueue(async () => {\n try {\n await fn(this.#portOps);\n } catch (e) {\n console.error('Error occured in anonymous callback.');\n console.error('Original error:', e);\n console.error('--- This callback was created at ---\\n', trace);\n }\n });\n }\n\n async acquireIdempotent(key, fn) {\n const trace = new Error('created bad cb').stack;\n\n if (this.#deduper.has(key)) {\n console.info(`\"${key}\" request coalesced.`);\n }\n\n this.#deduper.set(key, async () => {\n try {\n await fn(this.#portOps);\n } catch (e) {\n console.error('Error occured in anonymous callback.');\n console.error('Original error:', e);\n console.error('--- This callback was created at ---\\n', trace);\n }\n });\n\n await this.#enqueue(() => this.#execDedupedOp(key));\n }\n\n async #enqueue(fn) {\n // `navigator.locks` maintains queue and provides mutual exclusion.\n return navigator.locks.request(this.#lockName, fn);\n }\n\n async #execDedupedOp(key) {\n if (this.#deduper.has(key)) {\n const fn = this.#deduper.get(key);\n this.#deduper.delete(key);\n await fn();\n }\n }\n\n #lockName;\n #deduper;\n #portOps;\n}\n","export class PortOperations {\n constructor(port) {\n this.#port = port;\n }\n\n async rx(length, timeout=3000) {\n if (this.#port === null) {\n throw new Error('attempted RX before port initialization.');\n }\n\n /*\n * ReadableStream's built-in locking mechanism cannot be awaited or otherwise\n * asynchronously acquired. A PortMutex must be used.\n */\n if (this.#port.readable.locked) {\n throw new Error('attempted RX while port locked.');\n }\n\n const response = [];\n const reader = this.#port.readable.getReader();\n const timeoutHandle = setTimeout(() => reader.cancel(), timeout);\n\n try {\n // Response may be divided across multiple reads\n while (response.length < length) {\n const { value, done } = await reader.read();\n response.push(...(value ?? []));\n if (done || !value) break;\n }\n } finally {\n clearTimeout(timeoutHandle);\n reader.releaseLock();\n }\n\n return response;\n }\n\n async tx(buffer) {\n if (this.#port === null) {\n throw new Error('attempted TX before port initialization.');\n }\n \n /*\n * WritableStream's built-in locking mechanism cannot be awaited or otherwise\n * asynchronously acquired. A PortMutex must be used.\n */\n if (this.#port.writable.locked) {\n throw new Error('attempted TX while port locked.');\n }\n\n const writer = this.#port.writable.getWriter();\n\n try {\n await writer.write(new Uint8Array(buffer));\n } finally {\n /* \n * The writer must be completely torn down between every single write.\n * Many parsers can't handle delayed flushing and write coalescing.\n * Command sequences will fail if `releaseLock()` is used here.\n */\n await writer.close();\n }\n }\n\n #port;\n}\n","// All replies to all commands are 32 bytes\nexport const RX_PACKET_SZ = 32;\n\nexport const Command = Object.freeze({\n ANIMATE: 0x04,\n BRIGHTNESS: 0x00,\n BOOTLOADER: 0x02,\n DRAW: 0x06,\n DRAW_GREY_COL_BUFFER: 0x08,\n GAME_CTRL: 0x11,\n GAME_STATUS: 0x12,\n PANIC: 0x05,\n PATTERN: 0x01,\n SLEEP: 0x03,\n STAGE_GREY_COL: 0x07,\n START_GAME: 0x10,\n VERSION: 0x20,\n});\n\n// Used with Command.PATTERN\nexport const Pattern = Object.freeze({\n DISPLAY_LOTUS_HORIZONTAL: 0x03,\n DISPLAY_LOTUS_VERTICAL: 0x07,\n DISPLAY_PANIC: 0x06,\n DOUBLE_GRADIENT: 0x02,\n FULL_BRIGHTNESS: 0x05,\n GRADIENT: 0x01,\n PERCENTAGE: 0x00,\n ZIG_ZAG: 0x04,\n});\n\n// DRAW or DRAW_GREY_COL_BUFFER\nexport const BitDepth = Object.freeze({\n GRAY_8BIT: '8-bit',\n MONO_1BIT: '1-bit',\n})\n","import { HEIGHT, VID_ARR, WIDTH } from '../../../hardware-constants.js';\nimport { Command, RX_PACKET_SZ } from './commands.js';\n\nexport class CommandAbstractionLayer {\n constructor(portMutex = null) {\n this.portMutex = portMutex;\n }\n\n async bootloader() {\n await this.portMutex.acquire(async p => {\n await p.tx([...VID_ARR, Command.BOOTLOADER]);\n });\n }\n\n async brightness(brightness) {\n await this.portMutex.acquire(async p => {\n await p.tx([...VID_ARR, Command.BRIGHTNESS, brightness]);\n });\n }\n\n async draw(matrix) {\n let index = 0;\n let output = new Uint8Array(39).fill(0);\n\n // Pack cells into bits\n for (let r = 0; r < HEIGHT; r++) {\n for (let c = 0; c < WIDTH; c++) {\n if (matrix[r][c]) {\n output[index >> 3] |= 1 << index % 8;\n }\n index++;\n }\n }\n\n await this.portMutex.acquireIdempotent(\n 'drawMatrix', \n async p => {\n await p.tx([...VID_ARR, Command.DRAW, ...output]);\n }\n );\n }\n\n async drawGrayscale(matrix) {\n // Transpose & Gamma Correction\n const buffers = Array.from(\n { length: WIDTH }, \n (_, c) => new Array(\n { length: HEIGHT }, \n (_, r) => GAMMA[Math.floor((matrix[r][c] ?? 0) * 255)]\n )\n );\n\n // Only execute the most recent call \n await this.portMutex.acquireIdempotent(\n 'drawMatrix', \n async p => {\n for (let i = 0; i < WIDTH; i++) {\n await p.tx([...VID_ARR, Command.STAGE_GREY_COL, i, ...buffers[i]]);\n }\n await p.tx([...VID_ARR, Command.DRAW_GREY_COL_BUFFER]);\n }\n );\n }\n\n async asleep() {\n let asleep = false;\n\n await this.portMutex.acquire(async p => {\n await p.tx([...VID_ARR, Command.SLEEP]);\n asleep = await p.rx(RX_PACKET_SZ);\n asleep = asleep[0] != 0x00;\n });\n\n return asleep;\n }\n\n async sleep() {\n await this.portMutex.acquire(async p => {\n await p.tx([...VID_ARR, Command.SLEEP, 0x01]);\n });\n }\n\n async wake() {\n await this.portMutex.acquire(async p => {\n await p.tx([...VID_ARR, Command.SLEEP]);\n });\n }\n\n async pattern(pattern) {\n await this.portMutex.acquireIdempotent(\n 'drawMatrix',\n async p => {\n await p.tx([...VID_ARR, Command.PATTERN, pattern]);\n }\n );\n }\n\n async percent(percent) {\n await this.portMutex.acquireIdempotent(\n 'drawMatrix',\n async p => {\n await p.tx([...VID_ARR, Command.PATTERN, Pattern.PERCENTAGE, percent]);\n }\n );\n }\n\n async version() {\n let ver = {};\n\n await this.portMutex.acquire(async p => {\n await p.tx([...VID_ARR, Command.VERSION]);\n const response = await p.rx(RX_PACKET_SZ);\n\n // MMMMMMMM mmmmPPPP 0000000p\n ver.major = response[0];\n ver.minor = response[1] >> 4;\n ver.patch = response[1] & 0x0F;\n ver.preRelease = response[2] == 1;\n });\n\n return ver;\n }\n}\n","import { close, getPort } from '../../../web-serial/port.js';\nimport { PortMutex } from '../../../web-serial/PortMutex.js';\nimport { PortOperations } from '../../../web-serial/PortOperations.js';\nimport { CommandAbstractionLayer } from './CommandAbstractionLayer.js';\n\nexport class DefaultController extends CommandAbstractionLayer {\n async bootloader() {\n return super.bootloader();\n }\n\n async connect() {\n const port = await getPort();\n\n if (port?.connected) {\n await close(port);\n await port.open({ baudRate: 115200 });\n this.portMutex = new PortMutex(new PortOperations(port));\n }\n }\n\n async draw(matrix) {\n switch (this.#bitDepth) {\n\n case BitDepth.GRAY_8BIT:\n super.drawGrayscale(matrix);\n break;\n\n case BitDepth.MONO_1BIT:\n super.draw(matrix);\n break;\n }\n }\n\n async verifyFirmware() {\n try {\n const version = await super.version();\n\n return version\n && version.major != undefined\n && version.minor != undefined\n && version.patch != undefined\n && version.preRelease != undefined;\n \n } catch {\n return false;\n }\n }\n\n async version() {\n return super.version();\n }\n\n #bitDepth;\n}\n","export const Command = Object.freeze({\n /* 000 */ NOOP: 0x00,\n /* 'd' */ ANIMATION_DIAMOND: 0x64,\n /* 'b' */ ANIMATION_FIRE: 0x62,\n /* 'f' */ ANIMATION_FIREPLACE: 0x66,\n /* 'g' */ ANIMATION_GEAR: 0x67,\n /* 'r' */ ANIMATION_RING: 0x72,\n /* 'a' */ ANIMATION_STARTUP: 0x61,\n /* 'A' */ ANIMATION_STARTUP_ONCE: 0x41,\n /* 'e' */ BOOTLOADER: 0x65,\n /* 'm' */ DRAW_PWM: 0x6D,\n /* 'M' */ DRAW_PWM_BLOCKING: 0x4D,\n /* 'n' */ DRAW_SCALE: 0x6E,\n /* 'N' */ DRAW_SCALE_BLOCKING: 0x4E,\n /* 'c' */ FLUSH_CMD_QUEUE: 0x63,\n /* 't' */ TEST_PATTERN: 0x74,\n /* 'w' */ SET_CONST_PWM: 0x77,\n /* 's' */ SET_CONST_SCALE: 0x73,\n /* 'p' */ SET_PX_PWM: 0x70,\n /* 'q' */ SET_PX_SCALE: 0x71,\n /* 127 */ IDENTITY_STRING: 0x7F,\n});\n\nexport const IDENTITY_STR_LEN = 25;\n\nexport const IDENTITY_STR_REGEX = /^Sig\\sFW\\sLED\\sMatrix\\sFW\\sV(\\d+)\\.(\\d+)$/;\n","import { GAMMA } from '../../../hardware-constants.js';\nimport { Command, IDENTITY_STR_LEN } from './commands.js';\n\nexport class CommandAbstractionLayer {\n constructor(portMutex = null) {\n this.portMutex = portMutex;\n }\n\n async bootloader() {\n await this.portMutex.acquire(async p => {\n await p.tx([Command.BOOTLOADER]);\n });\n }\n\n async identityString() {\n let ident = null;\n\n await this.portMutex.acquire(async p => {\n await p.tx([Command.IDENTITY_STRING]);\n ident = await p.rx(IDENTITY_STR_LEN);\n });\n\n return String.fromCharCode(...ident);\n }\n\n async setPixelPwm(r, c, brightness) {\n await this.portMutex.acquire(\n async p => {\n await p.tx([Command.SET_PX_PWM, c, r, brightness]);\n }\n );\n }\n\n async setGlobalPwm(brightness) {\n await this.portMutex.acquire(\n async p => {\n await p.tx([Command.SET_CONST_PWM, brightness]);\n }\n );\n }\n\n async setMatrixPwm(matrix) {\n // Only execute the most recent call \n await this.portMutex.acquireIdempotent(\n 'drawMatrix', \n async p => {\n await p.tx(\n [Command.DRAW_PWM].concat(\n matrix.flat().map(v => \n GAMMA[Math.floor((v ?? 0) * 255)]\n )\n )\n );\n }\n );\n }\n\n async setPixelAnalog(r, c, brightness) {\n await this.portMutex.acquire(\n async p => {\n await p.tx([Command.SET_PX_SCALE, c, r, brightness]);\n }\n );\n }\n\n async setGlobalAnalog(brightness) {\n await this.portMutex.acquire(\n async p => {\n await p.tx([Command.SET_CONST_SCALE, brightness]);\n }\n );\n }\n\n async setMatrixAnalog(matrix) {\n // Only execute the most recent call \n await this.portMutex.acquireIdempotent(\n 'drawMatrix', \n async p => {\n await p.tx(\n [Command.DRAW_SCALE].concat(\n matrix.flat().map(v => \n GAMMA[Math.floor((v ?? 0) * 255)]\n )\n )\n );\n }\n );\n }\n}\n","import { close, getPort } from '../../../web-serial/port.js';\nimport { PortMutex } from '../../../web-serial/PortMutex.js';\nimport { PortOperations } from '../../../web-serial/PortOperations.js';\nimport { CommandAbstractionLayer } from './CommandAbstractionLayer.js';\nimport { IDENTITY_STR_REGEX } from './commands.js';\n\nexport class SigrootController extends CommandAbstractionLayer {\n async bootloader() {\n await super.bootloader();\n }\n\n async connect() {\n const port = await getPort();\n\n if (port?.connected) {\n await close(port);\n await port.open({ baudRate: 115200 });\n this.portMutex = new PortMutex(new PortOperations(port));\n }\n }\n\n async draw(matrix) {\n if (!this.#scaleInitialized) {\n await super.setGlobalAnalog(0x20);\n this.#scaleInitialized = true;\n }\n\n await super.setMatrixPwm(matrix);\n }\n\n async verifyFirmware() { \n return await this.version() != null;\n }\n\n async version() {\n const ident = await super.identityString();\n const match = ident.match(IDENTITY_STR_REGEX);\n\n if (match && match.length == 3) {\n return {\n major: match[1],\n minor: match[2]\n }\n } else {\n return null;\n }\n }\n\n #scaleInitialized;\n}\n","import { PID, VID } from '../hardware-constants.js';\n\nconst extraDevices = [];\n\nconst filters = [\n {\n vendorId: VID,\n productId: PID,\n }\n];\n\nexport class DeviceSelectionCancelled extends Error {\n constructor() {\n super('User cancelled device selection.');\n this.name = this.constructor.name;\n this.date = new Date();\n }\n}\n\nexport async function getDevice() {\n if (extraDevices && extraDevices.length > 0) {\n return extraDevices.pop();\n }\n\n extraDevices.push(...(await navigator.hid.getDevices()));\n if (extraDevices && extraDevices.length > 0) {\n return extraDevices.pop();\n }\n\n extraDevices.push(...(await navigator.hid.requestDevice({ filters })));\n if (extraDevices && extraDevices.length > 0) {\n return extraDevices.pop();\n }\n\n throw new DeviceSelectionCancelled();\n}\n","import { pad } from './util.js';\n\nexport class HIDOperations {\n constructor(device) {\n this.#device = device;\n }\n\n async send(report, data) {\n if (data.length < report.bytes) {\n data = pad(data, report.bytes);\n } else if (data.length > report.bytes) {\n throw new Error('Unable to send report: too many bytes');\n }\n\n const buffer = new Uint8Array(data).buffer;\n\n if (report.feature) {\n await this.#device.sendFeatureReport(report.id, buffer);\n } else {\n await this.#device.sendReport(report.id, buffer);\n }\n }\n\n async request(report) {\n let reply = [];\n\n if (report.feature) {\n reply = await this.#device.receiveFeatureReport(report.id);\n } else {\n /* \n * HID input reports are used for unprompted data.\n * See WebHID `HIDInputReportEvent`\n */\n throw new Error('Invalid operation');\n }\n\n if (reply.byteLength != report.bytes) {\n const exp = report.bytes;\n const act = reply.byteLength;\n console.error(`reply length=${act} (expected ${exp})`);\n }\n\n return reply;\n }\n\n #device;\n}\n","export function pad(arr, len, val=0x00) {\n return arr.concat(new Array(len - arr.length).fill(val));\n}\n","export const Reports = {\n GLITTER_DEVICE_INFO: {\n id: 0x01,\n bytes: 307,\n feature: true,\n },\n GLITTER_BASIC_CMD: {\n id: 0x02,\n bytes: 16,\n feature: true,\n },\n GLITTER_GRID_PWM_CNTL: {\n id: 0x03,\n bytes: 306,\n feature: true,\n },\n GLITTER_GRID_PWM_CNTL: {\n id: 0x04,\n bytes: 306,\n feature: true,\n }\n}\n\nexport const Commands = {\n GLITTER_CMD_REBOOT: 0x00,\n GLITTER_CMD_SLEEP: 0x01,\n GLITTER_CMD_WAKE_ON_COMMAND: 0x02,\n GLITTER_CMD_SET_SLEEP_TIMEOUT: 0x03,\n GLITTER_CMD_SET_GLOBAL_BRIGHTNESS: 0x04,\n GLITTER_CMD_DRAW_PIXEL: 0x05,\n GLITTER_CMD_DRAW_LINE: 0x06\n}\n\nexport const BootMode = {\n BOOTSEL: 0x00,\n NORMAL: 0x01,\n}\n","import { GAMMA } from '../../../hardware-constants.js';\nimport { Commands, Reports } from './reports.js';\n\nexport class ReportAbstractionLayer {\n constructor(device = null) {\n this.device = device;\n }\n\n async info() {\n const infoRaw = await this.device.request(Reports.GLITTER_DEVICE_INFO);\n\n return {\n sleep_pin: infoRaw.getUint8(1),\n dip1_pin: infoRaw.getUint8(2),\n intb_pin: infoRaw.getUint8(3),\n state_flags: infoRaw.getUint8(4),\n id_reg: infoRaw.getUint8(5),\n config_reg: infoRaw.getUint8(6),\n global_brightness: infoRaw.getUint8(7),\n display_width: infoRaw.getUint8(8),\n display_height: infoRaw.getUint8(9),\n timeout_ms: infoRaw.getUint32(10),\n version_major: infoRaw.getUint8(14),\n version_minor: infoRaw.getUint8(15),\n };\n }\n\n async wake() {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD,\n [Commands.GLITTER_CMD_SLEEP, false]\n );\n }\n\n async sleep() {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD,\n [Commands.GLITTER_CMD_SLEEP, true]\n );\n }\n\n async disableSleep() {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD, \n [Commands.GLITTER_CMD_SET_SLEEP_TIMEOUT, 0xff, 0xff, 0xff, 0xff]\n );\n }\n\n async disableDeepSleep() {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD, \n [Commands.GLITTER_CMD_WAKE_ON_COMMAND, 0x01]\n );\n }\n\n async disableSleepTimer() {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD, \n [Commands.GLITTER_CMD_SET_SLEEP_TIMEOUT, 0x00, 0x00, 0x00, 0x00]\n );\n }\n \n async enableDeepSleep() {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD, \n [Commands.GLITTER_CMD_WAKE_ON_COMMAND, 0x00]\n );\n }\n\n async enableSleepTimer(milliseconds) {\n const view = new DataView(new ArrayBuffer(4));\n const littleEndian = false;\n view.setInt32(0, milliseconds, littleEndian);\n await this.device.send(\n Reports.GLITTER_BASIC_CMD, \n [\n Commands.GLITTER_CMD_SET_SLEEP_TIMEOUT, \n view.getUint8(0), \n view.getUint8(1), \n view.getUint8(2), \n view.getUint8(3),\n ]\n );\n }\n\n async reboot(mode) {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD, \n [Commands.GLITTER_CMD_REBOOT, mode]\n );\n }\n\n async drawMatrix(matrix) {\n await this.device.send(\n Reports.GLITTER_GRID_PWM_CNTL,\n matrix.flat().map(v => GAMMA[Math.floor((v ?? 0) * 255)])\n );\n }\n\n async drawPixel(r, c, brightness) {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD,\n [Commands.GLITTER_CMD_DRAW_PIXEL, c, r, brightness]\n );\n }\n\n async drawLine({r1, c1}, {r2, c2}, brightness) {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD,\n [Commands.GLITTER_CMD_DRAW_PIXEL, r1, c1, r2, c2, brightness]\n );\n }\n\n device;\n}\n","import { HEIGHT, WIDTH } from '../../../hardware-constants.js';\nimport { getDevice } from '../../../web-hid/device.js';\nimport { HIDOperations } from '../../../web-hid/HIDOperations.js';\nimport { ReportAbstractionLayer } from './ReportAbstractionLayer.js';\nimport { BootMode } from './reports.js';\n\nexport class SparkleController extends ReportAbstractionLayer {\n async bootloader() {\n await super.reboot(BootMode.BOOTSEL);\n }\n\n async connect() {\n const device = await getDevice();\n if (device) {\n await device.open();\n this.device = new HIDOperations(device);\n }\n }\n \n async draw(matrix) {\n await super.drawMatrix(matrix);\n }\n\n async verifyFirmware() {\n try {\n const info = await super.info();\n return (\n info.display_height == HEIGHT &&\n info.display_width == WIDTH\n );\n } catch {\n return false;\n }\n }\n\n async version() {\n const info = await super.info();\n if (info.version_major != undefined \n && info.version_minor != undefined\n && (info.version_major > 0 || info.version_minor > 0)) {\n return {\n major: info.version_major,\n minor: info.version_minor\n }\n } else {\n // Sparkle <=1.1.1: Glitter version unavailable \n return { major: 1, minor: 0 };\n }\n }\n}\n","import { DefaultController } from './supported-firmware/FrameworkComputer/inputmodule-rs/DefaultController.js';\nimport { SigrootController } from './supported-firmware/sigroot/FW_LED_Matrix_Firmware/SigrootController.js';\nimport { SparkleController } from './supported-firmware/vddCore/sparkle-fw16/SparkleController.js';\n\nexport class HardwareControllerFactory {\n static async detectSerial() {\n const c1 = new DefaultController();\n const c2 = new SigrootController();\n\n await c1.connect();\n if (await c1.verifyFirmware()) {\n return c1;\n }\n \n await c2.connect()\n if (await c2.verifyFirmware()) {\n return c2;\n } \n \n return null;\n }\n\n static async detectHID() {\n const c1 = new SparkleController();\n\n await c1.connect();\n if (await c1.verifyFirmware()) {\n return c1;\n } \n \n return null;\n }\n}\n"],"names":["WIDTH","HEIGHT","VID","VID_ARR","PID","PID_ARR","GAMMA","Object","freeze","extraPorts","filters","usbVendorId","usbProductId","PortSelectionCancelled","Error","constructor","super","this","name","date","Date","PortUnavailable","async","getPort","length","pop","push","navigator","serial","getPorts","requestPort","e","close","port","message","PortMutex","portOperations","lockName","Math","random","toString","deduper","Map","portOps","acquire","fn","trace","stack","enqueue","console","error","acquireIdempotent","key","has","info","set","execDedupedOp","locks","request","get","delete","PortOperations","rx","timeout","readable","locked","response","reader","getReader","timeoutHandle","setTimeout","cancel","value","done","read","clearTimeout","releaseLock","tx","buffer","writable","writer","getWriter","write","Uint8Array","Command","ANIMATE","BRIGHTNESS","BOOTLOADER","DRAW","DRAW_GREY_COL_BUFFER","GAME_CTRL","GAME_STATUS","PANIC","PATTERN","SLEEP","STAGE_GREY_COL","START_GAME","VERSION","CommandAbstractionLayer$1","portMutex","bootloader","p","brightness","draw","matrix","index","output","fill","r","c","drawGrayscale","buffers","Array","from","_","floor","i","asleep","sleep","wake","pattern","percent","Pattern","PERCENTAGE","version","ver","major","minor","patch","preRelease","DefaultController","CommandAbstractionLayer","connect","connected","open","baudRate","bitDepth","BitDepth","GRAY_8BIT","MONO_1BIT","verifyFirmware","undefined","NOOP","ANIMATION_DIAMOND","ANIMATION_FIRE","ANIMATION_FIREPLACE","ANIMATION_GEAR","ANIMATION_RING","ANIMATION_STARTUP","ANIMATION_STARTUP_ONCE","DRAW_PWM","DRAW_PWM_BLOCKING","DRAW_SCALE","DRAW_SCALE_BLOCKING","FLUSH_CMD_QUEUE","TEST_PATTERN","SET_CONST_PWM","SET_CONST_SCALE","SET_PX_PWM","SET_PX_SCALE","IDENTITY_STRING","IDENTITY_STR_REGEX","identityString","ident","String","fromCharCode","setPixelPwm","setGlobalPwm","setMatrixPwm","concat","flat","map","v","setPixelAnalog","setGlobalAnalog","setMatrixAnalog","SigrootController","scaleInitialized","match","extraDevices","vendorId","productId","DeviceSelectionCancelled","HIDOperations","device","send","report","data","bytes","arr","len","val","pad","feature","sendFeatureReport","id","sendReport","reply","receiveFeatureReport","byteLength","exp","act","Reports","Commands","BootMode","ReportAbstractionLayer","infoRaw","sleep_pin","getUint8","dip1_pin","intb_pin","state_flags","id_reg","config_reg","global_brightness","display_width","display_height","timeout_ms","getUint32","version_major","version_minor","disableSleep","disableDeepSleep","disableSleepTimer","enableDeepSleep","enableSleepTimer","milliseconds","view","DataView","ArrayBuffer","setInt32","reboot","mode","drawMatrix","drawPixel","drawLine","r1","c1","r2","c2","SparkleController","hid","getDevices","requestDevice","getDevice","HardwareControllerFactory","detectSerial","detectHID"],"mappings":"AAAY,MAACA,EAAQ,EACRC,EAAS,GACTC,EAAM,MACNC,EAAU,CAAC,GAAM,KACjBC,EAAM,GACNC,EAAU,CAAC,EAAM,IAEjBC,EAAQC,OAAOC,OAAO,CACjC,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EA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3J,OAAS,EACxC,OAAO2J,EAAa1J,MAGtB,MAAM,IAAI6J,CACZ,CKvByB8D,GACjB5D,UACIA,EAAOlD,OACbrH,KAAKuK,OAAS,IAAID,EAAcC,GAEpC,CAEA,UAAMjF,CAAKC,SACHxF,MAAMyN,WAAWjI,EACzB,CAEA,oBAAMoC,GACJ,IACE,MAAMtF,QAAatC,MAAMsC,OACzB,OfzBgB,Ie0BdA,EAAKkK,gBf3BQ,Ge4BblK,EAAKiK,aAET,CAAE,MACA,OAAO,CACT,CACF,CAEA,aAAM3F,GACJ,MAAMtE,QAAatC,MAAMsC,OACzB,OAA0BuF,MAAtBvF,EAAKqK,eACkB9E,MAAtBvF,EAAKsK,gBACJtK,EAAKqK,cAAgB,GAAKrK,EAAKsK,cAAgB,GAC5C,CACL9F,MAAOxE,EAAKqK,cACZ5F,MAAOzE,EAAKsK,eAIP,CAAE9F,MAAO,EAAGC,MAAO,EAE9B,EC5CK,MAAMsH,EACX,yBAAaC,GACX,MAAMT,EAAK,IAAI3G,EACT6G,EAAK,IAAI/D,EAGf,aADM6D,EAAGzG,gBACCyG,EAAGjG,iBACJiG,SAGHE,EAAG3G,gBACC2G,EAAGnG,iBACJmG,EAGF,KACT,CAEA,sBAAaQ,GACX,MAAMV,EAAK,IAAIG,EAGf,aADMH,EAAGzG,gBACCyG,EAAGjG,iBACJiG,EAGF,IACT"}
1
+ {"version":3,"file":"led-matrix-controllers.browser.mjs","sources":["../src/hardware-constants.js","../src/web-serial/port.js","../src/web-serial/PortMutex.js","../src/web-serial/PortOperations.js","../src/supported-firmware/FrameworkComputer/inputmodule-rs/commands.js","../src/supported-firmware/FrameworkComputer/inputmodule-rs/CommandAbstractionLayer.js","../src/supported-firmware/FrameworkComputer/inputmodule-rs/DefaultController.js","../src/supported-firmware/sigroot/FW_LED_Matrix_Firmware/commands.js","../src/supported-firmware/sigroot/FW_LED_Matrix_Firmware/CommandAbstractionLayer.js","../src/supported-firmware/sigroot/FW_LED_Matrix_Firmware/SigrootController.js","../src/web-hid/device.js","../src/web-hid/HIDOperations.js","../src/web-hid/util.js","../src/supported-firmware/vddCore/sparkle-fw16/reports.js","../src/supported-firmware/vddCore/sparkle-fw16/ReportAbstractionLayer.js","../src/supported-firmware/vddCore/sparkle-fw16/SparkleController.js","../src/HardwareControllerFactory.js"],"sourcesContent":["export const WIDTH = 9;\nexport const HEIGHT = 34;\nexport const VID = 0x32AC;\nexport const VID_ARR = [0x32, 0xAC];\nexport const PID = 0x0020;\nexport const PID_ARR = [0x00, 0x20];\n\n// For PWM dimming (not for analog dimming/constant-current reduction!)\nexport const GAMMA = Object.freeze([\n 0, 0, 0, 0, 0, 0, 0, 1, \n 1, 1, 1, 1, 1, 1, 1, 1, \n 1, 1, 1, 1, 1, 1, 1, 1, \n 1, 1, 1, 1, 1, 1, 1, 1, \n 1, 1, 1, 2, 2, 2, 2, 2, \n 2, 2, 2, 2, 3, 3, 3, 3, \n 3, 3, 3, 4, 4, 4, 4, 4, \n 4, 5, 5, 5, 5, 6, 6, 6, \n 6, 6, 7, 7, 7, 7, 8, 8, \n 8, 9, 9, 9, 10, 10, 10, 11, \n 11, 11, 12, 12, 12, 13, 13, 14, \n 14, 14, 15, 15, 16, 16, 17, 17, \n 17, 18, 18, 19, 19, 20, 20, 21, \n 22, 22, 23, 23, 24, 24, 25, 26, \n 26, 27, 27, 28, 29, 29, 30, 31, \n 32, 32, 33, 34, 34, 35, 36, 37, \n 38, 38, 39, 40, 41, 42, 42, 43, \n 44, 45, 46, 47, 48, 49, 50, 51, \n 52, 53, 54, 55, 56, 57, 58, 59, \n 60, 61, 62, 63, 64, 66, 67, 68, \n 69, 70, 71, 73, 74, 75, 76, 78, \n 79, 80, 82, 83, 84, 86, 87, 88, \n 90, 91, 93, 94, 96, 97, 99, 100, \n 102, 103, 105, 106, 108, 110, 111, 113, \n 115, 116, 118, 120, 121, 123, 125, 127, \n 128, 130, 132, 134, 136, 138, 140, 141, \n 143, 145, 147, 149, 151, 153, 155, 157, \n 159, 161, 164, 166, 168, 170, 172, 174, \n 177, 179, 181, 183, 186, 188, 190, 193, \n 195, 197, 200, 202, 205, 207, 210, 212, \n 215, 217, 220, 222, 225, 228, 230, 233, \n 236, 238, 241, 244, 247, 249, 252, 255\n]);\n","import { PID, VID } from '../hardware-constants.js';\n\nconst filters = [{ usbVendorId: VID, usbProductId: PID }];\n\nexport class PortSelectionCancelled extends Error {\n constructor() {\n super('User cancelled port selection.');\n this.name = this.constructor.name;\n this.date = new Date();\n }\n}\n\nexport class PortUnavailable extends Error {\n constructor() {\n super('Selected port already in use.');\n this.name = this.constructor.name;\n this.date = new Date();\n }\n}\n\nasync function requestPort() {\n try {\n if (navigator.serial.requestPort) {\n return await navigator.serial.requestPort({ filters });\n } else {\n return null; // Web Worker\n }\n } catch (e) {\n switch (e.name) {\n case ('NotFoundError'):\n throw new PortSelectionCancelled();\n case ('InvalidStateError'):\n throw new PortUnavailable();\n case ('SecurityError'): // No user gesture\n return null;\n default:\n throw e;\n }\n }\n}\n\nclass KnownPorts {\n used = new Set();\n unused = [];\n\n async getOrFetchUnused() {\n let port = this.unused.pop();\n \n if (!port) {\n const systemPorts = await navigator.serial.getPorts({ filters });\n this.#enqueueUnique(systemPorts);\n port = this.unused.pop();\n }\n\n if (!port) {\n const manualPort = await requestPort();\n this.#enqueueUnique([manualPort]);\n port = this.unused.pop();\n }\n\n if (port) {\n this.used.add(port);\n }\n \n return port;\n }\n\n #enqueueUnique(ports) {\n if (ports) {\n for (const port of ports) {\n if (port && !this.used.has(port) && !this.unused.includes(port)) {\n this.unused.push(port);\n }\n }\n }\n }\n}\n\nconst knownPorts = new KnownPorts();\n\n/**\n * Adds user-selected port to permitted ports. Only for use outside of Web \n * Worker to establish permission for use within Web Worker.\n * @returns {null}\n */\nexport async function requestPortForWorker() {\n const _ = await requestPort();\n}\n\n/**\n * Never returns the same port twice. \n * @returns {(SerialPort|null)}\n */\nexport async function getUnusedPort() {\n return await knownPorts.getOrFetchUnused();\n}\n\n/**\n * Close port without throwing if already closed.\n * @param {SerialPort} port \n */\nexport async function close(port) {\n try {\n await port.close();\n } catch(e) {\n if (e.name != 'InvalidStateError') {\n if (e.message.includes('The port is already closed')) {\n throw e;\n }\n }\n }\n}\n","export class PortMutex {\n constructor(portOperations) {\n this.#lockName = `port-mutex-${Math.random().toString()}`;\n this.#deduper = new Map();\n this.#portOps = portOperations;\n }\n\n async acquire(fn) {\n const trace = new Error('created bad cb').stack;\n\n await this.#enqueue(async () => {\n try {\n await fn(this.#portOps);\n } catch (e) {\n console.error('Error occured in anonymous callback.');\n console.error('Original error:', e);\n console.error('--- This callback was created at ---\\n', trace);\n }\n });\n }\n\n async acquireIdempotent(key, fn) {\n const trace = new Error('created bad cb').stack;\n\n if (this.#deduper.has(key)) {\n console.info(`\"${key}\" request coalesced.`);\n }\n\n this.#deduper.set(key, async () => {\n try {\n await fn(this.#portOps);\n } catch (e) {\n console.error('Error occured in anonymous callback.');\n console.error('Original error:', e);\n console.error('--- This callback was created at ---\\n', trace);\n }\n });\n\n await this.#enqueue(() => this.#execDedupedOp(key));\n }\n\n async #enqueue(fn) {\n // `navigator.locks` maintains queue and provides mutual exclusion.\n return navigator.locks.request(this.#lockName, fn);\n }\n\n async #execDedupedOp(key) {\n if (this.#deduper.has(key)) {\n const fn = this.#deduper.get(key);\n this.#deduper.delete(key);\n await fn();\n }\n }\n\n #lockName;\n #deduper;\n #portOps;\n}\n","export class PortOperations {\n constructor(port) {\n this.#port = port;\n }\n\n async rx(length, timeout=3000) {\n if (this.#port === null) {\n throw new Error('attempted RX before port initialization.');\n }\n\n /*\n * ReadableStream's built-in locking mechanism cannot be awaited or otherwise\n * asynchronously acquired. A PortMutex must be used.\n */\n if (this.#port.readable.locked) {\n throw new Error('attempted RX while port locked.');\n }\n\n const response = [];\n const reader = this.#port.readable.getReader();\n const timeoutHandle = setTimeout(() => reader.cancel(), timeout);\n\n try {\n // Response may be divided across multiple reads\n while (response.length < length) {\n const { value, done } = await reader.read();\n response.push(...(value ?? []));\n if (done || !value) break;\n }\n } finally {\n clearTimeout(timeoutHandle);\n reader.releaseLock();\n }\n\n return response;\n }\n\n async tx(buffer) {\n if (this.#port === null) {\n throw new Error('attempted TX before port initialization.');\n }\n \n /*\n * WritableStream's built-in locking mechanism cannot be awaited or otherwise\n * asynchronously acquired. A PortMutex must be used.\n */\n if (this.#port.writable.locked) {\n throw new Error('attempted TX while port locked.');\n }\n\n const writer = this.#port.writable.getWriter();\n\n try {\n await writer.write(new Uint8Array(buffer));\n } finally {\n /* \n * The writer must be completely torn down between every single write.\n * Many parsers can't handle delayed flushing and write coalescing.\n * Command sequences will fail if `releaseLock()` is used here.\n */\n await writer.close();\n }\n }\n\n #port;\n}\n","// All replies to all commands are 32 bytes\nexport const RX_PACKET_SZ = 32;\n\nexport const Command = Object.freeze({\n ANIMATE: 0x04,\n BRIGHTNESS: 0x00,\n BOOTLOADER: 0x02,\n DRAW: 0x06,\n DRAW_GREY_COL_BUFFER: 0x08,\n GAME_CTRL: 0x11,\n GAME_STATUS: 0x12,\n PANIC: 0x05,\n PATTERN: 0x01,\n SLEEP: 0x03,\n STAGE_GREY_COL: 0x07,\n START_GAME: 0x10,\n VERSION: 0x20,\n});\n\n// Used with Command.PATTERN\nexport const Pattern = Object.freeze({\n DISPLAY_LOTUS_HORIZONTAL: 0x03,\n DISPLAY_LOTUS_VERTICAL: 0x07,\n DISPLAY_PANIC: 0x06,\n DOUBLE_GRADIENT: 0x02,\n FULL_BRIGHTNESS: 0x05,\n GRADIENT: 0x01,\n PERCENTAGE: 0x00,\n ZIG_ZAG: 0x04,\n});\n\n// DRAW or DRAW_GREY_COL_BUFFER\nexport const BitDepth = Object.freeze({\n GRAY_8BIT: '8-bit',\n MONO_1BIT: '1-bit',\n})\n","import { GAMMA, HEIGHT, VID_ARR, WIDTH } from '../../../hardware-constants.js';\nimport { Command, RX_PACKET_SZ } from './commands.js';\n\nexport class CommandAbstractionLayer {\n constructor(portMutex = null) {\n this.portMutex = portMutex;\n }\n\n async bootloader() {\n await this.portMutex.acquire(async p => {\n await p.tx([...VID_ARR, Command.BOOTLOADER]);\n });\n }\n\n async brightness(brightness) {\n await this.portMutex.acquire(async p => {\n await p.tx([...VID_ARR, Command.BRIGHTNESS, brightness]);\n });\n }\n\n async draw(matrix) {\n let index = 0;\n let output = new Uint8Array(39).fill(0);\n\n // Pack cells into bits\n for (let r = 0; r < HEIGHT; r++) {\n for (let c = 0; c < WIDTH; c++) {\n if (matrix[r][c]) {\n output[index >> 3] |= 1 << index % 8;\n }\n index++;\n }\n }\n\n await this.portMutex.acquireIdempotent(\n 'drawMatrix', \n async p => {\n await p.tx([...VID_ARR, Command.DRAW, ...output]);\n }\n );\n }\n\n async drawGrayscale(matrix) {\n // Transpose & Gamma Correction\n const buffers = Array.from(\n { length: WIDTH }, \n (_, c) => Array.from(\n { length: HEIGHT }, \n (_, r) => GAMMA[Math.floor((matrix[r][c] ?? 0) * 255)]\n )\n );\n\n // Only execute the most recent call \n await this.portMutex.acquireIdempotent(\n 'drawMatrix', \n async p => {\n for (let i = 0; i < WIDTH; i++) {\n await p.tx([...VID_ARR, Command.STAGE_GREY_COL, i, ...buffers[i]]);\n }\n await p.tx([...VID_ARR, Command.DRAW_GREY_COL_BUFFER]);\n }\n );\n }\n\n async asleep() {\n let asleep = false;\n\n await this.portMutex.acquire(async p => {\n await p.tx([...VID_ARR, Command.SLEEP]);\n asleep = await p.rx(RX_PACKET_SZ);\n asleep = asleep[0] != 0x00;\n });\n\n return asleep;\n }\n\n async sleep() {\n await this.portMutex.acquire(async p => {\n await p.tx([...VID_ARR, Command.SLEEP, 0x01]);\n });\n }\n\n async wake() {\n await this.portMutex.acquire(async p => {\n await p.tx([...VID_ARR, Command.SLEEP]);\n });\n }\n\n async pattern(pattern) {\n await this.portMutex.acquireIdempotent(\n 'drawMatrix',\n async p => {\n await p.tx([...VID_ARR, Command.PATTERN, pattern]);\n }\n );\n }\n\n async percent(percent) {\n await this.portMutex.acquireIdempotent(\n 'drawMatrix',\n async p => {\n await p.tx([...VID_ARR, Command.PATTERN, Pattern.PERCENTAGE, percent]);\n }\n );\n }\n\n async version() {\n let ver = {};\n\n await this.portMutex.acquire(async p => {\n await p.tx([...VID_ARR, Command.VERSION]);\n const response = await p.rx(RX_PACKET_SZ);\n\n // MMMMMMMM mmmmPPPP 0000000p\n ver.major = response[0];\n ver.minor = response[1] >> 4;\n ver.patch = response[1] & 0x0F;\n ver.preRelease = response[2] == 1;\n });\n\n return ver;\n }\n}\n","import { close, getUnusedPort } from '../../../web-serial/port.js';\nimport { PortMutex } from '../../../web-serial/PortMutex.js';\nimport { PortOperations } from '../../../web-serial/PortOperations.js';\nimport { CommandAbstractionLayer } from './CommandAbstractionLayer.js';\nimport { BitDepth } from './commands.js';\n\nexport class DefaultController extends CommandAbstractionLayer {\n async bootloader() {\n return super.bootloader();\n }\n\n async connect() {\n const port = await getUnusedPort();\n\n if (port?.connected) {\n await close(port);\n await port.open({ baudRate: 115200 });\n this.portMutex = new PortMutex(new PortOperations(port));\n } else {\n throw new Error('No Port Found');\n }\n }\n\n async draw(matrix) {\n switch (this.bitDepth ?? BitDepth.MONO_1BIT) {\n\n case (BitDepth.GRAY_8BIT):\n super.drawGrayscale(matrix);\n break;\n\n case (BitDepth.MONO_1BIT):\n super.draw(matrix);\n break;\n\n default:\n console.error(`Unsupported bitdepth: ${this.bitDepth}`);\n }\n }\n\n async verifyFirmware() {\n try {\n const version = await super.version();\n\n return version\n && version.major != undefined\n && version.minor != undefined\n && version.patch != undefined\n && version.preRelease != undefined;\n \n } catch {\n return false;\n }\n }\n\n async version() {\n return super.version();\n }\n}\n","export const Command = Object.freeze({\n /* 000 */ NOOP: 0x00,\n /* 'd' */ ANIMATION_DIAMOND: 0x64,\n /* 'b' */ ANIMATION_FIRE: 0x62,\n /* 'f' */ ANIMATION_FIREPLACE: 0x66,\n /* 'g' */ ANIMATION_GEAR: 0x67,\n /* 'r' */ ANIMATION_RING: 0x72,\n /* 'a' */ ANIMATION_STARTUP: 0x61,\n /* 'A' */ ANIMATION_STARTUP_ONCE: 0x41,\n /* 'e' */ BOOTLOADER: 0x65,\n /* 'm' */ DRAW_PWM: 0x6D,\n /* 'M' */ DRAW_PWM_BLOCKING: 0x4D,\n /* 'n' */ DRAW_SCALE: 0x6E,\n /* 'N' */ DRAW_SCALE_BLOCKING: 0x4E,\n /* 'c' */ FLUSH_CMD_QUEUE: 0x63,\n /* 't' */ TEST_PATTERN: 0x74,\n /* 'w' */ SET_CONST_PWM: 0x77,\n /* 's' */ SET_CONST_SCALE: 0x73,\n /* 'p' */ SET_PX_PWM: 0x70,\n /* 'q' */ SET_PX_SCALE: 0x71,\n /* 127 */ IDENTITY_STRING: 0x7F,\n});\n\nexport const IDENTITY_STR_LEN = 25;\n\nexport const IDENTITY_STR_REGEX = /^Sig\\sFW\\sLED\\sMatrix\\sFW\\sV(\\d+)\\.(\\d+)$/;\n","import { GAMMA } from '../../../hardware-constants.js';\nimport { Command, IDENTITY_STR_LEN } from './commands.js';\n\nexport class CommandAbstractionLayer {\n constructor(portMutex = null) {\n this.portMutex = portMutex;\n }\n\n async bootloader() {\n await this.portMutex.acquire(async p => {\n await p.tx([Command.BOOTLOADER]);\n });\n }\n\n async identityString() {\n let ident = null;\n\n await this.portMutex.acquire(async p => {\n await p.tx([Command.IDENTITY_STRING]);\n ident = await p.rx(IDENTITY_STR_LEN);\n });\n\n return String.fromCharCode(...ident);\n }\n\n async setPixelPwm(r, c, brightness) {\n await this.portMutex.acquire(\n async p => {\n await p.tx([Command.SET_PX_PWM, c, r, brightness]);\n }\n );\n }\n\n async setGlobalPwm(brightness) {\n await this.portMutex.acquire(\n async p => {\n await p.tx([Command.SET_CONST_PWM, brightness]);\n }\n );\n }\n\n async setMatrixPwm(matrix) {\n // Only execute the most recent call \n await this.portMutex.acquireIdempotent(\n 'drawMatrix', \n async p => {\n await p.tx(\n [Command.DRAW_PWM].concat(\n matrix.flat().map(v => \n GAMMA[Math.floor((v ?? 0) * 255)]\n )\n )\n );\n }\n );\n }\n\n async setPixelAnalog(r, c, brightness) {\n await this.portMutex.acquire(\n async p => {\n await p.tx([Command.SET_PX_SCALE, c, r, brightness]);\n }\n );\n }\n\n async setGlobalAnalog(brightness) {\n await this.portMutex.acquire(\n async p => {\n await p.tx([Command.SET_CONST_SCALE, brightness]);\n }\n );\n }\n\n async setMatrixAnalog(matrix) {\n // Only execute the most recent call \n await this.portMutex.acquireIdempotent(\n 'drawMatrix', \n async p => {\n await p.tx(\n [Command.DRAW_SCALE].concat(\n matrix.flat().map(v => \n GAMMA[Math.floor((v ?? 0) * 255)]\n )\n )\n );\n }\n );\n }\n}\n","import { close, getUnusedPort } from '../../../web-serial/port.js';\nimport { PortMutex } from '../../../web-serial/PortMutex.js';\nimport { PortOperations } from '../../../web-serial/PortOperations.js';\nimport { CommandAbstractionLayer } from './CommandAbstractionLayer.js';\nimport { IDENTITY_STR_REGEX } from './commands.js';\n\nexport class SigrootController extends CommandAbstractionLayer {\n async bootloader() {\n await super.bootloader();\n }\n\n async connect() {\n const port = await getUnusedPort();\n\n if (port?.connected) {\n await close(port);\n await port.open({ baudRate: 115200 });\n this.portMutex = new PortMutex(new PortOperations(port));\n }\n }\n\n async draw(matrix) {\n if (!this.#scaleInitialized) {\n await super.setGlobalAnalog(0x20);\n this.#scaleInitialized = true;\n } else {\n throw new Error('No Port Found');\n }\n\n await super.setMatrixPwm(matrix);\n }\n\n async verifyFirmware() { \n return await this.version() != null;\n }\n\n async version() {\n const ident = await super.identityString();\n const match = ident.match(IDENTITY_STR_REGEX);\n\n if (match && match.length == 3) {\n return {\n major: match[1],\n minor: match[2]\n }\n } else {\n return null;\n }\n }\n\n #scaleInitialized;\n}\n","import { PID, VID } from '../hardware-constants.js';\n\nconst filters = [{ vendorId: VID, productId: PID }];\n\nexport class DeviceSelectionCancelled extends Error {\n constructor() {\n super('User cancelled device selection.');\n this.name = this.constructor.name;\n this.date = new Date();\n }\n}\n\nasync function requestDevice() {\n try {\n if (navigator.serial.requestPort) {\n return await navigator.serial.requestDevice({ filters });\n } else {\n return null; // Web Worker\n }\n } catch (e) {\n switch (e.name) {\n case ('NotFoundError'):\n throw new DeviceSelectionCancelled();\n case ('SecurityError'): // No user gesture\n return null;\n default:\n throw e;\n }\n }\n}\n\nclass KnownDevices {\n used = new Set();\n unused = [];\n\n async getOrFetchUnused() {\n let device = this.unused.pop();\n\n if (!device) {\n const systemDevices = await navigator.hid.getDevices({ filters });\n this.#enqueueUnique(systemDevices);\n device = this.unused.pop();\n }\n\n if (!device) {\n const manualDevices = await requestDevice();\n this.#enqueueUnique([manualDevices]);\n device = this.unused.pop();\n }\n\n if (device) {\n this.used.add(device);\n }\n\n return device;\n }\n\n #enqueueUnique(devices) {\n if (devices) {\n for (const dev of devices) {\n if (dev && !this.used.has(dev) && !this.unused.includes(dev)) {\n this.unused.push(dev);\n }\n }\n }\n }\n}\n\nconst knownDevices = new KnownDevices();\n\n/**\n * Adds user-selected device to permitted device. Only for use outside of Web \n * Worker to establish permission for use within Web Worker.\n * @returns {null}\n */\nexport async function reqestDeviceForWorker() {\n const _ = await requestDevice();\n}\n\n/**\n * Never returns the same device twice. \n * @returns {(HIDDevice|null)}\n */\nexport async function getUnusedDevice() {\n return await knownDevices.getOrFetchUnused();\n}\n","import { pad } from './util.js';\n\nexport class HIDOperations {\n constructor(device) {\n this.#device = device;\n }\n\n async send(report, data) {\n if (data.length < report.bytes) {\n data = pad(data, report.bytes);\n } else if (data.length > report.bytes) {\n throw new Error('Unable to send report: too many bytes');\n }\n\n const buffer = new Uint8Array(data).buffer;\n\n if (report.feature) {\n await this.#device.sendFeatureReport(report.id, buffer);\n } else {\n await this.#device.sendReport(report.id, buffer);\n }\n }\n\n async request(report) {\n let reply = [];\n\n if (report.feature) {\n reply = await this.#device.receiveFeatureReport(report.id);\n } else {\n /* \n * HID input reports are used for unprompted data.\n * See WebHID `HIDInputReportEvent`\n */\n throw new Error('Invalid operation');\n }\n\n if (reply.byteLength != report.bytes) {\n const exp = report.bytes;\n const act = reply.byteLength;\n console.error(`reply length=${act} (expected ${exp})`);\n }\n\n return reply;\n }\n\n #device;\n}\n","export function pad(arr, len, val=0x00) {\n return arr.concat(new Array(len - arr.length).fill(val));\n}\n","export const Reports = {\n GLITTER_DEVICE_INFO: {\n id: 0x01,\n bytes: 307,\n feature: true,\n },\n GLITTER_BASIC_CMD: {\n id: 0x02,\n bytes: 16,\n feature: true,\n },\n GLITTER_GRID_PWM_CNTL: {\n id: 0x03,\n bytes: 306,\n feature: true,\n },\n GLITTER_GRID_PWM_CNTL: {\n id: 0x04,\n bytes: 306,\n feature: true,\n }\n}\n\nexport const Commands = {\n GLITTER_CMD_REBOOT: 0x00,\n GLITTER_CMD_SLEEP: 0x01,\n GLITTER_CMD_WAKE_ON_COMMAND: 0x02,\n GLITTER_CMD_SET_SLEEP_TIMEOUT: 0x03,\n GLITTER_CMD_SET_GLOBAL_BRIGHTNESS: 0x04,\n GLITTER_CMD_DRAW_PIXEL: 0x05,\n GLITTER_CMD_DRAW_LINE: 0x06\n}\n\nexport const BootMode = {\n BOOTSEL: 0x00,\n NORMAL: 0x01,\n}\n","import { GAMMA } from '../../../hardware-constants.js';\nimport { Commands, Reports } from './reports.js';\n\nexport class ReportAbstractionLayer {\n constructor(device = null) {\n this.device = device;\n }\n\n async info() {\n const infoRaw = await this.device.request(Reports.GLITTER_DEVICE_INFO);\n\n return {\n sleep_pin: infoRaw.getUint8(1),\n dip1_pin: infoRaw.getUint8(2),\n intb_pin: infoRaw.getUint8(3),\n state_flags: infoRaw.getUint8(4),\n id_reg: infoRaw.getUint8(5),\n config_reg: infoRaw.getUint8(6),\n global_brightness: infoRaw.getUint8(7),\n display_width: infoRaw.getUint8(8),\n display_height: infoRaw.getUint8(9),\n timeout_ms: infoRaw.getUint32(10),\n version_major: infoRaw.getUint8(14),\n version_minor: infoRaw.getUint8(15),\n };\n }\n\n async wake() {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD,\n [Commands.GLITTER_CMD_SLEEP, false]\n );\n }\n\n async sleep() {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD,\n [Commands.GLITTER_CMD_SLEEP, true]\n );\n }\n\n async disableSleep() {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD, \n [Commands.GLITTER_CMD_SET_SLEEP_TIMEOUT, 0xff, 0xff, 0xff, 0xff]\n );\n }\n\n async disableDeepSleep() {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD, \n [Commands.GLITTER_CMD_WAKE_ON_COMMAND, 0x01]\n );\n }\n\n async disableSleepTimer() {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD, \n [Commands.GLITTER_CMD_SET_SLEEP_TIMEOUT, 0x00, 0x00, 0x00, 0x00]\n );\n }\n \n async enableDeepSleep() {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD, \n [Commands.GLITTER_CMD_WAKE_ON_COMMAND, 0x00]\n );\n }\n\n async enableSleepTimer(milliseconds) {\n const view = new DataView(new ArrayBuffer(4));\n const littleEndian = false;\n view.setInt32(0, milliseconds, littleEndian);\n await this.device.send(\n Reports.GLITTER_BASIC_CMD, \n [\n Commands.GLITTER_CMD_SET_SLEEP_TIMEOUT, \n view.getUint8(0), \n view.getUint8(1), \n view.getUint8(2), \n view.getUint8(3),\n ]\n );\n }\n\n async reboot(mode) {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD, \n [Commands.GLITTER_CMD_REBOOT, mode]\n );\n }\n\n async drawMatrix(matrix) {\n await this.device.send(\n Reports.GLITTER_GRID_PWM_CNTL,\n matrix.flat().map(v => GAMMA[Math.floor((v ?? 0) * 255)])\n );\n }\n\n async drawPixel(r, c, brightness) {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD,\n [Commands.GLITTER_CMD_DRAW_PIXEL, c, r, brightness]\n );\n }\n\n async drawLine({r1, c1}, {r2, c2}, brightness) {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD,\n [Commands.GLITTER_CMD_DRAW_PIXEL, r1, c1, r2, c2, brightness]\n );\n }\n\n device;\n}\n","import { HEIGHT, WIDTH } from '../../../hardware-constants.js';\nimport { getUnusedDevice } from '../../../web-hid/device.js';\nimport { HIDOperations } from '../../../web-hid/HIDOperations.js';\nimport { ReportAbstractionLayer } from './ReportAbstractionLayer.js';\nimport { BootMode } from './reports.js';\n\nexport class SparkleController extends ReportAbstractionLayer {\n async bootloader() {\n await super.reboot(BootMode.BOOTSEL);\n }\n\n async connect() {\n const device = await getUnusedDevice();\n\n if (device) {\n await device.open();\n this.device = new HIDOperations(device);\n } else {\n throw new Error('No Device Found');\n }\n }\n \n async draw(matrix) {\n await super.drawMatrix(matrix);\n }\n\n async verifyFirmware() {\n try {\n const info = await super.info();\n return (\n info.display_height == HEIGHT &&\n info.display_width == WIDTH\n );\n } catch {\n return false;\n }\n }\n\n async version() {\n const info = await super.info();\n\n if (info.version_major != undefined \n && info.version_minor != undefined\n && (info.version_major > 0 || info.version_minor > 0)) {\n return {\n major: info.version_major,\n minor: info.version_minor\n }\n } else {\n // Sparkle <=1.1.1: Glitter version unavailable \n return { major: 1, minor: 0 };\n }\n }\n}\n","import { DefaultController } from './supported-firmware/FrameworkComputer/inputmodule-rs/DefaultController.js';\nimport { SigrootController } from './supported-firmware/sigroot/FW_LED_Matrix_Firmware/SigrootController.js';\nimport { SparkleController } from './supported-firmware/vddCore/sparkle-fw16/SparkleController.js';\n\nexport class HardwareControllerFactory {\n static async detectSerial() {\n const c1 = new DefaultController();\n const c2 = new SigrootController();\n\n await c1.connect();\n if (await c1.verifyFirmware()) {\n return c1;\n }\n \n await c2.connect()\n if (await c2.verifyFirmware()) {\n return c2;\n } \n \n return null;\n }\n\n static async detectHID() {\n const c1 = new SparkleController();\n\n await c1.connect();\n if (await c1.verifyFirmware()) {\n return c1;\n } \n \n return null;\n }\n}\n"],"names":["WIDTH","HEIGHT","VID","VID_ARR","PID","PID_ARR","GAMMA","Object","freeze","filters","usbVendorId","usbProductId","PortSelectionCancelled","Error","constructor","super","this","name","date","Date","PortUnavailable","async","requestPort","navigator","serial","e","knownPorts","used","Set","unused","getOrFetchUnused","port","pop","systemPorts","getPorts","enqueueUnique","manualPort","add","ports","has","includes","push","requestPortForWorker","getUnusedPort","close","message","PortMutex","portOperations","lockName","Math","random","toString","deduper","Map","portOps","acquire","fn","trace","stack","enqueue","console","error","acquireIdempotent","key","info","set","execDedupedOp","locks","request","get","delete","PortOperations","rx","length","timeout","readable","locked","response","reader","getReader","timeoutHandle","setTimeout","cancel","value","done","read","clearTimeout","releaseLock","tx","buffer","writable","writer","getWriter","write","Uint8Array","Command","ANIMATE","BRIGHTNESS","BOOTLOADER","DRAW","DRAW_GREY_COL_BUFFER","GAME_CTRL","GAME_STATUS","PANIC","PATTERN","SLEEP","STAGE_GREY_COL","START_GAME","VERSION","BitDepth","GRAY_8BIT","MONO_1BIT","CommandAbstractionLayer$1","portMutex","bootloader","p","brightness","draw","matrix","index","output","fill","r","c","drawGrayscale","buffers","Array","from","_","floor","i","asleep","sleep","wake","pattern","percent","Pattern","PERCENTAGE","version","ver","major","minor","patch","preRelease","DefaultController","CommandAbstractionLayer","connect","connected","open","baudRate","bitDepth","verifyFirmware","undefined","NOOP","ANIMATION_DIAMOND","ANIMATION_FIRE","ANIMATION_FIREPLACE","ANIMATION_GEAR","ANIMATION_RING","ANIMATION_STARTUP","ANIMATION_STARTUP_ONCE","DRAW_PWM","DRAW_PWM_BLOCKING","DRAW_SCALE","DRAW_SCALE_BLOCKING","FLUSH_CMD_QUEUE","TEST_PATTERN","SET_CONST_PWM","SET_CONST_SCALE","SET_PX_PWM","SET_PX_SCALE","IDENTITY_STRING","IDENTITY_STR_REGEX","identityString","ident","String","fromCharCode","setPixelPwm","setGlobalPwm","setMatrixPwm","concat","flat","map","v","setPixelAnalog","setGlobalAnalog","setMatrixAnalog","SigrootController","scaleInitialized","match","vendorId","productId","DeviceSelectionCancelled","requestDevice","knownDevices","device","systemDevices","hid","getDevices","manualDevices","devices","dev","reqestDeviceForWorker","getUnusedDevice","HIDOperations","send","report","data","bytes","arr","len","val","pad","feature","sendFeatureReport","id","sendReport","reply","receiveFeatureReport","byteLength","exp","act","Reports","Commands","BootMode","ReportAbstractionLayer","infoRaw","sleep_pin","getUint8","dip1_pin","intb_pin","state_flags","id_reg","config_reg","global_brightness","display_width","display_height","timeout_ms","getUint32","version_major","version_minor","disableSleep","disableDeepSleep","disableSleepTimer","enableDeepSleep","enableSleepTimer","milliseconds","view","DataView","ArrayBuffer","setInt32","reboot","mode","drawMatrix","drawPixel","drawLine","r1","c1","r2","c2","SparkleController","HardwareControllerFactory","detectSerial","detectHID"],"mappings":"AAAY,MAACA,EAAQ,EACRC,EAAS,GACTC,EAAM,MACNC,EAAU,CAAC,GAAM,KACjBC,EAAM,GACNC,EAAU,CAAC,EAAM,IAGjBC,EAAQC,OAAOC,OAAO,CACjC,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,GAAI,GAAI,GAAI,GACxB,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAC5B,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAC5B,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAC5B,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAC5B,GAAI,GAAI,G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,eAIP,CAAEpG,MAAO,EAAGC,MAAO,EAE9B,EChDK,MAAMwH,EACX,yBAAaC,GACX,MAAML,EAAK,IAAIjH,EACTmH,EAAK,IAAIxE,EAGf,aADMsE,EAAG/G,gBACC+G,EAAG1G,iBACJ0G,SAGHE,EAAGjH,gBACCiH,EAAG5G,iBACJ4G,EAGF,KACT,CAEA,sBAAaI,GACX,MAAMN,EAAK,IAAIG,EAGf,aADMH,EAAG/G,gBACC+G,EAAG1G,iBACJ0G,EAGF,IACT"}
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).LedMatrixControllers={})}(this,function(t){"use strict";const e=12972,a=[50,172],r=Object.freeze([0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,5,5,5,5,6,6,6,6,6,7,7,7,7,8,8,8,9,9,9,10,10,10,11,11,11,12,12,12,13,13,14,14,14,15,15,16,16,17,17,17,18,18,19,19,20,20,21,22,22,23,23,24,24,25,26,26,27,27,28,29,29,30,31,32,32,33,34,34,35,36,37,38,38,39,40,41,42,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,66,67,68,69,70,71,73,74,75,76,78,79,80,82,83,84,86,87,88,90,91,93,94,96,97,99,100,102,103,105,106,108,110,111,113,115,116,118,120,121,123,125,127,128,130,132,134,136,138,140,141,143,145,147,149,151,153,155,157,159,161,164,166,168,170,172,174,177,179,181,183,186,188,190,193,195,197,200,202,205,207,210,212,215,217,220,222,225,228,230,233,236,238,241,244,247,249,252,255]),i=[],n=[{usbVendorId:e,usbProductId:32}];class s extends Error{constructor(){super("User cancelled port selection."),this.name=this.constructor.name,this.date=new Date}}class o extends Error{constructor(){super("Selected port already in use."),this.name=this.constructor.name,this.date=new Date}}async function c(){try{if(i&&i.length>0)return i.pop();if(i.push(...await navigator.serial.getPorts()),i&&i.length>0)return i.pop();if(i.push(...await navigator.serial.requestPort({filters:n})),i&&i.length>0)return i.pop()}catch(t){throw"NotFoundError"==t.name?new s:"InvalidStateError"==t.name?new o:t}}async function l(t){try{await t.close()}catch(t){if("InvalidStateError"!=t.name&&"Failed to execute 'close' on 'SerialPort': The port is already closed."!=t.message)throw t}}class d{constructor(t){this.#t=`port-mutex-${Math.random().toString()}`,this.#e=new Map,this.#a=t}async acquire(t){const e=new Error("created bad cb").stack;await this.#r(async()=>{try{await t(this.#a)}catch(t){console.error("Error occured in anonymous callback."),console.error("Original error:",t),console.error("--- This callback was created at ---\n",e)}})}async acquireIdempotent(t,e){const a=new Error("created bad cb").stack;this.#e.has(t)&&console.info(`"${t}" request coalesced.`),this.#e.set(t,async()=>{try{await e(this.#a)}catch(t){console.error("Error occured in anonymous callback."),console.error("Original error:",t),console.error("--- This callback was created at ---\n",a)}}),await this.#r(()=>this.#i(t))}async#r(t){return navigator.locks.request(this.#t,t)}async#i(t){if(this.#e.has(t)){const e=this.#e.get(t);this.#e.delete(t),await e()}}#t;#e;#a}class u{constructor(t){this.#n=t}async rx(t,e=3e3){if(null===this.#n)throw new Error("attempted RX before port initialization.");if(this.#n.readable.locked)throw new Error("attempted RX while port locked.");const a=[],r=this.#n.readable.getReader(),i=setTimeout(()=>r.cancel(),e);try{for(;a.length<t;){const{value:t,done:e}=await r.read();if(a.push(...t??[]),e||!t)break}}finally{clearTimeout(i),r.releaseLock()}return a}async tx(t){if(null===this.#n)throw new Error("attempted TX before port initialization.");if(this.#n.writable.locked)throw new Error("attempted TX while port locked.");const e=this.#n.writable.getWriter();try{await e.write(new Uint8Array(t))}finally{await e.close()}}#n}const w=Object.freeze({ANIMATE:4,BRIGHTNESS:0,BOOTLOADER:2,DRAW:6,DRAW_GREY_COL_BUFFER:8,GAME_CTRL:17,GAME_STATUS:18,PANIC:5,PATTERN:1,SLEEP:3,STAGE_GREY_COL:7,START_GAME:16,VERSION:32});let p=class{constructor(t=null){this.portMutex=t}async bootloader(){await this.portMutex.acquire(async t=>{await t.tx([...a,w.BOOTLOADER])})}async brightness(t){await this.portMutex.acquire(async e=>{await e.tx([...a,w.BRIGHTNESS,t])})}async draw(t){let e=0,r=new Uint8Array(39).fill(0);for(let a=0;a<34;a++)for(let i=0;i<9;i++)t[a][i]&&(r[e>>3]|=1<<e%8),e++;await this.portMutex.acquireIdempotent("drawMatrix",async t=>{await t.tx([...a,w.DRAW,...r])})}async drawGrayscale(t){const e=Array.from({length:9},(e,a)=>new Array({length:34},(e,r)=>GAMMA[Math.floor(255*(t[r][a]??0))]));await this.portMutex.acquireIdempotent("drawMatrix",async t=>{for(let r=0;r<9;r++)await t.tx([...a,w.STAGE_GREY_COL,r,...e[r]]);await t.tx([...a,w.DRAW_GREY_COL_BUFFER])})}async asleep(){let t=!1;return await this.portMutex.acquire(async e=>{await e.tx([...a,w.SLEEP]),t=await e.rx(32),t=0!=t[0]}),t}async sleep(){await this.portMutex.acquire(async t=>{await t.tx([...a,w.SLEEP,1])})}async wake(){await this.portMutex.acquire(async t=>{await t.tx([...a,w.SLEEP])})}async pattern(t){await this.portMutex.acquireIdempotent("drawMatrix",async e=>{await e.tx([...a,w.PATTERN,t])})}async percent(t){await this.portMutex.acquireIdempotent("drawMatrix",async e=>{await e.tx([...a,w.PATTERN,Pattern.PERCENTAGE,t])})}async version(){let t={};return await this.portMutex.acquire(async e=>{await e.tx([...a,w.VERSION]);const r=await e.rx(32);t.major=r[0],t.minor=r[1]>>4,t.patch=15&r[1],t.preRelease=1==r[2]}),t}};class h extends p{async bootloader(){return super.bootloader()}async connect(){const t=await c();t?.connected&&(await l(t),await t.open({baudRate:115200}),this.portMutex=new d(new u(t)))}async draw(t){switch(this.#s){case BitDepth.GRAY_8BIT:super.drawGrayscale(t);break;case BitDepth.MONO_1BIT:super.draw(t)}}async verifyFirmware(){try{const t=await super.version();return t&&null!=t.major&&null!=t.minor&&null!=t.patch&&null!=t.preRelease}catch{return!1}}async version(){return super.version()}#s}const y=Object.freeze({NOOP:0,ANIMATION_DIAMOND:100,ANIMATION_FIRE:98,ANIMATION_FIREPLACE:102,ANIMATION_GEAR:103,ANIMATION_RING:114,ANIMATION_STARTUP:97,ANIMATION_STARTUP_ONCE:65,BOOTLOADER:101,DRAW_PWM:109,DRAW_PWM_BLOCKING:77,DRAW_SCALE:110,DRAW_SCALE_BLOCKING:78,FLUSH_CMD_QUEUE:99,TEST_PATTERN:116,SET_CONST_PWM:119,SET_CONST_SCALE:115,SET_PX_PWM:112,SET_PX_SCALE:113,IDENTITY_STRING:127}),f=/^Sig\sFW\sLED\sMatrix\sFW\sV(\d+)\.(\d+)$/;class E{constructor(t=null){this.portMutex=t}async bootloader(){await this.portMutex.acquire(async t=>{await t.tx([y.BOOTLOADER])})}async identityString(){let t=null;return await this.portMutex.acquire(async e=>{await e.tx([y.IDENTITY_STRING]),t=await e.rx(25)}),String.fromCharCode(...t)}async setPixelPwm(t,e,a){await this.portMutex.acquire(async r=>{await r.tx([y.SET_PX_PWM,e,t,a])})}async setGlobalPwm(t){await this.portMutex.acquire(async e=>{await e.tx([y.SET_CONST_PWM,t])})}async setMatrixPwm(t){await this.portMutex.acquireIdempotent("drawMatrix",async e=>{await e.tx([y.DRAW_PWM].concat(t.flat().map(t=>r[Math.floor(255*(t??0))])))})}async setPixelAnalog(t,e,a){await this.portMutex.acquire(async r=>{await r.tx([y.SET_PX_SCALE,e,t,a])})}async setGlobalAnalog(t){await this.portMutex.acquire(async e=>{await e.tx([y.SET_CONST_SCALE,t])})}async setMatrixAnalog(t){await this.portMutex.acquireIdempotent("drawMatrix",async e=>{await e.tx([y.DRAW_SCALE].concat(t.flat().map(t=>r[Math.floor(255*(t??0))])))})}}class x extends E{async bootloader(){await super.bootloader()}async connect(){const t=await c();t?.connected&&(await l(t),await t.open({baudRate:115200}),this.portMutex=new d(new u(t)))}async draw(t){this.#o||(await super.setGlobalAnalog(32),this.#o=!0),await super.setMatrixPwm(t)}async verifyFirmware(){return null!=await this.version()}async version(){const t=(await super.identityString()).match(f);return t&&3==t.length?{major:t[1],minor:t[2]}:null}#o}const _=[],A=[{vendorId:e,productId:32}];class m extends Error{constructor(){super("User cancelled device selection."),this.name=this.constructor.name,this.date=new Date}}class T{constructor(t){this.#c=t}async send(t,e){if(e.length<t.bytes)e=function(t,e,a=0){return t.concat(new Array(e-t.length).fill(a))}(e,t.bytes);else if(e.length>t.bytes)throw new Error("Unable to send report: too many bytes");const a=new Uint8Array(e).buffer;t.feature?await this.#c.sendFeatureReport(t.id,a):await this.#c.sendReport(t.id,a)}async request(t){let e=[];if(!t.feature)throw new Error("Invalid operation");if(e=await this.#c.receiveFeatureReport(t.id),e.byteLength!=t.bytes){const a=t.bytes,r=e.byteLength;console.error(`reply length=${r} (expected ${a})`)}return e}#c}const g={id:1,bytes:307,feature:!0},M={id:2,bytes:16,feature:!0},b={id:4,bytes:306,feature:!0},I=0,S=1,v=2,R=3,O=5,N=0;class D{constructor(t=null){this.device=t}async info(){const t=await this.device.request(g);return{sleep_pin:t.getUint8(1),dip1_pin:t.getUint8(2),intb_pin:t.getUint8(3),state_flags:t.getUint8(4),id_reg:t.getUint8(5),config_reg:t.getUint8(6),global_brightness:t.getUint8(7),display_width:t.getUint8(8),display_height:t.getUint8(9),timeout_ms:t.getUint32(10),version_major:t.getUint8(14),version_minor:t.getUint8(15)}}async wake(){await this.device.send(M,[S,!1])}async sleep(){await this.device.send(M,[S,!0])}async disableSleep(){await this.device.send(M,[R,255,255,255,255])}async disableDeepSleep(){await this.device.send(M,[v,1])}async disableSleepTimer(){await this.device.send(M,[R,0,0,0,0])}async enableDeepSleep(){await this.device.send(M,[v,0])}async enableSleepTimer(t){const e=new DataView(new ArrayBuffer(4));e.setInt32(0,t,!1),await this.device.send(M,[R,e.getUint8(0),e.getUint8(1),e.getUint8(2),e.getUint8(3)])}async reboot(t){await this.device.send(M,[I,t])}async drawMatrix(t){await this.device.send(b,t.flat().map(t=>r[Math.floor(255*(t??0))]))}async drawPixel(t,e,a){await this.device.send(M,[O,e,t,a])}async drawLine({r1:t,c1:e},{r2:a,c2:r},i){await this.device.send(M,[O,t,e,a,r,i])}device}class P extends D{async bootloader(){await super.reboot(N)}async connect(){const t=await async function(){if(_&&_.length>0)return _.pop();if(_.push(...await navigator.hid.getDevices()),_&&_.length>0)return _.pop();if(_.push(...await navigator.hid.requestDevice({filters:A})),_&&_.length>0)return _.pop();throw new m}();t&&(await t.open(),this.device=new T(t))}async draw(t){await super.drawMatrix(t)}async verifyFirmware(){try{const t=await super.info();return 34==t.display_height&&9==t.display_width}catch{return!1}}async version(){const t=await super.info();return null!=t.version_major&&null!=t.version_minor&&(t.version_major>0||t.version_minor>0)?{major:t.version_major,minor:t.version_minor}:{major:1,minor:0}}}t.DefaultController=h,t.GAMMA=r,t.HEIGHT=34,t.HardwareControllerFactory=class{static async detectSerial(){const t=new h,e=new x;return await t.connect(),await t.verifyFirmware()?t:(await e.connect(),await e.verifyFirmware()?e:null)}static async detectHID(){const t=new P;return await t.connect(),await t.verifyFirmware()?t:null}},t.PID=32,t.PID_ARR=[0,32],t.SigrootController=x,t.SparkleController=P,t.VID=e,t.VID_ARR=a,t.WIDTH=9});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).LedMatrixControllers={})}(this,function(e){"use strict";const t=12972,a=[50,172],r=Object.freeze([0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,5,5,5,5,6,6,6,6,6,7,7,7,7,8,8,8,9,9,9,10,10,10,11,11,11,12,12,12,13,13,14,14,14,15,15,16,16,17,17,17,18,18,19,19,20,20,21,22,22,23,23,24,24,25,26,26,27,27,28,29,29,30,31,32,32,33,34,34,35,36,37,38,38,39,40,41,42,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,66,67,68,69,70,71,73,74,75,76,78,79,80,82,83,84,86,87,88,90,91,93,94,96,97,99,100,102,103,105,106,108,110,111,113,115,116,118,120,121,123,125,127,128,130,132,134,136,138,140,141,143,145,147,149,151,153,155,157,159,161,164,166,168,170,172,174,177,179,181,183,186,188,190,193,195,197,200,202,205,207,210,212,215,217,220,222,225,228,230,233,236,238,241,244,247,249,252,255]),n=[{usbVendorId:t,usbProductId:32}];class i extends Error{constructor(){super("User cancelled port selection."),this.name=this.constructor.name,this.date=new Date}}class s extends Error{constructor(){super("Selected port already in use."),this.name=this.constructor.name,this.date=new Date}}async function o(){try{return navigator.serial.requestPort?await navigator.serial.requestPort({filters:n}):null}catch(e){switch(e.name){case"NotFoundError":throw new i;case"InvalidStateError":throw new s;case"SecurityError":return null;default:throw e}}}const c=new class{used=new Set;unused=[];async getOrFetchUnused(){let e=this.unused.pop();if(!e){const t=await navigator.serial.getPorts({filters:n});this.#e(t),e=this.unused.pop()}if(!e){const t=await o();this.#e([t]),e=this.unused.pop()}return e&&this.used.add(e),e}#e(e){if(e)for(const t of e)!t||this.used.has(t)||this.unused.includes(t)||this.unused.push(t)}};async function u(){return await c.getOrFetchUnused()}async function l(e){try{await e.close()}catch(e){if("InvalidStateError"!=e.name&&e.message.includes("The port is already closed"))throw e}}class d{constructor(e){this.#t=`port-mutex-${Math.random().toString()}`,this.#a=new Map,this.#r=e}async acquire(e){const t=new Error("created bad cb").stack;await this.#n(async()=>{try{await e(this.#r)}catch(e){console.error("Error occured in anonymous callback."),console.error("Original error:",e),console.error("--- This callback was created at ---\n",t)}})}async acquireIdempotent(e,t){const a=new Error("created bad cb").stack;this.#a.has(e)&&console.info(`"${e}" request coalesced.`),this.#a.set(e,async()=>{try{await t(this.#r)}catch(e){console.error("Error occured in anonymous callback."),console.error("Original error:",e),console.error("--- This callback was created at ---\n",a)}}),await this.#n(()=>this.#i(e))}async#n(e){return navigator.locks.request(this.#t,e)}async#i(e){if(this.#a.has(e)){const t=this.#a.get(e);this.#a.delete(e),await t()}}#t;#a;#r}class w{constructor(e){this.#s=e}async rx(e,t=3e3){if(null===this.#s)throw new Error("attempted RX before port initialization.");if(this.#s.readable.locked)throw new Error("attempted RX while port locked.");const a=[],r=this.#s.readable.getReader(),n=setTimeout(()=>r.cancel(),t);try{for(;a.length<e;){const{value:e,done:t}=await r.read();if(a.push(...e??[]),t||!e)break}}finally{clearTimeout(n),r.releaseLock()}return a}async tx(e){if(null===this.#s)throw new Error("attempted TX before port initialization.");if(this.#s.writable.locked)throw new Error("attempted TX while port locked.");const t=this.#s.writable.getWriter();try{await t.write(new Uint8Array(e))}finally{await t.close()}}#s}const h=Object.freeze({ANIMATE:4,BRIGHTNESS:0,BOOTLOADER:2,DRAW:6,DRAW_GREY_COL_BUFFER:8,GAME_CTRL:17,GAME_STATUS:18,PANIC:5,PATTERN:1,SLEEP:3,STAGE_GREY_COL:7,START_GAME:16,VERSION:32}),p=Object.freeze({GRAY_8BIT:"8-bit",MONO_1BIT:"1-bit"});let y=class{constructor(e=null){this.portMutex=e}async bootloader(){await this.portMutex.acquire(async e=>{await e.tx([...a,h.BOOTLOADER])})}async brightness(e){await this.portMutex.acquire(async t=>{await t.tx([...a,h.BRIGHTNESS,e])})}async draw(e){let t=0,r=new Uint8Array(39).fill(0);for(let a=0;a<34;a++)for(let n=0;n<9;n++)e[a][n]&&(r[t>>3]|=1<<t%8),t++;await this.portMutex.acquireIdempotent("drawMatrix",async e=>{await e.tx([...a,h.DRAW,...r])})}async drawGrayscale(e){const t=Array.from({length:9},(t,a)=>Array.from({length:34},(t,n)=>r[Math.floor(255*(e[n][a]??0))]));await this.portMutex.acquireIdempotent("drawMatrix",async e=>{for(let r=0;r<9;r++)await e.tx([...a,h.STAGE_GREY_COL,r,...t[r]]);await e.tx([...a,h.DRAW_GREY_COL_BUFFER])})}async asleep(){let e=!1;return await this.portMutex.acquire(async t=>{await t.tx([...a,h.SLEEP]),e=await t.rx(32),e=0!=e[0]}),e}async sleep(){await this.portMutex.acquire(async e=>{await e.tx([...a,h.SLEEP,1])})}async wake(){await this.portMutex.acquire(async e=>{await e.tx([...a,h.SLEEP])})}async pattern(e){await this.portMutex.acquireIdempotent("drawMatrix",async t=>{await t.tx([...a,h.PATTERN,e])})}async percent(e){await this.portMutex.acquireIdempotent("drawMatrix",async t=>{await t.tx([...a,h.PATTERN,Pattern.PERCENTAGE,e])})}async version(){let e={};return await this.portMutex.acquire(async t=>{await t.tx([...a,h.VERSION]);const r=await t.rx(32);e.major=r[0],e.minor=r[1]>>4,e.patch=15&r[1],e.preRelease=1==r[2]}),e}};class f extends y{async bootloader(){return super.bootloader()}async connect(){const e=await u();if(!e?.connected)throw new Error("No Port Found");await l(e),await e.open({baudRate:115200}),this.portMutex=new d(new w(e))}async draw(e){switch(this.bitDepth??p.MONO_1BIT){case p.GRAY_8BIT:super.drawGrayscale(e);break;case p.MONO_1BIT:super.draw(e);break;default:console.error(`Unsupported bitdepth: ${this.bitDepth}`)}}async verifyFirmware(){try{const e=await super.version();return e&&null!=e.major&&null!=e.minor&&null!=e.patch&&null!=e.preRelease}catch{return!1}}async version(){return super.version()}}const E=Object.freeze({NOOP:0,ANIMATION_DIAMOND:100,ANIMATION_FIRE:98,ANIMATION_FIREPLACE:102,ANIMATION_GEAR:103,ANIMATION_RING:114,ANIMATION_STARTUP:97,ANIMATION_STARTUP_ONCE:65,BOOTLOADER:101,DRAW_PWM:109,DRAW_PWM_BLOCKING:77,DRAW_SCALE:110,DRAW_SCALE_BLOCKING:78,FLUSH_CMD_QUEUE:99,TEST_PATTERN:116,SET_CONST_PWM:119,SET_CONST_SCALE:115,SET_PX_PWM:112,SET_PX_SCALE:113,IDENTITY_STRING:127}),_=/^Sig\sFW\sLED\sMatrix\sFW\sV(\d+)\.(\d+)$/;class x{constructor(e=null){this.portMutex=e}async bootloader(){await this.portMutex.acquire(async e=>{await e.tx([E.BOOTLOADER])})}async identityString(){let e=null;return await this.portMutex.acquire(async t=>{await t.tx([E.IDENTITY_STRING]),e=await t.rx(25)}),String.fromCharCode(...e)}async setPixelPwm(e,t,a){await this.portMutex.acquire(async r=>{await r.tx([E.SET_PX_PWM,t,e,a])})}async setGlobalPwm(e){await this.portMutex.acquire(async t=>{await t.tx([E.SET_CONST_PWM,e])})}async setMatrixPwm(e){await this.portMutex.acquireIdempotent("drawMatrix",async t=>{await t.tx([E.DRAW_PWM].concat(e.flat().map(e=>r[Math.floor(255*(e??0))])))})}async setPixelAnalog(e,t,a){await this.portMutex.acquire(async r=>{await r.tx([E.SET_PX_SCALE,t,e,a])})}async setGlobalAnalog(e){await this.portMutex.acquire(async t=>{await t.tx([E.SET_CONST_SCALE,e])})}async setMatrixAnalog(e){await this.portMutex.acquireIdempotent("drawMatrix",async t=>{await t.tx([E.DRAW_SCALE].concat(e.flat().map(e=>r[Math.floor(255*(e??0))])))})}}class m extends x{async bootloader(){await super.bootloader()}async connect(){const e=await u();e?.connected&&(await l(e),await e.open({baudRate:115200}),this.portMutex=new d(new w(e)))}async draw(e){if(this.#o)throw new Error("No Port Found");await super.setGlobalAnalog(32),this.#o=!0,await super.setMatrixPwm(e)}async verifyFirmware(){return null!=await this.version()}async version(){const e=(await super.identityString()).match(_);return e&&3==e.length?{major:e[1],minor:e[2]}:null}#o}const A=[{vendorId:t,productId:32}];class T extends Error{constructor(){super("User cancelled device selection."),this.name=this.constructor.name,this.date=new Date}}async function b(){try{return navigator.serial.requestPort?await navigator.serial.requestDevice({filters:A}):null}catch(e){switch(e.name){case"NotFoundError":throw new T;case"SecurityError":return null;default:throw e}}}const g=new class{used=new Set;unused=[];async getOrFetchUnused(){let e=this.unused.pop();if(!e){const t=await navigator.hid.getDevices({filters:A});this.#e(t),e=this.unused.pop()}if(!e){const t=await b();this.#e([t]),e=this.unused.pop()}return e&&this.used.add(e),e}#e(e){if(e)for(const t of e)!t||this.used.has(t)||this.unused.includes(t)||this.unused.push(t)}};async function M(){return await g.getOrFetchUnused()}class v{constructor(e){this.#c=e}async send(e,t){if(t.length<e.bytes)t=function(e,t,a=0){return e.concat(new Array(t-e.length).fill(a))}(t,e.bytes);else if(t.length>e.bytes)throw new Error("Unable to send report: too many bytes");const a=new Uint8Array(t).buffer;e.feature?await this.#c.sendFeatureReport(e.id,a):await this.#c.sendReport(e.id,a)}async request(e){let t=[];if(!e.feature)throw new Error("Invalid operation");if(t=await this.#c.receiveFeatureReport(e.id),t.byteLength!=e.bytes){const a=e.bytes,r=t.byteLength;console.error(`reply length=${r} (expected ${a})`)}return t}#c}const I={id:1,bytes:307,feature:!0},S={id:2,bytes:16,feature:!0},O={id:4,bytes:306,feature:!0},R=0,N=1,P=2,q=3,U=5,D=0;class C{constructor(e=null){this.device=e}async info(){const e=await this.device.request(I);return{sleep_pin:e.getUint8(1),dip1_pin:e.getUint8(2),intb_pin:e.getUint8(3),state_flags:e.getUint8(4),id_reg:e.getUint8(5),config_reg:e.getUint8(6),global_brightness:e.getUint8(7),display_width:e.getUint8(8),display_height:e.getUint8(9),timeout_ms:e.getUint32(10),version_major:e.getUint8(14),version_minor:e.getUint8(15)}}async wake(){await this.device.send(S,[N,!1])}async sleep(){await this.device.send(S,[N,!0])}async disableSleep(){await this.device.send(S,[q,255,255,255,255])}async disableDeepSleep(){await this.device.send(S,[P,1])}async disableSleepTimer(){await this.device.send(S,[q,0,0,0,0])}async enableDeepSleep(){await this.device.send(S,[P,0])}async enableSleepTimer(e){const t=new DataView(new ArrayBuffer(4));t.setInt32(0,e,!1),await this.device.send(S,[q,t.getUint8(0),t.getUint8(1),t.getUint8(2),t.getUint8(3)])}async reboot(e){await this.device.send(S,[R,e])}async drawMatrix(e){await this.device.send(O,e.flat().map(e=>r[Math.floor(255*(e??0))]))}async drawPixel(e,t,a){await this.device.send(S,[U,t,e,a])}async drawLine({r1:e,c1:t},{r2:a,c2:r},n){await this.device.send(S,[U,e,t,a,r,n])}device}class L extends C{async bootloader(){await super.reboot(D)}async connect(){const e=await M();if(!e)throw new Error("No Device Found");await e.open(),this.device=new v(e)}async draw(e){await super.drawMatrix(e)}async verifyFirmware(){try{const e=await super.info();return 34==e.display_height&&9==e.display_width}catch{return!1}}async version(){const e=await super.info();return null!=e.version_major&&null!=e.version_minor&&(e.version_major>0||e.version_minor>0)?{major:e.version_major,minor:e.version_minor}:{major:1,minor:0}}}e.DefaultController=f,e.DeviceSelectionCancelled=T,e.GAMMA=r,e.HEIGHT=34,e.HardwareControllerFactory=class{static async detectSerial(){const e=new f,t=new m;return await e.connect(),await e.verifyFirmware()?e:(await t.connect(),await t.verifyFirmware()?t:null)}static async detectHID(){const e=new L;return await e.connect(),await e.verifyFirmware()?e:null}},e.PID=32,e.PID_ARR=[0,32],e.PortSelectionCancelled=i,e.PortUnavailable=s,e.SigrootController=m,e.SparkleController=L,e.VID=t,e.VID_ARR=a,e.WIDTH=9,e.close=l,e.getUnusedDevice=M,e.getUnusedPort=u,e.reqestDeviceForWorker=async function(){await b()},e.requestPortForWorker=async function(){await o()}});
2
2
  //# sourceMappingURL=led-matrix-controllers.umd.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"led-matrix-controllers.umd.min.js","sources":["../src/hardware-constants.js","../src/web-serial/port.js","../src/web-serial/PortMutex.js","../src/web-serial/PortOperations.js","../src/supported-firmware/FrameworkComputer/inputmodule-rs/commands.js","../src/supported-firmware/FrameworkComputer/inputmodule-rs/CommandAbstractionLayer.js","../src/supported-firmware/FrameworkComputer/inputmodule-rs/DefaultController.js","../src/supported-firmware/sigroot/FW_LED_Matrix_Firmware/commands.js","../src/supported-firmware/sigroot/FW_LED_Matrix_Firmware/CommandAbstractionLayer.js","../src/supported-firmware/sigroot/FW_LED_Matrix_Firmware/SigrootController.js","../src/web-hid/device.js","../src/web-hid/HIDOperations.js","../src/web-hid/util.js","../src/supported-firmware/vddCore/sparkle-fw16/reports.js","../src/supported-firmware/vddCore/sparkle-fw16/ReportAbstractionLayer.js","../src/supported-firmware/vddCore/sparkle-fw16/SparkleController.js","../src/HardwareControllerFactory.js"],"sourcesContent":["export const WIDTH = 9;\nexport const HEIGHT = 34;\nexport const VID = 0x32AC;\nexport const VID_ARR = [0x32, 0xAC];\nexport const PID = 0x0020;\nexport const PID_ARR = [0x00, 0x20];\n\nexport const GAMMA = Object.freeze([\n 0, 0, 0, 0, 0, 0, 0, 1, \n 1, 1, 1, 1, 1, 1, 1, 1, \n 1, 1, 1, 1, 1, 1, 1, 1, \n 1, 1, 1, 1, 1, 1, 1, 1, \n 1, 1, 1, 2, 2, 2, 2, 2, \n 2, 2, 2, 2, 3, 3, 3, 3, \n 3, 3, 3, 4, 4, 4, 4, 4, \n 4, 5, 5, 5, 5, 6, 6, 6, \n 6, 6, 7, 7, 7, 7, 8, 8, \n 8, 9, 9, 9, 10, 10, 10, 11, \n 11, 11, 12, 12, 12, 13, 13, 14, \n 14, 14, 15, 15, 16, 16, 17, 17, \n 17, 18, 18, 19, 19, 20, 20, 21, \n 22, 22, 23, 23, 24, 24, 25, 26, \n 26, 27, 27, 28, 29, 29, 30, 31, \n 32, 32, 33, 34, 34, 35, 36, 37, \n 38, 38, 39, 40, 41, 42, 42, 43, \n 44, 45, 46, 47, 48, 49, 50, 51, \n 52, 53, 54, 55, 56, 57, 58, 59, \n 60, 61, 62, 63, 64, 66, 67, 68, \n 69, 70, 71, 73, 74, 75, 76, 78, \n 79, 80, 82, 83, 84, 86, 87, 88, \n 90, 91, 93, 94, 96, 97, 99, 100, \n 102, 103, 105, 106, 108, 110, 111, 113, \n 115, 116, 118, 120, 121, 123, 125, 127, \n 128, 130, 132, 134, 136, 138, 140, 141, \n 143, 145, 147, 149, 151, 153, 155, 157, \n 159, 161, 164, 166, 168, 170, 172, 174, \n 177, 179, 181, 183, 186, 188, 190, 193, \n 195, 197, 200, 202, 205, 207, 210, 212, \n 215, 217, 220, 222, 225, 228, 230, 233, \n 236, 238, 241, 244, 247, 249, 252, 255\n]);\n","import { PID, VID } from '../hardware-constants.js';\n\nconst extraPorts = [];\n\nconst filters = [\n {\n usbVendorId: VID,\n usbProductId: PID,\n }\n];\n\nexport class PortSelectionCancelled extends Error {\n constructor() {\n super('User cancelled port selection.');\n this.name = this.constructor.name;\n this.date = new Date();\n }\n}\n\nexport class PortUnavailable extends Error {\n constructor() {\n super('Selected port already in use.');\n this.name = this.constructor.name;\n this.date = new Date();\n }\n}\n\nexport async function getPort() {\n try {\n if (extraPorts && extraPorts.length > 0) {\n return extraPorts.pop();\n }\n\n extraPorts.push(...(await navigator.serial.getPorts()));\n if (extraPorts && extraPorts.length > 0) {\n return extraPorts.pop();\n }\n\n extraPorts.push(...(await navigator.serial.requestPort({ filters })));\n if (extraPorts && extraPorts.length > 0) {\n return extraPorts.pop();\n }\n\n } catch (e) {\n if (e.name == 'NotFoundError') {\n throw new PortSelectionCancelled();\n } else if (e.name == 'InvalidStateError') {\n throw new PortUnavailable();\n } else {\n throw e;\n }\n }\n}\n\nexport async function close(port) {\n try {\n await port.close();\n } catch(e) {\n if (e.name != 'InvalidStateError') {\n if (e.message != \"Failed to execute 'close' on 'SerialPort': The port is already closed.\") {\n throw e;\n }\n }\n }\n}\n","export class PortMutex {\n constructor(portOperations) {\n this.#lockName = `port-mutex-${Math.random().toString()}`;\n this.#deduper = new Map();\n this.#portOps = portOperations;\n }\n\n async acquire(fn) {\n const trace = new Error('created bad cb').stack;\n\n await this.#enqueue(async () => {\n try {\n await fn(this.#portOps);\n } catch (e) {\n console.error('Error occured in anonymous callback.');\n console.error('Original error:', e);\n console.error('--- This callback was created at ---\\n', trace);\n }\n });\n }\n\n async acquireIdempotent(key, fn) {\n const trace = new Error('created bad cb').stack;\n\n if (this.#deduper.has(key)) {\n console.info(`\"${key}\" request coalesced.`);\n }\n\n this.#deduper.set(key, async () => {\n try {\n await fn(this.#portOps);\n } catch (e) {\n console.error('Error occured in anonymous callback.');\n console.error('Original error:', e);\n console.error('--- This callback was created at ---\\n', trace);\n }\n });\n\n await this.#enqueue(() => this.#execDedupedOp(key));\n }\n\n async #enqueue(fn) {\n // `navigator.locks` maintains queue and provides mutual exclusion.\n return navigator.locks.request(this.#lockName, fn);\n }\n\n async #execDedupedOp(key) {\n if (this.#deduper.has(key)) {\n const fn = this.#deduper.get(key);\n this.#deduper.delete(key);\n await fn();\n }\n }\n\n #lockName;\n #deduper;\n #portOps;\n}\n","export class PortOperations {\n constructor(port) {\n this.#port = port;\n }\n\n async rx(length, timeout=3000) {\n if (this.#port === null) {\n throw new Error('attempted RX before port initialization.');\n }\n\n /*\n * ReadableStream's built-in locking mechanism cannot be awaited or otherwise\n * asynchronously acquired. A PortMutex must be used.\n */\n if (this.#port.readable.locked) {\n throw new Error('attempted RX while port locked.');\n }\n\n const response = [];\n const reader = this.#port.readable.getReader();\n const timeoutHandle = setTimeout(() => reader.cancel(), timeout);\n\n try {\n // Response may be divided across multiple reads\n while (response.length < length) {\n const { value, done } = await reader.read();\n response.push(...(value ?? []));\n if (done || !value) break;\n }\n } finally {\n clearTimeout(timeoutHandle);\n reader.releaseLock();\n }\n\n return response;\n }\n\n async tx(buffer) {\n if (this.#port === null) {\n throw new Error('attempted TX before port initialization.');\n }\n \n /*\n * WritableStream's built-in locking mechanism cannot be awaited or otherwise\n * asynchronously acquired. A PortMutex must be used.\n */\n if (this.#port.writable.locked) {\n throw new Error('attempted TX while port locked.');\n }\n\n const writer = this.#port.writable.getWriter();\n\n try {\n await writer.write(new Uint8Array(buffer));\n } finally {\n /* \n * The writer must be completely torn down between every single write.\n * Many parsers can't handle delayed flushing and write coalescing.\n * Command sequences will fail if `releaseLock()` is used here.\n */\n await writer.close();\n }\n }\n\n #port;\n}\n","// All replies to all commands are 32 bytes\nexport const RX_PACKET_SZ = 32;\n\nexport const Command = Object.freeze({\n ANIMATE: 0x04,\n BRIGHTNESS: 0x00,\n BOOTLOADER: 0x02,\n DRAW: 0x06,\n DRAW_GREY_COL_BUFFER: 0x08,\n GAME_CTRL: 0x11,\n GAME_STATUS: 0x12,\n PANIC: 0x05,\n PATTERN: 0x01,\n SLEEP: 0x03,\n STAGE_GREY_COL: 0x07,\n START_GAME: 0x10,\n VERSION: 0x20,\n});\n\n// Used with Command.PATTERN\nexport const Pattern = Object.freeze({\n DISPLAY_LOTUS_HORIZONTAL: 0x03,\n DISPLAY_LOTUS_VERTICAL: 0x07,\n DISPLAY_PANIC: 0x06,\n DOUBLE_GRADIENT: 0x02,\n FULL_BRIGHTNESS: 0x05,\n GRADIENT: 0x01,\n PERCENTAGE: 0x00,\n ZIG_ZAG: 0x04,\n});\n\n// DRAW or DRAW_GREY_COL_BUFFER\nexport const BitDepth = Object.freeze({\n GRAY_8BIT: '8-bit',\n MONO_1BIT: '1-bit',\n})\n","import { HEIGHT, VID_ARR, WIDTH } from '../../../hardware-constants.js';\nimport { Command, RX_PACKET_SZ } from './commands.js';\n\nexport class CommandAbstractionLayer {\n constructor(portMutex = null) {\n this.portMutex = portMutex;\n }\n\n async bootloader() {\n await this.portMutex.acquire(async p => {\n await p.tx([...VID_ARR, Command.BOOTLOADER]);\n });\n }\n\n async brightness(brightness) {\n await this.portMutex.acquire(async p => {\n await p.tx([...VID_ARR, Command.BRIGHTNESS, brightness]);\n });\n }\n\n async draw(matrix) {\n let index = 0;\n let output = new Uint8Array(39).fill(0);\n\n // Pack cells into bits\n for (let r = 0; r < HEIGHT; r++) {\n for (let c = 0; c < WIDTH; c++) {\n if (matrix[r][c]) {\n output[index >> 3] |= 1 << index % 8;\n }\n index++;\n }\n }\n\n await this.portMutex.acquireIdempotent(\n 'drawMatrix', \n async p => {\n await p.tx([...VID_ARR, Command.DRAW, ...output]);\n }\n );\n }\n\n async drawGrayscale(matrix) {\n // Transpose & Gamma Correction\n const buffers = Array.from(\n { length: WIDTH }, \n (_, c) => new Array(\n { length: HEIGHT }, \n (_, r) => GAMMA[Math.floor((matrix[r][c] ?? 0) * 255)]\n )\n );\n\n // Only execute the most recent call \n await this.portMutex.acquireIdempotent(\n 'drawMatrix', \n async p => {\n for (let i = 0; i < WIDTH; i++) {\n await p.tx([...VID_ARR, Command.STAGE_GREY_COL, i, ...buffers[i]]);\n }\n await p.tx([...VID_ARR, Command.DRAW_GREY_COL_BUFFER]);\n }\n );\n }\n\n async asleep() {\n let asleep = false;\n\n await this.portMutex.acquire(async p => {\n await p.tx([...VID_ARR, Command.SLEEP]);\n asleep = await p.rx(RX_PACKET_SZ);\n asleep = asleep[0] != 0x00;\n });\n\n return asleep;\n }\n\n async sleep() {\n await this.portMutex.acquire(async p => {\n await p.tx([...VID_ARR, Command.SLEEP, 0x01]);\n });\n }\n\n async wake() {\n await this.portMutex.acquire(async p => {\n await p.tx([...VID_ARR, Command.SLEEP]);\n });\n }\n\n async pattern(pattern) {\n await this.portMutex.acquireIdempotent(\n 'drawMatrix',\n async p => {\n await p.tx([...VID_ARR, Command.PATTERN, pattern]);\n }\n );\n }\n\n async percent(percent) {\n await this.portMutex.acquireIdempotent(\n 'drawMatrix',\n async p => {\n await p.tx([...VID_ARR, Command.PATTERN, Pattern.PERCENTAGE, percent]);\n }\n );\n }\n\n async version() {\n let ver = {};\n\n await this.portMutex.acquire(async p => {\n await p.tx([...VID_ARR, Command.VERSION]);\n const response = await p.rx(RX_PACKET_SZ);\n\n // MMMMMMMM mmmmPPPP 0000000p\n ver.major = response[0];\n ver.minor = response[1] >> 4;\n ver.patch = response[1] & 0x0F;\n ver.preRelease = response[2] == 1;\n });\n\n return ver;\n }\n}\n","import { close, getPort } from '../../../web-serial/port.js';\nimport { PortMutex } from '../../../web-serial/PortMutex.js';\nimport { PortOperations } from '../../../web-serial/PortOperations.js';\nimport { CommandAbstractionLayer } from './CommandAbstractionLayer.js';\n\nexport class DefaultController extends CommandAbstractionLayer {\n async bootloader() {\n return super.bootloader();\n }\n\n async connect() {\n const port = await getPort();\n\n if (port?.connected) {\n await close(port);\n await port.open({ baudRate: 115200 });\n this.portMutex = new PortMutex(new PortOperations(port));\n }\n }\n\n async draw(matrix) {\n switch (this.#bitDepth) {\n\n case BitDepth.GRAY_8BIT:\n super.drawGrayscale(matrix);\n break;\n\n case BitDepth.MONO_1BIT:\n super.draw(matrix);\n break;\n }\n }\n\n async verifyFirmware() {\n try {\n const version = await super.version();\n\n return version\n && version.major != undefined\n && version.minor != undefined\n && version.patch != undefined\n && version.preRelease != undefined;\n \n } catch {\n return false;\n }\n }\n\n async version() {\n return super.version();\n }\n\n #bitDepth;\n}\n","export const Command = Object.freeze({\n /* 000 */ NOOP: 0x00,\n /* 'd' */ ANIMATION_DIAMOND: 0x64,\n /* 'b' */ ANIMATION_FIRE: 0x62,\n /* 'f' */ ANIMATION_FIREPLACE: 0x66,\n /* 'g' */ ANIMATION_GEAR: 0x67,\n /* 'r' */ ANIMATION_RING: 0x72,\n /* 'a' */ ANIMATION_STARTUP: 0x61,\n /* 'A' */ ANIMATION_STARTUP_ONCE: 0x41,\n /* 'e' */ BOOTLOADER: 0x65,\n /* 'm' */ DRAW_PWM: 0x6D,\n /* 'M' */ DRAW_PWM_BLOCKING: 0x4D,\n /* 'n' */ DRAW_SCALE: 0x6E,\n /* 'N' */ DRAW_SCALE_BLOCKING: 0x4E,\n /* 'c' */ FLUSH_CMD_QUEUE: 0x63,\n /* 't' */ TEST_PATTERN: 0x74,\n /* 'w' */ SET_CONST_PWM: 0x77,\n /* 's' */ SET_CONST_SCALE: 0x73,\n /* 'p' */ SET_PX_PWM: 0x70,\n /* 'q' */ SET_PX_SCALE: 0x71,\n /* 127 */ IDENTITY_STRING: 0x7F,\n});\n\nexport const IDENTITY_STR_LEN = 25;\n\nexport const IDENTITY_STR_REGEX = /^Sig\\sFW\\sLED\\sMatrix\\sFW\\sV(\\d+)\\.(\\d+)$/;\n","import { GAMMA } from '../../../hardware-constants.js';\nimport { Command, IDENTITY_STR_LEN } from './commands.js';\n\nexport class CommandAbstractionLayer {\n constructor(portMutex = null) {\n this.portMutex = portMutex;\n }\n\n async bootloader() {\n await this.portMutex.acquire(async p => {\n await p.tx([Command.BOOTLOADER]);\n });\n }\n\n async identityString() {\n let ident = null;\n\n await this.portMutex.acquire(async p => {\n await p.tx([Command.IDENTITY_STRING]);\n ident = await p.rx(IDENTITY_STR_LEN);\n });\n\n return String.fromCharCode(...ident);\n }\n\n async setPixelPwm(r, c, brightness) {\n await this.portMutex.acquire(\n async p => {\n await p.tx([Command.SET_PX_PWM, c, r, brightness]);\n }\n );\n }\n\n async setGlobalPwm(brightness) {\n await this.portMutex.acquire(\n async p => {\n await p.tx([Command.SET_CONST_PWM, brightness]);\n }\n );\n }\n\n async setMatrixPwm(matrix) {\n // Only execute the most recent call \n await this.portMutex.acquireIdempotent(\n 'drawMatrix', \n async p => {\n await p.tx(\n [Command.DRAW_PWM].concat(\n matrix.flat().map(v => \n GAMMA[Math.floor((v ?? 0) * 255)]\n )\n )\n );\n }\n );\n }\n\n async setPixelAnalog(r, c, brightness) {\n await this.portMutex.acquire(\n async p => {\n await p.tx([Command.SET_PX_SCALE, c, r, brightness]);\n }\n );\n }\n\n async setGlobalAnalog(brightness) {\n await this.portMutex.acquire(\n async p => {\n await p.tx([Command.SET_CONST_SCALE, brightness]);\n }\n );\n }\n\n async setMatrixAnalog(matrix) {\n // Only execute the most recent call \n await this.portMutex.acquireIdempotent(\n 'drawMatrix', \n async p => {\n await p.tx(\n [Command.DRAW_SCALE].concat(\n matrix.flat().map(v => \n GAMMA[Math.floor((v ?? 0) * 255)]\n )\n )\n );\n }\n );\n }\n}\n","import { close, getPort } from '../../../web-serial/port.js';\nimport { PortMutex } from '../../../web-serial/PortMutex.js';\nimport { PortOperations } from '../../../web-serial/PortOperations.js';\nimport { CommandAbstractionLayer } from './CommandAbstractionLayer.js';\nimport { IDENTITY_STR_REGEX } from './commands.js';\n\nexport class SigrootController extends CommandAbstractionLayer {\n async bootloader() {\n await super.bootloader();\n }\n\n async connect() {\n const port = await getPort();\n\n if (port?.connected) {\n await close(port);\n await port.open({ baudRate: 115200 });\n this.portMutex = new PortMutex(new PortOperations(port));\n }\n }\n\n async draw(matrix) {\n if (!this.#scaleInitialized) {\n await super.setGlobalAnalog(0x20);\n this.#scaleInitialized = true;\n }\n\n await super.setMatrixPwm(matrix);\n }\n\n async verifyFirmware() { \n return await this.version() != null;\n }\n\n async version() {\n const ident = await super.identityString();\n const match = ident.match(IDENTITY_STR_REGEX);\n\n if (match && match.length == 3) {\n return {\n major: match[1],\n minor: match[2]\n }\n } else {\n return null;\n }\n }\n\n #scaleInitialized;\n}\n","import { PID, VID } from '../hardware-constants.js';\n\nconst extraDevices = [];\n\nconst filters = [\n {\n vendorId: VID,\n productId: PID,\n }\n];\n\nexport class DeviceSelectionCancelled extends Error {\n constructor() {\n super('User cancelled device selection.');\n this.name = this.constructor.name;\n this.date = new Date();\n }\n}\n\nexport async function getDevice() {\n if (extraDevices && extraDevices.length > 0) {\n return extraDevices.pop();\n }\n\n extraDevices.push(...(await navigator.hid.getDevices()));\n if (extraDevices && extraDevices.length > 0) {\n return extraDevices.pop();\n }\n\n extraDevices.push(...(await navigator.hid.requestDevice({ filters })));\n if (extraDevices && extraDevices.length > 0) {\n return extraDevices.pop();\n }\n\n throw new DeviceSelectionCancelled();\n}\n","import { pad } from './util.js';\n\nexport class HIDOperations {\n constructor(device) {\n this.#device = device;\n }\n\n async send(report, data) {\n if (data.length < report.bytes) {\n data = pad(data, report.bytes);\n } else if (data.length > report.bytes) {\n throw new Error('Unable to send report: too many bytes');\n }\n\n const buffer = new Uint8Array(data).buffer;\n\n if (report.feature) {\n await this.#device.sendFeatureReport(report.id, buffer);\n } else {\n await this.#device.sendReport(report.id, buffer);\n }\n }\n\n async request(report) {\n let reply = [];\n\n if (report.feature) {\n reply = await this.#device.receiveFeatureReport(report.id);\n } else {\n /* \n * HID input reports are used for unprompted data.\n * See WebHID `HIDInputReportEvent`\n */\n throw new Error('Invalid operation');\n }\n\n if (reply.byteLength != report.bytes) {\n const exp = report.bytes;\n const act = reply.byteLength;\n console.error(`reply length=${act} (expected ${exp})`);\n }\n\n return reply;\n }\n\n #device;\n}\n","export function pad(arr, len, val=0x00) {\n return arr.concat(new Array(len - arr.length).fill(val));\n}\n","export const Reports = {\n GLITTER_DEVICE_INFO: {\n id: 0x01,\n bytes: 307,\n feature: true,\n },\n GLITTER_BASIC_CMD: {\n id: 0x02,\n bytes: 16,\n feature: true,\n },\n GLITTER_GRID_PWM_CNTL: {\n id: 0x03,\n bytes: 306,\n feature: true,\n },\n GLITTER_GRID_PWM_CNTL: {\n id: 0x04,\n bytes: 306,\n feature: true,\n }\n}\n\nexport const Commands = {\n GLITTER_CMD_REBOOT: 0x00,\n GLITTER_CMD_SLEEP: 0x01,\n GLITTER_CMD_WAKE_ON_COMMAND: 0x02,\n GLITTER_CMD_SET_SLEEP_TIMEOUT: 0x03,\n GLITTER_CMD_SET_GLOBAL_BRIGHTNESS: 0x04,\n GLITTER_CMD_DRAW_PIXEL: 0x05,\n GLITTER_CMD_DRAW_LINE: 0x06\n}\n\nexport const BootMode = {\n BOOTSEL: 0x00,\n NORMAL: 0x01,\n}\n","import { GAMMA } from '../../../hardware-constants.js';\nimport { Commands, Reports } from './reports.js';\n\nexport class ReportAbstractionLayer {\n constructor(device = null) {\n this.device = device;\n }\n\n async info() {\n const infoRaw = await this.device.request(Reports.GLITTER_DEVICE_INFO);\n\n return {\n sleep_pin: infoRaw.getUint8(1),\n dip1_pin: infoRaw.getUint8(2),\n intb_pin: infoRaw.getUint8(3),\n state_flags: infoRaw.getUint8(4),\n id_reg: infoRaw.getUint8(5),\n config_reg: infoRaw.getUint8(6),\n global_brightness: infoRaw.getUint8(7),\n display_width: infoRaw.getUint8(8),\n display_height: infoRaw.getUint8(9),\n timeout_ms: infoRaw.getUint32(10),\n version_major: infoRaw.getUint8(14),\n version_minor: infoRaw.getUint8(15),\n };\n }\n\n async wake() {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD,\n [Commands.GLITTER_CMD_SLEEP, false]\n );\n }\n\n async sleep() {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD,\n [Commands.GLITTER_CMD_SLEEP, true]\n );\n }\n\n async disableSleep() {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD, \n [Commands.GLITTER_CMD_SET_SLEEP_TIMEOUT, 0xff, 0xff, 0xff, 0xff]\n );\n }\n\n async disableDeepSleep() {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD, \n [Commands.GLITTER_CMD_WAKE_ON_COMMAND, 0x01]\n );\n }\n\n async disableSleepTimer() {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD, \n [Commands.GLITTER_CMD_SET_SLEEP_TIMEOUT, 0x00, 0x00, 0x00, 0x00]\n );\n }\n \n async enableDeepSleep() {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD, \n [Commands.GLITTER_CMD_WAKE_ON_COMMAND, 0x00]\n );\n }\n\n async enableSleepTimer(milliseconds) {\n const view = new DataView(new ArrayBuffer(4));\n const littleEndian = false;\n view.setInt32(0, milliseconds, littleEndian);\n await this.device.send(\n Reports.GLITTER_BASIC_CMD, \n [\n Commands.GLITTER_CMD_SET_SLEEP_TIMEOUT, \n view.getUint8(0), \n view.getUint8(1), \n view.getUint8(2), \n view.getUint8(3),\n ]\n );\n }\n\n async reboot(mode) {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD, \n [Commands.GLITTER_CMD_REBOOT, mode]\n );\n }\n\n async drawMatrix(matrix) {\n await this.device.send(\n Reports.GLITTER_GRID_PWM_CNTL,\n matrix.flat().map(v => GAMMA[Math.floor((v ?? 0) * 255)])\n );\n }\n\n async drawPixel(r, c, brightness) {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD,\n [Commands.GLITTER_CMD_DRAW_PIXEL, c, r, brightness]\n );\n }\n\n async drawLine({r1, c1}, {r2, c2}, brightness) {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD,\n [Commands.GLITTER_CMD_DRAW_PIXEL, r1, c1, r2, c2, brightness]\n );\n }\n\n device;\n}\n","import { HEIGHT, WIDTH } from '../../../hardware-constants.js';\nimport { getDevice } from '../../../web-hid/device.js';\nimport { HIDOperations } from '../../../web-hid/HIDOperations.js';\nimport { ReportAbstractionLayer } from './ReportAbstractionLayer.js';\nimport { BootMode } from './reports.js';\n\nexport class SparkleController extends ReportAbstractionLayer {\n async bootloader() {\n await super.reboot(BootMode.BOOTSEL);\n }\n\n async connect() {\n const device = await getDevice();\n if (device) {\n await device.open();\n this.device = new HIDOperations(device);\n }\n }\n \n async draw(matrix) {\n await super.drawMatrix(matrix);\n }\n\n async verifyFirmware() {\n try {\n const info = await super.info();\n return (\n info.display_height == HEIGHT &&\n info.display_width == WIDTH\n );\n } catch {\n return false;\n }\n }\n\n async version() {\n const info = await super.info();\n if (info.version_major != undefined \n && info.version_minor != undefined\n && (info.version_major > 0 || info.version_minor > 0)) {\n return {\n major: info.version_major,\n minor: info.version_minor\n }\n } else {\n // Sparkle <=1.1.1: Glitter version unavailable \n return { major: 1, minor: 0 };\n }\n }\n}\n","import { DefaultController } from './supported-firmware/FrameworkComputer/inputmodule-rs/DefaultController.js';\nimport { SigrootController } from './supported-firmware/sigroot/FW_LED_Matrix_Firmware/SigrootController.js';\nimport { SparkleController } from './supported-firmware/vddCore/sparkle-fw16/SparkleController.js';\n\nexport class HardwareControllerFactory {\n static async detectSerial() {\n const c1 = new DefaultController();\n const c2 = new SigrootController();\n\n await c1.connect();\n if (await c1.verifyFirmware()) {\n return c1;\n }\n \n await c2.connect()\n if (await c2.verifyFirmware()) {\n return c2;\n } \n \n return null;\n }\n\n static async detectHID() {\n const c1 = new SparkleController();\n\n await c1.connect();\n if (await c1.verifyFirmware()) {\n return c1;\n } \n \n return null;\n }\n}\n"],"names":["VID","VID_ARR","GAMMA","Object","freeze","extraPorts","filters","usbVendorId","usbProductId","PortSelectionCancelled","Error","constructor","super","this","name","date","Date","PortUnavailable","async","getPort","length","pop","push","navigator","serial","getPorts","requestPort","e","close","port","message","PortMutex","portOperations","lockName","Math","random","toString","deduper","Map","portOps","acquire","fn","trace","stack","enqueue","console","error","acquireIdempotent","key","has","info","set","execDedupedOp","locks","request","get","delete","PortOperations","rx","timeout","readable","locked","response","reader","getReader","timeoutHandle","setTimeout","cancel","value","done","read","clearTimeout","releaseLock","tx","buffer","writable","writer","getWriter","write","Uint8Array","Command","ANIMATE","BRIGHTNESS","BOOTLOADER","DRAW","DRAW_GREY_COL_BUFFER","GAME_CTRL","GAME_STATUS","PANIC","PATTERN","SLEEP","STAGE_GREY_COL","START_GAME","VERSION","CommandAbstractionLayer$1","portMutex","bootloader","p","brightness","draw","matrix","index","output","fill","r","c","drawGrayscale","buffers","Array","from","_","floor","i","asleep","sleep","wake","pattern","percent","Pattern","PERCENTAGE","version","ver","major","minor","patch","preRelease","DefaultController","CommandAbstractionLayer","connect","connected","open","baudRate","bitDepth","BitDepth","GRAY_8BIT","MONO_1BIT","verifyFirmware","undefined","NOOP","ANIMATION_DIAMOND","ANIMATION_FIRE","ANIMATION_FIREPLACE","ANIMATION_GEAR","ANIMATION_RING","ANIMATION_STARTUP","ANIMATION_STARTUP_ONCE","DRAW_PWM","DRAW_PWM_BLOCKING","DRAW_SCALE","DRAW_SCALE_BLOCKING","FLUSH_CMD_QUEUE","TEST_PATTERN","SET_CONST_PWM","SET_CONST_SCALE","SET_PX_PWM","SET_PX_SCALE","IDENTITY_STRING","IDENTITY_STR_REGEX","identityString","ident","String","fromCharCode","setPixelPwm","setGlobalPwm","setMatrixPwm","concat","flat","map","v","setPixelAnalog","setGlobalAnalog","setMatrixAnalog","SigrootController","scaleInitialized","match","extraDevices","vendorId","productId","DeviceSelectionCancelled","HIDOperations","device","send","report","data","bytes","arr","len","val","pad","feature","sendFeatureReport","id","sendReport","reply","receiveFeatureReport","byteLength","exp","act","Reports","Commands","BootMode","ReportAbstractionLayer","infoRaw","sleep_pin","getUint8","dip1_pin","intb_pin","state_flags","id_reg","config_reg","global_brightness","display_width","display_height","timeout_ms","getUint32","version_major","version_minor","disableSleep","disableDeepSleep","disableSleepTimer","enableDeepSleep","enableSleepTimer","milliseconds","view","DataView","ArrayBuffer","setInt32","reboot","mode","drawMatrix","drawPixel","drawLine","r1","c1","r2","c2","SparkleController","hid","getDevices","requestDevice","getDevice","detectSerial","detectHID"],"mappings":"2PAAY,MAECA,EAAM,MACNC,EAAU,CAAC,GAAM,KAIjBC,EAAQC,OAAOC,OAAO,CACjC,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,GAAI,GAAI,GAAI,GACxB,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAC5B,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAC5B,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAC5B,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAC5B,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAC5B,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAC5B,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAC5B,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAC5B,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAC5B,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAC5B,GAAI,GAAI,GAAI,GAAI,GA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iBACJiG,EAGF,IACT,ShB3BiB,aACI,CAAC,EAAM,4EALT"}
1
+ {"version":3,"file":"led-matrix-controllers.umd.min.js","sources":["../src/hardware-constants.js","../src/web-serial/port.js","../src/web-serial/PortMutex.js","../src/web-serial/PortOperations.js","../src/supported-firmware/FrameworkComputer/inputmodule-rs/commands.js","../src/supported-firmware/FrameworkComputer/inputmodule-rs/CommandAbstractionLayer.js","../src/supported-firmware/FrameworkComputer/inputmodule-rs/DefaultController.js","../src/supported-firmware/sigroot/FW_LED_Matrix_Firmware/commands.js","../src/supported-firmware/sigroot/FW_LED_Matrix_Firmware/CommandAbstractionLayer.js","../src/supported-firmware/sigroot/FW_LED_Matrix_Firmware/SigrootController.js","../src/web-hid/device.js","../src/web-hid/HIDOperations.js","../src/web-hid/util.js","../src/supported-firmware/vddCore/sparkle-fw16/reports.js","../src/supported-firmware/vddCore/sparkle-fw16/ReportAbstractionLayer.js","../src/supported-firmware/vddCore/sparkle-fw16/SparkleController.js","../src/HardwareControllerFactory.js"],"sourcesContent":["export const WIDTH = 9;\nexport const HEIGHT = 34;\nexport const VID = 0x32AC;\nexport const VID_ARR = [0x32, 0xAC];\nexport const PID = 0x0020;\nexport const PID_ARR = [0x00, 0x20];\n\n// For PWM dimming (not for analog dimming/constant-current reduction!)\nexport const GAMMA = Object.freeze([\n 0, 0, 0, 0, 0, 0, 0, 1, \n 1, 1, 1, 1, 1, 1, 1, 1, \n 1, 1, 1, 1, 1, 1, 1, 1, \n 1, 1, 1, 1, 1, 1, 1, 1, \n 1, 1, 1, 2, 2, 2, 2, 2, \n 2, 2, 2, 2, 3, 3, 3, 3, \n 3, 3, 3, 4, 4, 4, 4, 4, \n 4, 5, 5, 5, 5, 6, 6, 6, \n 6, 6, 7, 7, 7, 7, 8, 8, \n 8, 9, 9, 9, 10, 10, 10, 11, \n 11, 11, 12, 12, 12, 13, 13, 14, \n 14, 14, 15, 15, 16, 16, 17, 17, \n 17, 18, 18, 19, 19, 20, 20, 21, \n 22, 22, 23, 23, 24, 24, 25, 26, \n 26, 27, 27, 28, 29, 29, 30, 31, \n 32, 32, 33, 34, 34, 35, 36, 37, \n 38, 38, 39, 40, 41, 42, 42, 43, \n 44, 45, 46, 47, 48, 49, 50, 51, \n 52, 53, 54, 55, 56, 57, 58, 59, \n 60, 61, 62, 63, 64, 66, 67, 68, \n 69, 70, 71, 73, 74, 75, 76, 78, \n 79, 80, 82, 83, 84, 86, 87, 88, \n 90, 91, 93, 94, 96, 97, 99, 100, \n 102, 103, 105, 106, 108, 110, 111, 113, \n 115, 116, 118, 120, 121, 123, 125, 127, \n 128, 130, 132, 134, 136, 138, 140, 141, \n 143, 145, 147, 149, 151, 153, 155, 157, \n 159, 161, 164, 166, 168, 170, 172, 174, \n 177, 179, 181, 183, 186, 188, 190, 193, \n 195, 197, 200, 202, 205, 207, 210, 212, \n 215, 217, 220, 222, 225, 228, 230, 233, \n 236, 238, 241, 244, 247, 249, 252, 255\n]);\n","import { PID, VID } from '../hardware-constants.js';\n\nconst filters = [{ usbVendorId: VID, usbProductId: PID }];\n\nexport class PortSelectionCancelled extends Error {\n constructor() {\n super('User cancelled port selection.');\n this.name = this.constructor.name;\n this.date = new Date();\n }\n}\n\nexport class PortUnavailable extends Error {\n constructor() {\n super('Selected port already in use.');\n this.name = this.constructor.name;\n this.date = new Date();\n }\n}\n\nasync function requestPort() {\n try {\n if (navigator.serial.requestPort) {\n return await navigator.serial.requestPort({ filters });\n } else {\n return null; // Web Worker\n }\n } catch (e) {\n switch (e.name) {\n case ('NotFoundError'):\n throw new PortSelectionCancelled();\n case ('InvalidStateError'):\n throw new PortUnavailable();\n case ('SecurityError'): // No user gesture\n return null;\n default:\n throw e;\n }\n }\n}\n\nclass KnownPorts {\n used = new Set();\n unused = [];\n\n async getOrFetchUnused() {\n let port = this.unused.pop();\n \n if (!port) {\n const systemPorts = await navigator.serial.getPorts({ filters });\n this.#enqueueUnique(systemPorts);\n port = this.unused.pop();\n }\n\n if (!port) {\n const manualPort = await requestPort();\n this.#enqueueUnique([manualPort]);\n port = this.unused.pop();\n }\n\n if (port) {\n this.used.add(port);\n }\n \n return port;\n }\n\n #enqueueUnique(ports) {\n if (ports) {\n for (const port of ports) {\n if (port && !this.used.has(port) && !this.unused.includes(port)) {\n this.unused.push(port);\n }\n }\n }\n }\n}\n\nconst knownPorts = new KnownPorts();\n\n/**\n * Adds user-selected port to permitted ports. Only for use outside of Web \n * Worker to establish permission for use within Web Worker.\n * @returns {null}\n */\nexport async function requestPortForWorker() {\n const _ = await requestPort();\n}\n\n/**\n * Never returns the same port twice. \n * @returns {(SerialPort|null)}\n */\nexport async function getUnusedPort() {\n return await knownPorts.getOrFetchUnused();\n}\n\n/**\n * Close port without throwing if already closed.\n * @param {SerialPort} port \n */\nexport async function close(port) {\n try {\n await port.close();\n } catch(e) {\n if (e.name != 'InvalidStateError') {\n if (e.message.includes('The port is already closed')) {\n throw e;\n }\n }\n }\n}\n","export class PortMutex {\n constructor(portOperations) {\n this.#lockName = `port-mutex-${Math.random().toString()}`;\n this.#deduper = new Map();\n this.#portOps = portOperations;\n }\n\n async acquire(fn) {\n const trace = new Error('created bad cb').stack;\n\n await this.#enqueue(async () => {\n try {\n await fn(this.#portOps);\n } catch (e) {\n console.error('Error occured in anonymous callback.');\n console.error('Original error:', e);\n console.error('--- This callback was created at ---\\n', trace);\n }\n });\n }\n\n async acquireIdempotent(key, fn) {\n const trace = new Error('created bad cb').stack;\n\n if (this.#deduper.has(key)) {\n console.info(`\"${key}\" request coalesced.`);\n }\n\n this.#deduper.set(key, async () => {\n try {\n await fn(this.#portOps);\n } catch (e) {\n console.error('Error occured in anonymous callback.');\n console.error('Original error:', e);\n console.error('--- This callback was created at ---\\n', trace);\n }\n });\n\n await this.#enqueue(() => this.#execDedupedOp(key));\n }\n\n async #enqueue(fn) {\n // `navigator.locks` maintains queue and provides mutual exclusion.\n return navigator.locks.request(this.#lockName, fn);\n }\n\n async #execDedupedOp(key) {\n if (this.#deduper.has(key)) {\n const fn = this.#deduper.get(key);\n this.#deduper.delete(key);\n await fn();\n }\n }\n\n #lockName;\n #deduper;\n #portOps;\n}\n","export class PortOperations {\n constructor(port) {\n this.#port = port;\n }\n\n async rx(length, timeout=3000) {\n if (this.#port === null) {\n throw new Error('attempted RX before port initialization.');\n }\n\n /*\n * ReadableStream's built-in locking mechanism cannot be awaited or otherwise\n * asynchronously acquired. A PortMutex must be used.\n */\n if (this.#port.readable.locked) {\n throw new Error('attempted RX while port locked.');\n }\n\n const response = [];\n const reader = this.#port.readable.getReader();\n const timeoutHandle = setTimeout(() => reader.cancel(), timeout);\n\n try {\n // Response may be divided across multiple reads\n while (response.length < length) {\n const { value, done } = await reader.read();\n response.push(...(value ?? []));\n if (done || !value) break;\n }\n } finally {\n clearTimeout(timeoutHandle);\n reader.releaseLock();\n }\n\n return response;\n }\n\n async tx(buffer) {\n if (this.#port === null) {\n throw new Error('attempted TX before port initialization.');\n }\n \n /*\n * WritableStream's built-in locking mechanism cannot be awaited or otherwise\n * asynchronously acquired. A PortMutex must be used.\n */\n if (this.#port.writable.locked) {\n throw new Error('attempted TX while port locked.');\n }\n\n const writer = this.#port.writable.getWriter();\n\n try {\n await writer.write(new Uint8Array(buffer));\n } finally {\n /* \n * The writer must be completely torn down between every single write.\n * Many parsers can't handle delayed flushing and write coalescing.\n * Command sequences will fail if `releaseLock()` is used here.\n */\n await writer.close();\n }\n }\n\n #port;\n}\n","// All replies to all commands are 32 bytes\nexport const RX_PACKET_SZ = 32;\n\nexport const Command = Object.freeze({\n ANIMATE: 0x04,\n BRIGHTNESS: 0x00,\n BOOTLOADER: 0x02,\n DRAW: 0x06,\n DRAW_GREY_COL_BUFFER: 0x08,\n GAME_CTRL: 0x11,\n GAME_STATUS: 0x12,\n PANIC: 0x05,\n PATTERN: 0x01,\n SLEEP: 0x03,\n STAGE_GREY_COL: 0x07,\n START_GAME: 0x10,\n VERSION: 0x20,\n});\n\n// Used with Command.PATTERN\nexport const Pattern = Object.freeze({\n DISPLAY_LOTUS_HORIZONTAL: 0x03,\n DISPLAY_LOTUS_VERTICAL: 0x07,\n DISPLAY_PANIC: 0x06,\n DOUBLE_GRADIENT: 0x02,\n FULL_BRIGHTNESS: 0x05,\n GRADIENT: 0x01,\n PERCENTAGE: 0x00,\n ZIG_ZAG: 0x04,\n});\n\n// DRAW or DRAW_GREY_COL_BUFFER\nexport const BitDepth = Object.freeze({\n GRAY_8BIT: '8-bit',\n MONO_1BIT: '1-bit',\n})\n","import { GAMMA, HEIGHT, VID_ARR, WIDTH } from '../../../hardware-constants.js';\nimport { Command, RX_PACKET_SZ } from './commands.js';\n\nexport class CommandAbstractionLayer {\n constructor(portMutex = null) {\n this.portMutex = portMutex;\n }\n\n async bootloader() {\n await this.portMutex.acquire(async p => {\n await p.tx([...VID_ARR, Command.BOOTLOADER]);\n });\n }\n\n async brightness(brightness) {\n await this.portMutex.acquire(async p => {\n await p.tx([...VID_ARR, Command.BRIGHTNESS, brightness]);\n });\n }\n\n async draw(matrix) {\n let index = 0;\n let output = new Uint8Array(39).fill(0);\n\n // Pack cells into bits\n for (let r = 0; r < HEIGHT; r++) {\n for (let c = 0; c < WIDTH; c++) {\n if (matrix[r][c]) {\n output[index >> 3] |= 1 << index % 8;\n }\n index++;\n }\n }\n\n await this.portMutex.acquireIdempotent(\n 'drawMatrix', \n async p => {\n await p.tx([...VID_ARR, Command.DRAW, ...output]);\n }\n );\n }\n\n async drawGrayscale(matrix) {\n // Transpose & Gamma Correction\n const buffers = Array.from(\n { length: WIDTH }, \n (_, c) => Array.from(\n { length: HEIGHT }, \n (_, r) => GAMMA[Math.floor((matrix[r][c] ?? 0) * 255)]\n )\n );\n\n // Only execute the most recent call \n await this.portMutex.acquireIdempotent(\n 'drawMatrix', \n async p => {\n for (let i = 0; i < WIDTH; i++) {\n await p.tx([...VID_ARR, Command.STAGE_GREY_COL, i, ...buffers[i]]);\n }\n await p.tx([...VID_ARR, Command.DRAW_GREY_COL_BUFFER]);\n }\n );\n }\n\n async asleep() {\n let asleep = false;\n\n await this.portMutex.acquire(async p => {\n await p.tx([...VID_ARR, Command.SLEEP]);\n asleep = await p.rx(RX_PACKET_SZ);\n asleep = asleep[0] != 0x00;\n });\n\n return asleep;\n }\n\n async sleep() {\n await this.portMutex.acquire(async p => {\n await p.tx([...VID_ARR, Command.SLEEP, 0x01]);\n });\n }\n\n async wake() {\n await this.portMutex.acquire(async p => {\n await p.tx([...VID_ARR, Command.SLEEP]);\n });\n }\n\n async pattern(pattern) {\n await this.portMutex.acquireIdempotent(\n 'drawMatrix',\n async p => {\n await p.tx([...VID_ARR, Command.PATTERN, pattern]);\n }\n );\n }\n\n async percent(percent) {\n await this.portMutex.acquireIdempotent(\n 'drawMatrix',\n async p => {\n await p.tx([...VID_ARR, Command.PATTERN, Pattern.PERCENTAGE, percent]);\n }\n );\n }\n\n async version() {\n let ver = {};\n\n await this.portMutex.acquire(async p => {\n await p.tx([...VID_ARR, Command.VERSION]);\n const response = await p.rx(RX_PACKET_SZ);\n\n // MMMMMMMM mmmmPPPP 0000000p\n ver.major = response[0];\n ver.minor = response[1] >> 4;\n ver.patch = response[1] & 0x0F;\n ver.preRelease = response[2] == 1;\n });\n\n return ver;\n }\n}\n","import { close, getUnusedPort } from '../../../web-serial/port.js';\nimport { PortMutex } from '../../../web-serial/PortMutex.js';\nimport { PortOperations } from '../../../web-serial/PortOperations.js';\nimport { CommandAbstractionLayer } from './CommandAbstractionLayer.js';\nimport { BitDepth } from './commands.js';\n\nexport class DefaultController extends CommandAbstractionLayer {\n async bootloader() {\n return super.bootloader();\n }\n\n async connect() {\n const port = await getUnusedPort();\n\n if (port?.connected) {\n await close(port);\n await port.open({ baudRate: 115200 });\n this.portMutex = new PortMutex(new PortOperations(port));\n } else {\n throw new Error('No Port Found');\n }\n }\n\n async draw(matrix) {\n switch (this.bitDepth ?? BitDepth.MONO_1BIT) {\n\n case (BitDepth.GRAY_8BIT):\n super.drawGrayscale(matrix);\n break;\n\n case (BitDepth.MONO_1BIT):\n super.draw(matrix);\n break;\n\n default:\n console.error(`Unsupported bitdepth: ${this.bitDepth}`);\n }\n }\n\n async verifyFirmware() {\n try {\n const version = await super.version();\n\n return version\n && version.major != undefined\n && version.minor != undefined\n && version.patch != undefined\n && version.preRelease != undefined;\n \n } catch {\n return false;\n }\n }\n\n async version() {\n return super.version();\n }\n}\n","export const Command = Object.freeze({\n /* 000 */ NOOP: 0x00,\n /* 'd' */ ANIMATION_DIAMOND: 0x64,\n /* 'b' */ ANIMATION_FIRE: 0x62,\n /* 'f' */ ANIMATION_FIREPLACE: 0x66,\n /* 'g' */ ANIMATION_GEAR: 0x67,\n /* 'r' */ ANIMATION_RING: 0x72,\n /* 'a' */ ANIMATION_STARTUP: 0x61,\n /* 'A' */ ANIMATION_STARTUP_ONCE: 0x41,\n /* 'e' */ BOOTLOADER: 0x65,\n /* 'm' */ DRAW_PWM: 0x6D,\n /* 'M' */ DRAW_PWM_BLOCKING: 0x4D,\n /* 'n' */ DRAW_SCALE: 0x6E,\n /* 'N' */ DRAW_SCALE_BLOCKING: 0x4E,\n /* 'c' */ FLUSH_CMD_QUEUE: 0x63,\n /* 't' */ TEST_PATTERN: 0x74,\n /* 'w' */ SET_CONST_PWM: 0x77,\n /* 's' */ SET_CONST_SCALE: 0x73,\n /* 'p' */ SET_PX_PWM: 0x70,\n /* 'q' */ SET_PX_SCALE: 0x71,\n /* 127 */ IDENTITY_STRING: 0x7F,\n});\n\nexport const IDENTITY_STR_LEN = 25;\n\nexport const IDENTITY_STR_REGEX = /^Sig\\sFW\\sLED\\sMatrix\\sFW\\sV(\\d+)\\.(\\d+)$/;\n","import { GAMMA } from '../../../hardware-constants.js';\nimport { Command, IDENTITY_STR_LEN } from './commands.js';\n\nexport class CommandAbstractionLayer {\n constructor(portMutex = null) {\n this.portMutex = portMutex;\n }\n\n async bootloader() {\n await this.portMutex.acquire(async p => {\n await p.tx([Command.BOOTLOADER]);\n });\n }\n\n async identityString() {\n let ident = null;\n\n await this.portMutex.acquire(async p => {\n await p.tx([Command.IDENTITY_STRING]);\n ident = await p.rx(IDENTITY_STR_LEN);\n });\n\n return String.fromCharCode(...ident);\n }\n\n async setPixelPwm(r, c, brightness) {\n await this.portMutex.acquire(\n async p => {\n await p.tx([Command.SET_PX_PWM, c, r, brightness]);\n }\n );\n }\n\n async setGlobalPwm(brightness) {\n await this.portMutex.acquire(\n async p => {\n await p.tx([Command.SET_CONST_PWM, brightness]);\n }\n );\n }\n\n async setMatrixPwm(matrix) {\n // Only execute the most recent call \n await this.portMutex.acquireIdempotent(\n 'drawMatrix', \n async p => {\n await p.tx(\n [Command.DRAW_PWM].concat(\n matrix.flat().map(v => \n GAMMA[Math.floor((v ?? 0) * 255)]\n )\n )\n );\n }\n );\n }\n\n async setPixelAnalog(r, c, brightness) {\n await this.portMutex.acquire(\n async p => {\n await p.tx([Command.SET_PX_SCALE, c, r, brightness]);\n }\n );\n }\n\n async setGlobalAnalog(brightness) {\n await this.portMutex.acquire(\n async p => {\n await p.tx([Command.SET_CONST_SCALE, brightness]);\n }\n );\n }\n\n async setMatrixAnalog(matrix) {\n // Only execute the most recent call \n await this.portMutex.acquireIdempotent(\n 'drawMatrix', \n async p => {\n await p.tx(\n [Command.DRAW_SCALE].concat(\n matrix.flat().map(v => \n GAMMA[Math.floor((v ?? 0) * 255)]\n )\n )\n );\n }\n );\n }\n}\n","import { close, getUnusedPort } from '../../../web-serial/port.js';\nimport { PortMutex } from '../../../web-serial/PortMutex.js';\nimport { PortOperations } from '../../../web-serial/PortOperations.js';\nimport { CommandAbstractionLayer } from './CommandAbstractionLayer.js';\nimport { IDENTITY_STR_REGEX } from './commands.js';\n\nexport class SigrootController extends CommandAbstractionLayer {\n async bootloader() {\n await super.bootloader();\n }\n\n async connect() {\n const port = await getUnusedPort();\n\n if (port?.connected) {\n await close(port);\n await port.open({ baudRate: 115200 });\n this.portMutex = new PortMutex(new PortOperations(port));\n }\n }\n\n async draw(matrix) {\n if (!this.#scaleInitialized) {\n await super.setGlobalAnalog(0x20);\n this.#scaleInitialized = true;\n } else {\n throw new Error('No Port Found');\n }\n\n await super.setMatrixPwm(matrix);\n }\n\n async verifyFirmware() { \n return await this.version() != null;\n }\n\n async version() {\n const ident = await super.identityString();\n const match = ident.match(IDENTITY_STR_REGEX);\n\n if (match && match.length == 3) {\n return {\n major: match[1],\n minor: match[2]\n }\n } else {\n return null;\n }\n }\n\n #scaleInitialized;\n}\n","import { PID, VID } from '../hardware-constants.js';\n\nconst filters = [{ vendorId: VID, productId: PID }];\n\nexport class DeviceSelectionCancelled extends Error {\n constructor() {\n super('User cancelled device selection.');\n this.name = this.constructor.name;\n this.date = new Date();\n }\n}\n\nasync function requestDevice() {\n try {\n if (navigator.serial.requestPort) {\n return await navigator.serial.requestDevice({ filters });\n } else {\n return null; // Web Worker\n }\n } catch (e) {\n switch (e.name) {\n case ('NotFoundError'):\n throw new DeviceSelectionCancelled();\n case ('SecurityError'): // No user gesture\n return null;\n default:\n throw e;\n }\n }\n}\n\nclass KnownDevices {\n used = new Set();\n unused = [];\n\n async getOrFetchUnused() {\n let device = this.unused.pop();\n\n if (!device) {\n const systemDevices = await navigator.hid.getDevices({ filters });\n this.#enqueueUnique(systemDevices);\n device = this.unused.pop();\n }\n\n if (!device) {\n const manualDevices = await requestDevice();\n this.#enqueueUnique([manualDevices]);\n device = this.unused.pop();\n }\n\n if (device) {\n this.used.add(device);\n }\n\n return device;\n }\n\n #enqueueUnique(devices) {\n if (devices) {\n for (const dev of devices) {\n if (dev && !this.used.has(dev) && !this.unused.includes(dev)) {\n this.unused.push(dev);\n }\n }\n }\n }\n}\n\nconst knownDevices = new KnownDevices();\n\n/**\n * Adds user-selected device to permitted device. Only for use outside of Web \n * Worker to establish permission for use within Web Worker.\n * @returns {null}\n */\nexport async function reqestDeviceForWorker() {\n const _ = await requestDevice();\n}\n\n/**\n * Never returns the same device twice. \n * @returns {(HIDDevice|null)}\n */\nexport async function getUnusedDevice() {\n return await knownDevices.getOrFetchUnused();\n}\n","import { pad } from './util.js';\n\nexport class HIDOperations {\n constructor(device) {\n this.#device = device;\n }\n\n async send(report, data) {\n if (data.length < report.bytes) {\n data = pad(data, report.bytes);\n } else if (data.length > report.bytes) {\n throw new Error('Unable to send report: too many bytes');\n }\n\n const buffer = new Uint8Array(data).buffer;\n\n if (report.feature) {\n await this.#device.sendFeatureReport(report.id, buffer);\n } else {\n await this.#device.sendReport(report.id, buffer);\n }\n }\n\n async request(report) {\n let reply = [];\n\n if (report.feature) {\n reply = await this.#device.receiveFeatureReport(report.id);\n } else {\n /* \n * HID input reports are used for unprompted data.\n * See WebHID `HIDInputReportEvent`\n */\n throw new Error('Invalid operation');\n }\n\n if (reply.byteLength != report.bytes) {\n const exp = report.bytes;\n const act = reply.byteLength;\n console.error(`reply length=${act} (expected ${exp})`);\n }\n\n return reply;\n }\n\n #device;\n}\n","export function pad(arr, len, val=0x00) {\n return arr.concat(new Array(len - arr.length).fill(val));\n}\n","export const Reports = {\n GLITTER_DEVICE_INFO: {\n id: 0x01,\n bytes: 307,\n feature: true,\n },\n GLITTER_BASIC_CMD: {\n id: 0x02,\n bytes: 16,\n feature: true,\n },\n GLITTER_GRID_PWM_CNTL: {\n id: 0x03,\n bytes: 306,\n feature: true,\n },\n GLITTER_GRID_PWM_CNTL: {\n id: 0x04,\n bytes: 306,\n feature: true,\n }\n}\n\nexport const Commands = {\n GLITTER_CMD_REBOOT: 0x00,\n GLITTER_CMD_SLEEP: 0x01,\n GLITTER_CMD_WAKE_ON_COMMAND: 0x02,\n GLITTER_CMD_SET_SLEEP_TIMEOUT: 0x03,\n GLITTER_CMD_SET_GLOBAL_BRIGHTNESS: 0x04,\n GLITTER_CMD_DRAW_PIXEL: 0x05,\n GLITTER_CMD_DRAW_LINE: 0x06\n}\n\nexport const BootMode = {\n BOOTSEL: 0x00,\n NORMAL: 0x01,\n}\n","import { GAMMA } from '../../../hardware-constants.js';\nimport { Commands, Reports } from './reports.js';\n\nexport class ReportAbstractionLayer {\n constructor(device = null) {\n this.device = device;\n }\n\n async info() {\n const infoRaw = await this.device.request(Reports.GLITTER_DEVICE_INFO);\n\n return {\n sleep_pin: infoRaw.getUint8(1),\n dip1_pin: infoRaw.getUint8(2),\n intb_pin: infoRaw.getUint8(3),\n state_flags: infoRaw.getUint8(4),\n id_reg: infoRaw.getUint8(5),\n config_reg: infoRaw.getUint8(6),\n global_brightness: infoRaw.getUint8(7),\n display_width: infoRaw.getUint8(8),\n display_height: infoRaw.getUint8(9),\n timeout_ms: infoRaw.getUint32(10),\n version_major: infoRaw.getUint8(14),\n version_minor: infoRaw.getUint8(15),\n };\n }\n\n async wake() {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD,\n [Commands.GLITTER_CMD_SLEEP, false]\n );\n }\n\n async sleep() {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD,\n [Commands.GLITTER_CMD_SLEEP, true]\n );\n }\n\n async disableSleep() {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD, \n [Commands.GLITTER_CMD_SET_SLEEP_TIMEOUT, 0xff, 0xff, 0xff, 0xff]\n );\n }\n\n async disableDeepSleep() {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD, \n [Commands.GLITTER_CMD_WAKE_ON_COMMAND, 0x01]\n );\n }\n\n async disableSleepTimer() {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD, \n [Commands.GLITTER_CMD_SET_SLEEP_TIMEOUT, 0x00, 0x00, 0x00, 0x00]\n );\n }\n \n async enableDeepSleep() {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD, \n [Commands.GLITTER_CMD_WAKE_ON_COMMAND, 0x00]\n );\n }\n\n async enableSleepTimer(milliseconds) {\n const view = new DataView(new ArrayBuffer(4));\n const littleEndian = false;\n view.setInt32(0, milliseconds, littleEndian);\n await this.device.send(\n Reports.GLITTER_BASIC_CMD, \n [\n Commands.GLITTER_CMD_SET_SLEEP_TIMEOUT, \n view.getUint8(0), \n view.getUint8(1), \n view.getUint8(2), \n view.getUint8(3),\n ]\n );\n }\n\n async reboot(mode) {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD, \n [Commands.GLITTER_CMD_REBOOT, mode]\n );\n }\n\n async drawMatrix(matrix) {\n await this.device.send(\n Reports.GLITTER_GRID_PWM_CNTL,\n matrix.flat().map(v => GAMMA[Math.floor((v ?? 0) * 255)])\n );\n }\n\n async drawPixel(r, c, brightness) {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD,\n [Commands.GLITTER_CMD_DRAW_PIXEL, c, r, brightness]\n );\n }\n\n async drawLine({r1, c1}, {r2, c2}, brightness) {\n await this.device.send(\n Reports.GLITTER_BASIC_CMD,\n [Commands.GLITTER_CMD_DRAW_PIXEL, r1, c1, r2, c2, brightness]\n );\n }\n\n device;\n}\n","import { HEIGHT, WIDTH } from '../../../hardware-constants.js';\nimport { getUnusedDevice } from '../../../web-hid/device.js';\nimport { HIDOperations } from '../../../web-hid/HIDOperations.js';\nimport { ReportAbstractionLayer } from './ReportAbstractionLayer.js';\nimport { BootMode } from './reports.js';\n\nexport class SparkleController extends ReportAbstractionLayer {\n async bootloader() {\n await super.reboot(BootMode.BOOTSEL);\n }\n\n async connect() {\n const device = await getUnusedDevice();\n\n if (device) {\n await device.open();\n this.device = new HIDOperations(device);\n } else {\n throw new Error('No Device Found');\n }\n }\n \n async draw(matrix) {\n await super.drawMatrix(matrix);\n }\n\n async verifyFirmware() {\n try {\n const info = await super.info();\n return (\n info.display_height == HEIGHT &&\n info.display_width == WIDTH\n );\n } catch {\n return false;\n }\n }\n\n async version() {\n const info = await super.info();\n\n if (info.version_major != undefined \n && info.version_minor != undefined\n && (info.version_major > 0 || info.version_minor > 0)) {\n return {\n major: info.version_major,\n minor: info.version_minor\n }\n } else {\n // Sparkle <=1.1.1: Glitter version unavailable \n return { major: 1, minor: 0 };\n }\n }\n}\n","import { DefaultController } from './supported-firmware/FrameworkComputer/inputmodule-rs/DefaultController.js';\nimport { SigrootController } from './supported-firmware/sigroot/FW_LED_Matrix_Firmware/SigrootController.js';\nimport { SparkleController } from './supported-firmware/vddCore/sparkle-fw16/SparkleController.js';\n\nexport class HardwareControllerFactory {\n static async detectSerial() {\n const c1 = new DefaultController();\n const c2 = new SigrootController();\n\n await c1.connect();\n if (await c1.verifyFirmware()) {\n return c1;\n }\n \n await c2.connect()\n if (await c2.verifyFirmware()) {\n return c2;\n } \n \n return null;\n }\n\n static async detectHID() {\n const c1 = new SparkleController();\n\n await c1.connect();\n if (await c1.verifyFirmware()) {\n return c1;\n } \n \n return null;\n }\n}\n"],"names":["VID","VID_ARR","GAMMA","Object","freeze","filters","usbVendorId","usbProductId","PortSelectionCancelled","Error","constructor","super","this","name","date","Date","PortUnavailable","async","requestPort","navigator","serial","e","knownPorts","used","Set","unused","getOrFetchUnused","port","pop","systemPorts","getPorts","enqueueUnique","manualPort","add","ports","has","includes","push","getUnusedPort","close","message","PortMutex","portOperations","lockName","Math","random","toString","deduper","Map","portOps","acquire","fn","trace","stack","enqueue","console","error","acquireIdempotent","key","info","set","execDedupedOp","locks","request","get","delete","PortOperations","rx","length","timeout","readable","locked","response","reader","getReader","timeoutHandle","setTimeout","cancel","value","done","read","clearTimeout","releaseLock","tx","buffer","writable","writer","getWriter","write","Uint8Array","Command","ANIMATE","BRIGHTNESS","BOOTLOADER","DRAW","DRAW_GREY_COL_BUFFER","GAME_CTRL","GAME_STATUS","PANIC","PATTERN","SLEEP","STAGE_GREY_COL","START_GAME","VERSION","BitDepth","GRAY_8BIT","MONO_1BIT","CommandAbstractionLayer$1","portMutex","bootloader","p","brightness","draw","matrix","index","output","fill","r","c","drawGrayscale","buffers","Array","from","_","floor","i","asleep","sleep","wake","pattern","percent","Pattern","PERCENTAGE","version","ver","major","minor","patch","preRelease","DefaultController","CommandAbstractionLayer","connect","connected","open","baudRate","bitDepth","verifyFirmware","undefined","NOOP","ANIMATION_DIAMOND","ANIMATION_FIRE","ANIMATION_FIREPLACE","ANIMATION_GEAR","ANIMATION_RING","ANIMATION_STARTUP","ANIMATION_STARTUP_ONCE","DRAW_PWM","DRAW_PWM_BLOCKING","DRAW_SCALE","DRAW_SCALE_BLOCKING","FLUSH_CMD_QUEUE","TEST_PATTERN","SET_CONST_PWM","SET_CONST_SCALE","SET_PX_PWM","SET_PX_SCALE","IDENTITY_STRING","IDENTITY_STR_REGEX","identityString","ident","String","fromCharCode","setPixelPwm","setGlobalPwm","setMatrixPwm","concat","flat","map","v","setPixelAnalog","setGlobalAnalog","setMatrixAnalog","SigrootController","scaleInitialized","match","vendorId","productId","DeviceSelectionCancelled","requestDevice","knownDevices","device","systemDevices","hid","getDevices","manualDevices","devices","dev","getUnusedDevice","HIDOperations","send","report","data","bytes","arr","len","val","pad","feature","sendFeatureReport","id","sendReport","reply","receiveFeatureReport","byteLength","exp","act","Reports","Commands","BootMode","ReportAbstractionLayer","infoRaw","sleep_pin","getUint8","dip1_pin","intb_pin","state_flags","id_reg","config_reg","global_brightness","display_width","display_height","timeout_ms","getUint32","version_major","version_minor","disableSleep","disableDeepSleep","disableSleepTimer","enableDeepSleep","enableSleepTimer","milliseconds","view","DataView","ArrayBuffer","setInt32","reboot","mode","drawMatrix","drawPixel","drawLine","r1","c1","r2","c2","SparkleController","detectSerial","detectHID"],"mappings":"2PAAY,MAECA,EAAM,MACNC,EAAU,CAAC,GAAM,KAKjBC,EAAQC,OAAOC,OAAO,CACjC,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrB,EA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AAK0K,aAET,CAAE,MACA,OAAO,CACT,CACF,CAEA,aAAMhG,GACJ,MAAM1E,QAAahD,MAAMgD,OAEzB,OAA0BwF,MAAtBxF,EAAK8K,eACkBtF,MAAtBxF,EAAK+K,gBACJ/K,EAAK8K,cAAgB,GAAK9K,EAAK+K,cAAgB,GAC5C,CACLnG,MAAO5E,EAAK8K,cACZjG,MAAO7E,EAAK+K,eAIP,CAAEnG,MAAO,EAAGC,MAAO,EAE9B,wEfnDoB,+BgBGf,MACL,yBAAauH,GACX,MAAMJ,EAAK,IAAIhH,EACTkH,EAAK,IAAIvE,EAGf,aADMqE,EAAG9G,gBACC8G,EAAGzG,iBACJyG,SAGHE,EAAGhH,gBACCgH,EAAG3G,iBACJ2G,EAGF,KACT,CAEA,sBAAaG,GACX,MAAML,EAAK,IAAIG,EAGf,aADMH,EAAG9G,gBACC8G,EAAGzG,iBACJyG,EAGF,IACT,ShB3BiB,aACI,CAAC,EAAM,2HALT,0EU2Ed1O,uBACW2K,GAClB,yBTQO3K,uBACWC,GAClB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "led-matrix-controllers",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/jpadgett314/led-matrix-controllers.git"
@@ -5,6 +5,7 @@ export const VID_ARR = [0x32, 0xAC];
5
5
  export const PID = 0x0020;
6
6
  export const PID_ARR = [0x00, 0x20];
7
7
 
8
+ // For PWM dimming (not for analog dimming/constant-current reduction!)
8
9
  export const GAMMA = Object.freeze([
9
10
  0, 0, 0, 0, 0, 0, 0, 1,
10
11
  1, 1, 1, 1, 1, 1, 1, 1,
package/src/index.js CHANGED
@@ -3,3 +3,5 @@ export * from './HardwareControllerFactory.js';
3
3
  export * from './supported-firmware/FrameworkComputer/inputmodule-rs/DefaultController.js';
4
4
  export * from './supported-firmware/sigroot/FW_LED_Matrix_Firmware/SigrootController.js'
5
5
  export * from './supported-firmware/vddCore/sparkle-fw16/SparkleController.js';
6
+ export * from './web-hid/device.js';
7
+ export * from './web-serial/port.js';
@@ -1,4 +1,4 @@
1
- import { HEIGHT, VID_ARR, WIDTH } from '../../../hardware-constants.js';
1
+ import { GAMMA, HEIGHT, VID_ARR, WIDTH } from '../../../hardware-constants.js';
2
2
  import { Command, RX_PACKET_SZ } from './commands.js';
3
3
 
4
4
  export class CommandAbstractionLayer {
@@ -44,7 +44,7 @@ export class CommandAbstractionLayer {
44
44
  // Transpose & Gamma Correction
45
45
  const buffers = Array.from(
46
46
  { length: WIDTH },
47
- (_, c) => new Array(
47
+ (_, c) => Array.from(
48
48
  { length: HEIGHT },
49
49
  (_, r) => GAMMA[Math.floor((matrix[r][c] ?? 0) * 255)]
50
50
  )
@@ -1,7 +1,8 @@
1
- import { close, getPort } from '../../../web-serial/port.js';
1
+ import { close, getUnusedPort } from '../../../web-serial/port.js';
2
2
  import { PortMutex } from '../../../web-serial/PortMutex.js';
3
3
  import { PortOperations } from '../../../web-serial/PortOperations.js';
4
4
  import { CommandAbstractionLayer } from './CommandAbstractionLayer.js';
5
+ import { BitDepth } from './commands.js';
5
6
 
6
7
  export class DefaultController extends CommandAbstractionLayer {
7
8
  async bootloader() {
@@ -9,25 +10,30 @@ export class DefaultController extends CommandAbstractionLayer {
9
10
  }
10
11
 
11
12
  async connect() {
12
- const port = await getPort();
13
+ const port = await getUnusedPort();
13
14
 
14
15
  if (port?.connected) {
15
16
  await close(port);
16
17
  await port.open({ baudRate: 115200 });
17
18
  this.portMutex = new PortMutex(new PortOperations(port));
19
+ } else {
20
+ throw new Error('No Port Found');
18
21
  }
19
22
  }
20
23
 
21
24
  async draw(matrix) {
22
- switch (this.#bitDepth) {
25
+ switch (this.bitDepth ?? BitDepth.MONO_1BIT) {
23
26
 
24
- case BitDepth.GRAY_8BIT:
27
+ case (BitDepth.GRAY_8BIT):
25
28
  super.drawGrayscale(matrix);
26
29
  break;
27
30
 
28
- case BitDepth.MONO_1BIT:
31
+ case (BitDepth.MONO_1BIT):
29
32
  super.draw(matrix);
30
33
  break;
34
+
35
+ default:
36
+ console.error(`Unsupported bitdepth: ${this.bitDepth}`);
31
37
  }
32
38
  }
33
39
 
@@ -49,6 +55,4 @@ export class DefaultController extends CommandAbstractionLayer {
49
55
  async version() {
50
56
  return super.version();
51
57
  }
52
-
53
- #bitDepth;
54
58
  }
@@ -1,4 +1,4 @@
1
- import { close, getPort } from '../../../web-serial/port.js';
1
+ import { close, getUnusedPort } from '../../../web-serial/port.js';
2
2
  import { PortMutex } from '../../../web-serial/PortMutex.js';
3
3
  import { PortOperations } from '../../../web-serial/PortOperations.js';
4
4
  import { CommandAbstractionLayer } from './CommandAbstractionLayer.js';
@@ -10,7 +10,7 @@ export class SigrootController extends CommandAbstractionLayer {
10
10
  }
11
11
 
12
12
  async connect() {
13
- const port = await getPort();
13
+ const port = await getUnusedPort();
14
14
 
15
15
  if (port?.connected) {
16
16
  await close(port);
@@ -23,6 +23,8 @@ export class SigrootController extends CommandAbstractionLayer {
23
23
  if (!this.#scaleInitialized) {
24
24
  await super.setGlobalAnalog(0x20);
25
25
  this.#scaleInitialized = true;
26
+ } else {
27
+ throw new Error('No Port Found');
26
28
  }
27
29
 
28
30
  await super.setMatrixPwm(matrix);
@@ -1,5 +1,5 @@
1
1
  import { HEIGHT, WIDTH } from '../../../hardware-constants.js';
2
- import { getDevice } from '../../../web-hid/device.js';
2
+ import { getUnusedDevice } from '../../../web-hid/device.js';
3
3
  import { HIDOperations } from '../../../web-hid/HIDOperations.js';
4
4
  import { ReportAbstractionLayer } from './ReportAbstractionLayer.js';
5
5
  import { BootMode } from './reports.js';
@@ -10,10 +10,13 @@ export class SparkleController extends ReportAbstractionLayer {
10
10
  }
11
11
 
12
12
  async connect() {
13
- const device = await getDevice();
13
+ const device = await getUnusedDevice();
14
+
14
15
  if (device) {
15
16
  await device.open();
16
17
  this.device = new HIDOperations(device);
18
+ } else {
19
+ throw new Error('No Device Found');
17
20
  }
18
21
  }
19
22
 
@@ -35,6 +38,7 @@ export class SparkleController extends ReportAbstractionLayer {
35
38
 
36
39
  async version() {
37
40
  const info = await super.info();
41
+
38
42
  if (info.version_major != undefined
39
43
  && info.version_minor != undefined
40
44
  && (info.version_major > 0 || info.version_minor > 0)) {
@@ -1,13 +1,6 @@
1
1
  import { PID, VID } from '../hardware-constants.js';
2
2
 
3
- const extraDevices = [];
4
-
5
- const filters = [
6
- {
7
- vendorId: VID,
8
- productId: PID,
9
- }
10
- ];
3
+ const filters = [{ vendorId: VID, productId: PID }];
11
4
 
12
5
  export class DeviceSelectionCancelled extends Error {
13
6
  constructor() {
@@ -17,20 +10,77 @@ export class DeviceSelectionCancelled extends Error {
17
10
  }
18
11
  }
19
12
 
20
- export async function getDevice() {
21
- if (extraDevices && extraDevices.length > 0) {
22
- return extraDevices.pop();
13
+ async function requestDevice() {
14
+ try {
15
+ if (navigator.serial.requestPort) {
16
+ return await navigator.serial.requestDevice({ filters });
17
+ } else {
18
+ return null; // Web Worker
19
+ }
20
+ } catch (e) {
21
+ switch (e.name) {
22
+ case ('NotFoundError'):
23
+ throw new DeviceSelectionCancelled();
24
+ case ('SecurityError'): // No user gesture
25
+ return null;
26
+ default:
27
+ throw e;
28
+ }
23
29
  }
30
+ }
31
+
32
+ class KnownDevices {
33
+ used = new Set();
34
+ unused = [];
35
+
36
+ async getOrFetchUnused() {
37
+ let device = this.unused.pop();
38
+
39
+ if (!device) {
40
+ const systemDevices = await navigator.hid.getDevices({ filters });
41
+ this.#enqueueUnique(systemDevices);
42
+ device = this.unused.pop();
43
+ }
24
44
 
25
- extraDevices.push(...(await navigator.hid.getDevices()));
26
- if (extraDevices && extraDevices.length > 0) {
27
- return extraDevices.pop();
45
+ if (!device) {
46
+ const manualDevices = await requestDevice();
47
+ this.#enqueueUnique([manualDevices]);
48
+ device = this.unused.pop();
49
+ }
50
+
51
+ if (device) {
52
+ this.used.add(device);
53
+ }
54
+
55
+ return device;
28
56
  }
29
57
 
30
- extraDevices.push(...(await navigator.hid.requestDevice({ filters })));
31
- if (extraDevices && extraDevices.length > 0) {
32
- return extraDevices.pop();
58
+ #enqueueUnique(devices) {
59
+ if (devices) {
60
+ for (const dev of devices) {
61
+ if (dev && !this.used.has(dev) && !this.unused.includes(dev)) {
62
+ this.unused.push(dev);
63
+ }
64
+ }
65
+ }
33
66
  }
67
+ }
68
+
69
+ const knownDevices = new KnownDevices();
70
+
71
+ /**
72
+ * Adds user-selected device to permitted device. Only for use outside of Web
73
+ * Worker to establish permission for use within Web Worker.
74
+ * @returns {null}
75
+ */
76
+ export async function reqestDeviceForWorker() {
77
+ const _ = await requestDevice();
78
+ }
34
79
 
35
- throw new DeviceSelectionCancelled();
80
+ /**
81
+ * Never returns the same device twice.
82
+ * @returns {(HIDDevice|null)}
83
+ */
84
+ export async function getUnusedDevice() {
85
+ return await knownDevices.getOrFetchUnused();
36
86
  }
@@ -22,7 +22,7 @@ export class PortMutex {
22
22
  async acquireIdempotent(key, fn) {
23
23
  const trace = new Error('created bad cb').stack;
24
24
 
25
- if (this.#deduper.has(key)) {
25
+ if (this.#deduper.has(key)) {
26
26
  console.info(`"${key}" request coalesced.`);
27
27
  }
28
28
 
@@ -1,13 +1,6 @@
1
1
  import { PID, VID } from '../hardware-constants.js';
2
2
 
3
- const extraPorts = [];
4
-
5
- const filters = [
6
- {
7
- usbVendorId: VID,
8
- usbProductId: PID,
9
- }
10
- ];
3
+ const filters = [{ usbVendorId: VID, usbProductId: PID }];
11
4
 
12
5
  export class PortSelectionCancelled extends Error {
13
6
  constructor() {
@@ -25,39 +18,93 @@ export class PortUnavailable extends Error {
25
18
  }
26
19
  }
27
20
 
28
- export async function getPort() {
21
+ async function requestPort() {
29
22
  try {
30
- if (extraPorts && extraPorts.length > 0) {
31
- return extraPorts.pop();
23
+ if (navigator.serial.requestPort) {
24
+ return await navigator.serial.requestPort({ filters });
25
+ } else {
26
+ return null; // Web Worker
27
+ }
28
+ } catch (e) {
29
+ switch (e.name) {
30
+ case ('NotFoundError'):
31
+ throw new PortSelectionCancelled();
32
+ case ('InvalidStateError'):
33
+ throw new PortUnavailable();
34
+ case ('SecurityError'): // No user gesture
35
+ return null;
36
+ default:
37
+ throw e;
32
38
  }
39
+ }
40
+ }
33
41
 
34
- extraPorts.push(...(await navigator.serial.getPorts()));
35
- if (extraPorts && extraPorts.length > 0) {
36
- return extraPorts.pop();
42
+ class KnownPorts {
43
+ used = new Set();
44
+ unused = [];
45
+
46
+ async getOrFetchUnused() {
47
+ let port = this.unused.pop();
48
+
49
+ if (!port) {
50
+ const systemPorts = await navigator.serial.getPorts({ filters });
51
+ this.#enqueueUnique(systemPorts);
52
+ port = this.unused.pop();
37
53
  }
38
54
 
39
- extraPorts.push(...(await navigator.serial.requestPort({ filters })));
40
- if (extraPorts && extraPorts.length > 0) {
41
- return extraPorts.pop();
55
+ if (!port) {
56
+ const manualPort = await requestPort();
57
+ this.#enqueueUnique([manualPort]);
58
+ port = this.unused.pop();
42
59
  }
43
60
 
44
- } catch (e) {
45
- if (e.name == 'NotFoundError') {
46
- throw new PortSelectionCancelled();
47
- } else if (e.name == 'InvalidStateError') {
48
- throw new PortUnavailable();
49
- } else {
50
- throw e;
61
+ if (port) {
62
+ this.used.add(port);
63
+ }
64
+
65
+ return port;
66
+ }
67
+
68
+ #enqueueUnique(ports) {
69
+ if (ports) {
70
+ for (const port of ports) {
71
+ if (port && !this.used.has(port) && !this.unused.includes(port)) {
72
+ this.unused.push(port);
73
+ }
74
+ }
51
75
  }
52
76
  }
53
77
  }
54
78
 
79
+ const knownPorts = new KnownPorts();
80
+
81
+ /**
82
+ * Adds user-selected port to permitted ports. Only for use outside of Web
83
+ * Worker to establish permission for use within Web Worker.
84
+ * @returns {null}
85
+ */
86
+ export async function requestPortForWorker() {
87
+ const _ = await requestPort();
88
+ }
89
+
90
+ /**
91
+ * Never returns the same port twice.
92
+ * @returns {(SerialPort|null)}
93
+ */
94
+ export async function getUnusedPort() {
95
+ return await knownPorts.getOrFetchUnused();
96
+ }
97
+
98
+ /**
99
+ * Close port without throwing if already closed.
100
+ * @param {SerialPort} port
101
+ */
55
102
  export async function close(port) {
56
103
  try {
57
104
  await port.close();
58
105
  } catch(e) {
59
106
  if (e.name != 'InvalidStateError') {
60
- if (e.message != "Failed to execute 'close' on 'SerialPort': The port is already closed.") {
107
+ if (e.message.includes('The port is already closed')) {
61
108
  throw e;
62
109
  }
63
110
  }