led-matrix-controllers 0.2.1 → 0.2.3

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.
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2025 Jacob Padgett
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Jacob Padgett
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,84 +1,81 @@
1
- # LED Matrix Controllers
2
-
3
- Cross-firmware controllers for the [Framework Laptop 16 LED matrix module](https://frame.work/products/16-led-matrix) using WebHID and Web Serial APIs
4
-
5
- ## Supported Firmwares
6
-
7
- - https://github.com/FrameworkComputer/inputmodule-rs (Out-of-box default)
8
- - https://github.com/vddCore/sparkle-fw16
9
- - https://github.com/sigroot/FW_LED_Matrix_Firmware
10
-
11
- If you maintain another firmware or a fork, please open an issue or submit a PR!
12
-
13
- ## Quick Start
14
-
15
- ### Installation
16
-
17
- #### Browser
18
-
19
- ```html
20
- <script type="module">
21
- import { DefaultController } from 'https://esm.sh/led-matrix-controllers@latest';
22
- const controller = new DefaultController();
23
- await controller.connect();
24
- // ...
25
- </script>
26
- ```
27
-
28
- #### Node.js
29
-
30
- ```bash
31
- npm install led-matrix-controllers
32
- ```
33
-
34
- Also see [examples/webpack/](examples/webpack/)
35
-
36
- ### Usage
37
-
38
- #### For specific firmware
39
-
40
- ```js
41
- // Controllers for specific firmware
42
- import { DefaultController, SigrootController, SparkleController } from 'led-matrix-controllers';
43
-
44
- const controller = new DefaultController();
45
- await controller.connect();
46
- await controller.draw( /* 34x9 matrix array */ );
47
- ```
48
-
49
- Also see [examples/sparkle.html](examples/sparkle.html)
50
-
51
- #### For specific interface
52
-
53
- ```js
54
- import { HardwareControllerFactory } from 'led-matrix-controllers';
55
-
56
- // connect to device
57
- const foo = HardwareControllerFactory.detectSerial();
58
- const bar = HardwareControllerFactory.detectHID();
59
- ```
60
-
61
- Also see [examples/detect-firmware.html](examples/detect-firmware.html)
62
-
63
- ## Development
64
-
65
- ### Prerequisites
66
-
67
- * **Node.js** (v16.9.0 or later recommended for corepack)
68
-
69
- ### Installation
70
-
71
- Setup development environment
72
-
73
- ```bash
74
- npm install -g corepack
75
- corepack enable
76
- yarn set version stable
77
- yarn install
78
- ```
79
-
80
- Bundle (optional)
81
-
82
- ```bash
83
- yarn build
84
- ```
1
+ # LED Matrix Controllers
2
+
3
+ Cross-firmware controllers for the [Framework Laptop 16 LED matrix module](https://frame.work/products/16-led-matrix) using WebHID and Web Serial APIs
4
+
5
+ ## Supported Firmwares
6
+
7
+ - https://github.com/FrameworkComputer/inputmodule-rs (Out-of-box default)
8
+ - https://github.com/vddCore/sparkle-fw16
9
+ - https://github.com/sigroot/FW_LED_Matrix_Firmware
10
+
11
+ If you maintain another firmware or a fork, please open an issue or submit a PR!
12
+
13
+ ## Quick Start
14
+
15
+ ### Installation
16
+
17
+ #### Browser
18
+
19
+ ```html
20
+ <script type="module">
21
+ import { DefaultController } from 'https://esm.sh/led-matrix-controllers@latest';
22
+ const controller = new DefaultController();
23
+ await controller.connect();
24
+ // ...
25
+ </script>
26
+ ```
27
+
28
+ #### Node.js
29
+
30
+ ```bash
31
+ npm install led-matrix-controllers
32
+ ```
33
+
34
+ Also see [examples/webpack/](examples/webpack/)
35
+
36
+ ### Usage
37
+
38
+ #### For specific firmware
39
+
40
+ ```js
41
+ // Controllers for specific firmware
42
+ import { DefaultController, SigrootController, SparkleController } from 'led-matrix-controllers';
43
+
44
+ const controller = new DefaultController();
45
+ await controller.connect();
46
+ await controller.draw( /* 34x9 matrix array */ );
47
+ ```
48
+
49
+ Also see [examples/sparkle.html](examples/sparkle.html)
50
+
51
+ #### For specific interface
52
+
53
+ ```js
54
+ import { HardwareControllerFactory } from 'led-matrix-controllers';
55
+
56
+ // connect to device
57
+ const foo = HardwareControllerFactory.detectSerial();
58
+ const bar = HardwareControllerFactory.detectHID();
59
+ ```
60
+
61
+ Also see [examples/detect-firmware.html](examples/detect-firmware.html)
62
+
63
+ ## Development
64
+
65
+ ### Prerequisites
66
+
67
+ * **Node.js** (v18 or later)
68
+
69
+ ### Installation
70
+
71
+ Setup development environment
72
+
73
+ ```bash
74
+ npm install
75
+ ```
76
+
77
+ Bundle (optional)
78
+
79
+ ```bash
80
+ npm run build
81
+ ```
@@ -1,2 +1,2 @@
1
- const e=9,t=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 u(){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(e){throw"NotFoundError"==e.name?new l:"InvalidStateError"==e.name?new d:e}}async function w(e){try{await e.close()}catch(e){if("InvalidStateError"!=e.name&&"Failed to execute 'close' on 'SerialPort': The port is already closed."!=e.message)throw e}}class h{constructor(e){this.#e=`port-mutex-${Math.random().toString()}`,this.#t=new Map,this.#a=e}async acquire(e){const t=new Error("created bad cb").stack;await this.#r(async()=>{try{await e(this.#a)}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.#t.has(e)&&console.info(`"${e}" request coalesced.`),this.#t.set(e,async()=>{try{await t(this.#a)}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.#r(()=>this.#i(e))}async#r(e){return navigator.locks.request(this.#e,e)}async#i(e){if(this.#t.has(e)){const t=this.#t.get(e);this.#t.delete(e),await t()}}#e;#t;#a}class p{constructor(e){this.#n=e}async rx(e,t=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(),t);try{for(;a.length<e;){const{value:e,done:t}=await r.read();if(a.push(...e??[]),t||!e)break}}finally{clearTimeout(i),r.releaseLock()}return a}async tx(e){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 t=this.#n.writable.getWriter();try{await t.write(new Uint8Array(e))}finally{await t.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 _=class{constructor(e=null){this.portMutex=e}async bootloader(){await this.portMutex.acquire(async e=>{await e.tx([...r,y.BOOTLOADER])})}async draw(e){let t=0,a=new Uint8Array(39).fill(0);for(let r=0;r<34;r++)for(let i=0;i<9;i++)e[r][i]&&(a[t>>3]|=1<<t%8),t++;await this.portMutex.acquireIdempotent("drawMatrix",async e=>{await e.tx([...r,y.DRAW,...a])})}async drawGrayscale(e){const t=Array.from({length:9},(t,a)=>new Array({length:34},(t,r)=>GAMMA[Math.floor(255*(e[r][a]??0))]));await this.portMutex.acquireIdempotent("drawMatrix",async e=>{for(let a=0;a<9;a++)await e.tx([y.STAGE_GREY_COL,a,...t[a]]);await e.tx([y.DRAW_GREY_COL_BUFFER])})}async version(){let e={};return await this.portMutex.acquire(async t=>{await t.tx([...r,y.VERSION]);const a=await t.rx(32);e.major=a[0],e.minor=a[1]>>4,e.patch=15&a[1],e.preRelease=1==a[2]}),e}};class A extends _{async bootloader(){return super.bootloader()}async connect(){const e=await u();e?.connected&&(await w(e),await e.open({baudRate:115200}),this.portMutex=new h(new p(e)))}async draw(e){switch(this.#s){case BitDepth.GRAY_8BIT:super.drawGrayscale(e);break;case BitDepth.MONO_1BIT:super.draw(e)}}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()}#s}const m=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}),E=/^Sig\sFW\sLED\sMatrix\sFW\sV(\d+)\.(\d+)$/;class f{constructor(e=null){this.portMutex=e}async bootloader(){await this.portMutex.acquire(async e=>{await e.tx([m.BOOTLOADER])})}async identityString(){let e=null;return await this.portMutex.acquire(async t=>{await t.tx([m.IDENTITY_STRING]),e=await t.rx(25)}),String.fromCharCode(...e)}async setPixelPwm(e,t,a){await this.portMutex.acquire(async r=>{await r.tx([m.SET_PX_PWM,t,e,a])})}async setGlobalPwm(e){await this.portMutex.acquire(async t=>{await t.tx([m.SET_CONST_PWM,e])})}async setMatrixPwm(e){await this.portMutex.acquireIdempotent("drawMatrix",async t=>{await t.tx([m.DRAW_PWM].concat(e.flat().map(e=>s[Math.floor(255*(e??0))])))})}async setPixelAnalog(e,t,a){await this.portMutex.acquire(async r=>{await r.tx([m.SET_PX_SCALE,t,e,a])})}async setGlobalAnalog(e){await this.portMutex.acquire(async t=>{await t.tx([m.SET_CONST_SCALE,e])})}async setMatrixAnalog(e){await this.portMutex.acquireIdempotent("drawMatrix",async t=>{await t.tx([m.DRAW_SCALE].concat(e.flat().map(e=>s[Math.floor(255*(e??0))])))})}}class T extends f{async bootloader(){await super.bootloader()}async connect(){const e=await u();e?.connected&&(await w(e),await e.open({baudRate:115200}),this.portMutex=new h(new p(e)))}async draw(e){this.#o||(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(E);return e&&3==e.length?{major:e[1],minor:e[2]}:null}#o}const g=[],b=[{vendorId:a,productId:32}];class x extends Error{constructor(){super("User cancelled device selection."),this.name=this.constructor.name,this.date=new Date}}class M{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 v={id:1,bytes:307,feature:!0},I={id:2,bytes:16,feature:!0},S={id:4,bytes:306,feature:!0},O=0,R=1,N=2,D=3,P=5,U=0;class G{constructor(e=null){this.device=e}async info(){const e=await this.device.request(v);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(I,[R,!1])}async sleep(){await this.device.send(I,[R,!0])}async disableSleep(){await this.device.send(I,[D,255,255,255,255])}async disableDeepSleep(){await this.device.send(I,[N,1])}async disableSleepTimer(){await this.device.send(I,[D,0,0,0,0])}async enableDeepSleep(){await this.device.send(I,[N,0])}async enableSleepTimer(e){const t=new DataView(new ArrayBuffer(4));t.setInt32(0,e,!1),await this.device.send(I,[D,t.getUint8(0),t.getUint8(1),t.getUint8(2),t.getUint8(3)])}async reboot(e){await this.device.send(I,[O,e])}async drawMatrix(e){await this.device.send(S,e.flat().map(e=>s[Math.floor(255*(e??0))]))}async drawPixel(e,t,a){await this.device.send(I,[P,t,e,a])}async drawLine({r1:e,c1:t},{r2:a,c2:r},i){await this.device.send(I,[P,e,t,a,r,i])}device}class L extends G{async bootloader(){await super.reboot(U)}async connect(){const e=await async function(){if(g&&g.length>0)return g.pop();if(g.push(...await navigator.hid.getDevices()),g&&g.length>0)return g.pop();if(g.push(...await navigator.hid.requestDevice({filters:b})),g&&g.length>0)return g.pop();throw new x}();e&&(await e.open(),this.device=new M(e))}async draw(e){await super.drawMatrix(e)}async verifyFirmware(){try{const e=await super.info();return e.display_height==HEIGHT&&e.display_width==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}}}class C{static async detectSerial(){const e=new A,t=new T;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}}export{A as DefaultController,s as GAMMA,t as HEIGHT,C as HardwareControllerFactory,i as PID,n as PID_ARR,T as SigrootController,L as SparkleController,a as VID,r as VID_ARR,e 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=[],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};
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;\r\nexport const HEIGHT = 34;\r\nexport const VID = 0x32AC;\r\nexport const VID_ARR = [0x32, 0xAC];\r\nexport const PID = 0x0020;\r\nexport const PID_ARR = [0x00, 0x20];\r\n\r\nexport const GAMMA = Object.freeze([\r\n 0, 0, 0, 0, 0, 0, 0, 1, \r\n 1, 1, 1, 1, 1, 1, 1, 1, \r\n 1, 1, 1, 1, 1, 1, 1, 1, \r\n 1, 1, 1, 1, 1, 1, 1, 1, \r\n 1, 1, 1, 2, 2, 2, 2, 2, \r\n 2, 2, 2, 2, 3, 3, 3, 3, \r\n 3, 3, 3, 4, 4, 4, 4, 4, \r\n 4, 5, 5, 5, 5, 6, 6, 6, \r\n 6, 6, 7, 7, 7, 7, 8, 8, \r\n 8, 9, 9, 9, 10, 10, 10, 11, \r\n 11, 11, 12, 12, 12, 13, 13, 14, \r\n 14, 14, 15, 15, 16, 16, 17, 17, \r\n 17, 18, 18, 19, 19, 20, 20, 21, \r\n 22, 22, 23, 23, 24, 24, 25, 26, \r\n 26, 27, 27, 28, 29, 29, 30, 31, \r\n 32, 32, 33, 34, 34, 35, 36, 37, \r\n 38, 38, 39, 40, 41, 42, 42, 43, \r\n 44, 45, 46, 47, 48, 49, 50, 51, \r\n 52, 53, 54, 55, 56, 57, 58, 59, \r\n 60, 61, 62, 63, 64, 66, 67, 68, \r\n 69, 70, 71, 73, 74, 75, 76, 78, \r\n 79, 80, 82, 83, 84, 86, 87, 88, \r\n 90, 91, 93, 94, 96, 97, 99, 100, \r\n 102, 103, 105, 106, 108, 110, 111, 113, \r\n 115, 116, 118, 120, 121, 123, 125, 127, \r\n 128, 130, 132, 134, 136, 138, 140, 141, \r\n 143, 145, 147, 149, 151, 153, 155, 157, \r\n 159, 161, 164, 166, 168, 170, 172, 174, \r\n 177, 179, 181, 183, 186, 188, 190, 193, \r\n 195, 197, 200, 202, 205, 207, 210, 212, \r\n 215, 217, 220, 222, 225, 228, 230, 233, \r\n 236, 238, 241, 244, 247, 249, 252, 255\r\n]);\r\n","import { PID, VID } from '../hardware-constants.js';\r\n\r\nconst extraPorts = [];\r\n\r\nconst filters = [\r\n {\r\n usbVendorId: VID,\r\n usbProductId: PID,\r\n }\r\n];\r\n\r\nexport class PortSelectionCancelled extends Error {\r\n constructor() {\r\n super('User cancelled port selection.');\r\n this.name = this.constructor.name;\r\n this.date = new Date();\r\n }\r\n}\r\n\r\nexport class PortUnavailable extends Error {\r\n constructor() {\r\n super('Selected port already in use.');\r\n this.name = this.constructor.name;\r\n this.date = new Date();\r\n }\r\n}\r\n\r\nexport async function getPort() {\r\n try {\r\n if (extraPorts && extraPorts.length > 0) {\r\n return extraPorts.pop();\r\n }\r\n\r\n extraPorts.push(...await navigator.serial.getPorts());\r\n if (extraPorts && extraPorts.length > 0) {\r\n return extraPorts.pop();\r\n }\r\n\r\n extraPorts.push(...await navigator.serial.requestPort({ filters }));\r\n if (extraPorts && extraPorts.length > 0) {\r\n return extraPorts.pop();\r\n }\r\n\r\n } catch (e) {\r\n if (e.name == 'NotFoundError') {\r\n throw new PortSelectionCancelled();\r\n } else if (e.name == 'InvalidStateError') {\r\n throw new PortUnavailable();\r\n } else {\r\n throw e;\r\n }\r\n }\r\n}\r\n\r\nexport async function close(port) {\r\n try {\r\n await port.close();\r\n } catch(e) {\r\n if (e.name != 'InvalidStateError') {\r\n if (e.message != \"Failed to execute 'close' on 'SerialPort': The port is already closed.\") {\r\n throw e;\r\n }\r\n }\r\n }\r\n}\r\n","export class PortMutex {\r\n constructor(portOperations) {\r\n this.#lockName = `port-mutex-${Math.random().toString()}`;\r\n this.#deduper = new Map();\r\n this.#portOps = portOperations;\r\n }\r\n\r\n async acquire(fn) {\r\n const trace = new Error('created bad cb').stack;\r\n\r\n await this.#enqueue(async () => {\r\n try {\r\n await fn(this.#portOps);\r\n } catch (e) {\r\n console.error('Error occured in anonymous callback.');\r\n console.error('Original error:', e);\r\n console.error('--- This callback was created at ---\\n', trace);\r\n }\r\n });\r\n }\r\n\r\n async acquireIdempotent(key, fn) {\r\n const trace = new Error('created bad cb').stack;\r\n\r\n if (this.#deduper.has(key)) {\r\n console.info(`\"${key}\" request coalesced.`);\r\n }\r\n\r\n this.#deduper.set(key, async () => {\r\n try {\r\n await fn(this.#portOps);\r\n } catch (e) {\r\n console.error('Error occured in anonymous callback.');\r\n console.error('Original error:', e);\r\n console.error('--- This callback was created at ---\\n', trace);\r\n }\r\n });\r\n\r\n await this.#enqueue(() => this.#execDedupedOp(key));\r\n }\r\n\r\n async #enqueue(fn) {\r\n // `navigator.locks` maintains queue and provides mutual exclusion.\r\n return navigator.locks.request(this.#lockName, fn);\r\n }\r\n\r\n async #execDedupedOp(key) {\r\n if (this.#deduper.has(key)) {\r\n const fn = this.#deduper.get(key);\r\n this.#deduper.delete(key);\r\n await fn();\r\n }\r\n }\r\n\r\n #lockName;\r\n #deduper;\r\n #portOps;\r\n}\r\n","export class PortOperations {\r\n constructor(port) {\r\n this.#port = port;\r\n }\r\n\r\n async rx(length, timeout=3000) {\r\n if (this.#port === null) {\r\n throw new Error('attempted RX before port initialization.');\r\n }\r\n\r\n /*\r\n * ReadableStream's built-in locking mechanism cannot be awaited or otherwise\r\n * asynchronously acquired. A PortMutex must be used.\r\n */\r\n if (this.#port.readable.locked) {\r\n throw new Error('attempted RX while port locked.');\r\n }\r\n\r\n const response = [];\r\n const reader = this.#port.readable.getReader();\r\n const timeoutHandle = setTimeout(() => reader.cancel(), timeout);\r\n\r\n try {\r\n // Response may be divided across multiple reads\r\n while (response.length < length) {\r\n const { value, done } = await reader.read();\r\n response.push(...(value ?? []));\r\n if (done || !value) break;\r\n }\r\n } finally {\r\n clearTimeout(timeoutHandle);\r\n reader.releaseLock();\r\n }\r\n\r\n return response;\r\n }\r\n\r\n async tx(buffer) {\r\n if (this.#port === null) {\r\n throw new Error('attempted TX before port initialization.');\r\n }\r\n \r\n /*\r\n * WritableStream's built-in locking mechanism cannot be awaited or otherwise\r\n * asynchronously acquired. A PortMutex must be used.\r\n */\r\n if (this.#port.writable.locked) {\r\n throw new Error('attempted TX while port locked.');\r\n }\r\n\r\n const writer = this.#port.writable.getWriter();\r\n\r\n try {\r\n await writer.write(new Uint8Array(buffer));\r\n } finally {\r\n /* \r\n * The writer must be completely torn down between every single write.\r\n * Many parsers can't handle delayed flushing and write coalescing.\r\n * Command sequences will fail if `releaseLock()` is used here.\r\n */\r\n await writer.close();\r\n }\r\n }\r\n\r\n #port;\r\n}\r\n","// All replies to all commands are 32 bytes\r\nexport const RX_PACKET_SZ = 32;\r\n\r\nexport const Command = Object.freeze({\r\n ANIMATE: 0x04,\r\n BRIGHTNESS: 0x00,\r\n BOOTLOADER: 0x02,\r\n DRAW: 0x06,\r\n DRAW_GREY_COL_BUFFER: 0x08,\r\n GAME_CTRL: 0x11,\r\n GAME_STATUS: 0x12,\r\n PANIC: 0x05,\r\n PATTERN: 0x01,\r\n SLEEP: 0x03,\r\n STAGE_GREY_COL: 0x07,\r\n START_GAME: 0x10,\r\n VERSION: 0x20,\r\n});\r\n\r\n// Used with Command.PATTERN\r\nexport const Pattern = Object.freeze({\r\n DISPLAY_LOTUS_HORIZONTAL: 0x03,\r\n DISPLAY_LOTUS_VERTICAL: 0x07,\r\n DISPLAY_PANIC: 0x06,\r\n DOUBLE_GRADIENT: 0x02,\r\n FULL_BRIGHTNESS: 0x05,\r\n GRADIENT: 0x01,\r\n PERCENTAGE: 0x00,\r\n ZIG_ZAG: 0x04,\r\n});\r\n\r\n// DRAW or DRAW_GREY_COL_BUFFER\r\nexport const BitDepth = Object.freeze({\r\n GRAY_8BIT: '8-bit',\r\n MONO_1BIT: '1-bit',\r\n})\r\n","import { HEIGHT, VID_ARR, WIDTH } from '../../../hardware-constants.js';\r\nimport { Command, RX_PACKET_SZ } from './commands.js';\r\n\r\nexport class CommandAbstractionLayer {\r\n constructor(portMutex = null) {\r\n this.portMutex = portMutex;\r\n }\r\n\r\n async bootloader() {\r\n await this.portMutex.acquire(async p => {\r\n await p.tx([...VID_ARR, Command.BOOTLOADER]);\r\n });\r\n }\r\n\r\n async draw(matrix) {\r\n let index = 0;\r\n let output = new Uint8Array(39).fill(0);\r\n\r\n // Pack cells into bits\r\n for (let r = 0; r < HEIGHT; r++) {\r\n for (let c = 0; c < WIDTH; c++) {\r\n if (matrix[r][c]) {\r\n output[index >> 3] |= 1 << index % 8;\r\n }\r\n index++;\r\n }\r\n }\r\n\r\n await this.portMutex.acquireIdempotent(\r\n 'drawMatrix', \r\n async p => {\r\n await p.tx([...VID_ARR, Command.DRAW, ...output]);\r\n }\r\n );\r\n }\r\n\r\n async drawGrayscale(matrix) {\r\n // Transpose & Gamma Correction\r\n const buffers = Array.from(\r\n { length: WIDTH }, \r\n (_, c) => new Array(\r\n { length: HEIGHT }, \r\n (_, r) => GAMMA[Math.floor((matrix[r][c] ?? 0) * 255)]\r\n )\r\n );\r\n\r\n // Only execute the most recent call \r\n await this.portMutex.acquireIdempotent(\r\n 'drawMatrix', \r\n async p => {\r\n for (let i = 0; i < WIDTH; i++) {\r\n await p.tx([Command.STAGE_GREY_COL, i, ...buffers[i]]);\r\n }\r\n await p.tx([Command.DRAW_GREY_COL_BUFFER]);\r\n }\r\n );\r\n }\r\n\r\n async version() {\r\n let ver = {};\r\n\r\n await this.portMutex.acquire(async p => {\r\n await p.tx([...VID_ARR, Command.VERSION]);\r\n const response = await p.rx(RX_PACKET_SZ);\r\n\r\n // MMMMMMMM mmmmPPPP 0000000p\r\n ver.major = response[0];\r\n ver.minor = response[1] >> 4;\r\n ver.patch = response[1] & 0x0F;\r\n ver.preRelease = response[2] == 1;\r\n });\r\n\r\n return ver;\r\n }\r\n}\r\n","import { close, getPort } from '../../../web-serial/port.js';\r\nimport { PortMutex } from '../../../web-serial/PortMutex.js';\r\nimport { PortOperations } from '../../../web-serial/PortOperations.js';\r\nimport { CommandAbstractionLayer } from './CommandAbstractionLayer.js';\r\n\r\nexport class DefaultController extends CommandAbstractionLayer {\r\n async bootloader() {\r\n return super.bootloader();\r\n }\r\n\r\n async connect() {\r\n const port = await getPort();\r\n\r\n if (port?.connected) {\r\n await close(port);\r\n await port.open({ baudRate: 115200 });\r\n this.portMutex = new PortMutex(new PortOperations(port));\r\n }\r\n }\r\n\r\n async draw(matrix) {\r\n switch (this.#bitDepth) {\r\n\r\n case BitDepth.GRAY_8BIT:\r\n super.drawGrayscale(matrix);\r\n break;\r\n\r\n case BitDepth.MONO_1BIT:\r\n super.draw(matrix);\r\n break;\r\n }\r\n }\r\n\r\n async verifyFirmware() {\r\n try {\r\n const version = await super.version();\r\n\r\n return version\r\n && version.major != undefined\r\n && version.minor != undefined\r\n && version.patch != undefined\r\n && version.preRelease != undefined;\r\n \r\n } catch {\r\n return false;\r\n }\r\n }\r\n\r\n async version() {\r\n return super.version();\r\n }\r\n\r\n #bitDepth;\r\n}\r\n","export const Command = Object.freeze({\r\n /* 000 */ NOOP: 0x00,\r\n /* 'd' */ ANIMATION_DIAMOND: 0x64,\r\n /* 'b' */ ANIMATION_FIRE: 0x62,\r\n /* 'f' */ ANIMATION_FIREPLACE: 0x66,\r\n /* 'g' */ ANIMATION_GEAR: 0x67,\r\n /* 'r' */ ANIMATION_RING: 0x72,\r\n /* 'a' */ ANIMATION_STARTUP: 0x61,\r\n /* 'A' */ ANIMATION_STARTUP_ONCE: 0x41,\r\n /* 'e' */ BOOTLOADER: 0x65,\r\n /* 'm' */ DRAW_PWM: 0x6D,\r\n /* 'M' */ DRAW_PWM_BLOCKING: 0x4D,\r\n /* 'n' */ DRAW_SCALE: 0x6E,\r\n /* 'N' */ DRAW_SCALE_BLOCKING: 0x4E,\r\n /* 'c' */ FLUSH_CMD_QUEUE: 0x63,\r\n /* 't' */ TEST_PATTERN: 0x74,\r\n /* 'w' */ SET_CONST_PWM: 0x77,\r\n /* 's' */ SET_CONST_SCALE: 0x73,\r\n /* 'p' */ SET_PX_PWM: 0x70,\r\n /* 'q' */ SET_PX_SCALE: 0x71,\r\n /* 127 */ IDENTITY_STRING: 0x7F,\r\n});\r\n\r\nexport const IDENTITY_STR_LEN = 25;\r\n\r\nexport const IDENTITY_STR_REGEX = /^Sig\\sFW\\sLED\\sMatrix\\sFW\\sV(\\d+)\\.(\\d+)$/;\r\n","import { GAMMA } from '../../../hardware-constants.js';\r\nimport { Command, IDENTITY_STR_LEN } from './commands.js';\r\n\r\nexport class CommandAbstractionLayer {\r\n constructor(portMutex = null) {\r\n this.portMutex = portMutex;\r\n }\r\n\r\n async bootloader() {\r\n await this.portMutex.acquire(async p => {\r\n await p.tx([Command.BOOTLOADER]);\r\n });\r\n }\r\n\r\n async identityString() {\r\n let ident = null;\r\n\r\n await this.portMutex.acquire(async p => {\r\n await p.tx([Command.IDENTITY_STRING]);\r\n ident = await p.rx(IDENTITY_STR_LEN);\r\n });\r\n\r\n return String.fromCharCode(...ident);\r\n }\r\n\r\n async setPixelPwm(r, c, brightness) {\r\n await this.portMutex.acquire(\r\n async p => {\r\n await p.tx([Command.SET_PX_PWM, c, r, brightness]);\r\n }\r\n );\r\n }\r\n\r\n async setGlobalPwm(brightness) {\r\n await this.portMutex.acquire(\r\n async p => {\r\n await p.tx([Command.SET_CONST_PWM, brightness]);\r\n }\r\n );\r\n }\r\n\r\n async setMatrixPwm(matrix) {\r\n // Only execute the most recent call \r\n await this.portMutex.acquireIdempotent(\r\n 'drawMatrix', \r\n async p => {\r\n await p.tx(\r\n [Command.DRAW_PWM].concat(\r\n matrix.flat().map(v => \r\n GAMMA[Math.floor((v ?? 0) * 255)]\r\n )\r\n )\r\n );\r\n }\r\n );\r\n }\r\n\r\n async setPixelAnalog(r, c, brightness) {\r\n await this.portMutex.acquire(\r\n async p => {\r\n await p.tx([Command.SET_PX_SCALE, c, r, brightness]);\r\n }\r\n );\r\n }\r\n\r\n async setGlobalAnalog(brightness) {\r\n await this.portMutex.acquire(\r\n async p => {\r\n await p.tx([Command.SET_CONST_SCALE, brightness]);\r\n }\r\n );\r\n }\r\n\r\n async setMatrixAnalog(matrix) {\r\n // Only execute the most recent call \r\n await this.portMutex.acquireIdempotent(\r\n 'drawMatrix', \r\n async p => {\r\n await p.tx(\r\n [Command.DRAW_SCALE].concat(\r\n matrix.flat().map(v => \r\n GAMMA[Math.floor((v ?? 0) * 255)]\r\n )\r\n )\r\n );\r\n }\r\n );\r\n }\r\n}\r\n","import { close, getPort } from '../../../web-serial/port.js';\r\nimport { PortMutex } from '../../../web-serial/PortMutex.js';\r\nimport { PortOperations } from '../../../web-serial/PortOperations.js';\r\nimport { CommandAbstractionLayer } from './CommandAbstractionLayer.js';\r\nimport { IDENTITY_STR_REGEX } from './commands.js';\r\n\r\nexport class SigrootController extends CommandAbstractionLayer {\r\n async bootloader() {\r\n await super.bootloader();\r\n }\r\n\r\n async connect() {\r\n const port = await getPort();\r\n\r\n if (port?.connected) {\r\n await close(port);\r\n await port.open({ baudRate: 115200 });\r\n this.portMutex = new PortMutex(new PortOperations(port));\r\n }\r\n }\r\n\r\n async draw(matrix) {\r\n if (!this.#scaleInitialized) {\r\n await super.setGlobalAnalog(0x20);\r\n this.#scaleInitialized = true;\r\n }\r\n\r\n await super.setMatrixPwm(matrix);\r\n }\r\n\r\n async verifyFirmware() { \r\n return await this.version() != null;\r\n }\r\n\r\n async version() {\r\n const ident = await super.identityString();\r\n const match = ident.match(IDENTITY_STR_REGEX);\r\n\r\n if (match && match.length == 3) {\r\n return {\r\n major: match[1],\r\n minor: match[2]\r\n }\r\n } else {\r\n return null;\r\n }\r\n }\r\n\r\n #scaleInitialized;\r\n}\r\n","import { PID, VID } from '../hardware-constants.js';\r\n\r\nconst extraDevices = [];\r\n\r\nconst filters = [\r\n {\r\n vendorId: VID,\r\n productId: PID,\r\n }\r\n];\r\n\r\nexport class DeviceSelectionCancelled extends Error {\r\n constructor() {\r\n super('User cancelled device selection.');\r\n this.name = this.constructor.name;\r\n this.date = new Date();\r\n }\r\n}\r\n\r\nexport async function getDevice() {\r\n if (extraDevices && extraDevices.length > 0) {\r\n return extraDevices.pop();\r\n }\r\n\r\n extraDevices.push(...(await navigator.hid.getDevices()));\r\n if (extraDevices && extraDevices.length > 0) {\r\n return extraDevices.pop();\r\n }\r\n\r\n extraDevices.push(...(await navigator.hid.requestDevice({ filters })));\r\n if (extraDevices && extraDevices.length > 0) {\r\n return extraDevices.pop();\r\n }\r\n\r\n throw new DeviceSelectionCancelled();\r\n}\r\n","import { pad } from './util.js';\r\n\r\nexport class HIDOperations {\r\n constructor(device) {\r\n this.#device = device;\r\n }\r\n\r\n async send(report, data) {\r\n if (data.length < report.bytes) {\r\n data = pad(data, report.bytes);\r\n } else if (data.length > report.bytes) {\r\n throw new Error('Unable to send report: too many bytes');\r\n }\r\n\r\n const buffer = new Uint8Array(data).buffer;\r\n\r\n if (report.feature) {\r\n await this.#device.sendFeatureReport(report.id, buffer);\r\n } else {\r\n await this.#device.sendReport(report.id, buffer);\r\n }\r\n }\r\n\r\n async request(report) {\r\n let reply = [];\r\n\r\n if (report.feature) {\r\n reply = await this.#device.receiveFeatureReport(report.id);\r\n } else {\r\n /* \r\n * HID input reports are used for unprompted data.\r\n * See WebHID `HIDInputReportEvent`\r\n */\r\n throw new Error('Invalid operation');\r\n }\r\n\r\n if (reply.byteLength != report.bytes) {\r\n const exp = report.bytes;\r\n const act = reply.byteLength;\r\n console.error(`reply length=${act} (expected ${exp})`);\r\n }\r\n\r\n return reply;\r\n }\r\n\r\n #device;\r\n}\r\n","export function pad(arr, len, val=0x00) {\r\n return arr.concat(new Array(len - arr.length).fill(val));\r\n}\r\n","export const Reports = {\r\n GLITTER_DEVICE_INFO: {\r\n id: 0x01,\r\n bytes: 307,\r\n feature: true,\r\n },\r\n GLITTER_BASIC_CMD: {\r\n id: 0x02,\r\n bytes: 16,\r\n feature: true,\r\n },\r\n GLITTER_GRID_PWM_CNTL: {\r\n id: 0x03,\r\n bytes: 306,\r\n feature: true,\r\n },\r\n GLITTER_GRID_PWM_CNTL: {\r\n id: 0x04,\r\n bytes: 306,\r\n feature: true,\r\n }\r\n}\r\n\r\nexport const Commands = {\r\n GLITTER_CMD_REBOOT: 0x00,\r\n GLITTER_CMD_SLEEP: 0x01,\r\n GLITTER_CMD_WAKE_ON_COMMAND: 0x02,\r\n GLITTER_CMD_SET_SLEEP_TIMEOUT: 0x03,\r\n GLITTER_CMD_SET_GLOBAL_BRIGHTNESS: 0x04,\r\n GLITTER_CMD_DRAW_PIXEL: 0x05,\r\n GLITTER_CMD_DRAW_LINE: 0x06\r\n}\r\n\r\nexport const BootMode = {\r\n BOOTSEL: 0x00,\r\n NORMAL: 0x01,\r\n}\r\n","import { GAMMA } from '../../../hardware-constants.js';\r\nimport { Commands, Reports } from './reports.js';\r\n\r\nexport class ReportAbstractionLayer {\r\n constructor(device = null) {\r\n this.device = device;\r\n }\r\n\r\n async info() {\r\n const infoRaw = await this.device.request(Reports.GLITTER_DEVICE_INFO);\r\n\r\n return {\r\n sleep_pin: infoRaw.getUint8(1),\r\n dip1_pin: infoRaw.getUint8(2),\r\n intb_pin: infoRaw.getUint8(3),\r\n state_flags: infoRaw.getUint8(4),\r\n id_reg: infoRaw.getUint8(5),\r\n config_reg: infoRaw.getUint8(6),\r\n global_brightness: infoRaw.getUint8(7),\r\n display_width: infoRaw.getUint8(8),\r\n display_height: infoRaw.getUint8(9),\r\n timeout_ms: infoRaw.getUint32(10),\r\n version_major: infoRaw.getUint8(14),\r\n version_minor: infoRaw.getUint8(15),\r\n };\r\n }\r\n\r\n async wake() {\r\n await this.device.send(\r\n Reports.GLITTER_BASIC_CMD,\r\n [Commands.GLITTER_CMD_SLEEP, false]\r\n );\r\n }\r\n\r\n async sleep() {\r\n await this.device.send(\r\n Reports.GLITTER_BASIC_CMD,\r\n [Commands.GLITTER_CMD_SLEEP, true]\r\n );\r\n }\r\n\r\n async disableSleep() {\r\n await this.device.send(\r\n Reports.GLITTER_BASIC_CMD, \r\n [Commands.GLITTER_CMD_SET_SLEEP_TIMEOUT, 0xff, 0xff, 0xff, 0xff]\r\n );\r\n }\r\n\r\n async disableDeepSleep() {\r\n await this.device.send(\r\n Reports.GLITTER_BASIC_CMD, \r\n [Commands.GLITTER_CMD_WAKE_ON_COMMAND, 0x01]\r\n );\r\n }\r\n\r\n async disableSleepTimer() {\r\n await this.device.send(\r\n Reports.GLITTER_BASIC_CMD, \r\n [Commands.GLITTER_CMD_SET_SLEEP_TIMEOUT, 0x00, 0x00, 0x00, 0x00]\r\n );\r\n }\r\n \r\n async enableDeepSleep() {\r\n await this.device.send(\r\n Reports.GLITTER_BASIC_CMD, \r\n [Commands.GLITTER_CMD_WAKE_ON_COMMAND, 0x00]\r\n );\r\n }\r\n\r\n async enableSleepTimer(milliseconds) {\r\n const view = new DataView(new ArrayBuffer(4));\r\n const littleEndian = false;\r\n view.setInt32(0, milliseconds, littleEndian);\r\n await this.device.send(\r\n Reports.GLITTER_BASIC_CMD, \r\n [\r\n Commands.GLITTER_CMD_SET_SLEEP_TIMEOUT, \r\n view.getUint8(0), \r\n view.getUint8(1), \r\n view.getUint8(2), \r\n view.getUint8(3),\r\n ]\r\n );\r\n }\r\n\r\n async reboot(mode) {\r\n await this.device.send(\r\n Reports.GLITTER_BASIC_CMD, \r\n [Commands.GLITTER_CMD_REBOOT, mode]\r\n );\r\n }\r\n\r\n async drawMatrix(matrix) {\r\n await this.device.send(\r\n Reports.GLITTER_GRID_PWM_CNTL,\r\n matrix.flat().map(v => GAMMA[Math.floor((v ?? 0) * 255)])\r\n );\r\n }\r\n\r\n async drawPixel(r, c, brightness) {\r\n await this.device.send(\r\n Reports.GLITTER_BASIC_CMD,\r\n [Commands.GLITTER_CMD_DRAW_PIXEL, c, r, brightness]\r\n );\r\n }\r\n\r\n async drawLine({r1, c1}, {r2, c2}, brightness) {\r\n await this.device.send(\r\n Reports.GLITTER_BASIC_CMD,\r\n [Commands.GLITTER_CMD_DRAW_PIXEL, r1, c1, r2, c2, brightness]\r\n );\r\n }\r\n\r\n device;\r\n}\r\n","import { getDevice } from '../../../web-hid/device.js';\r\nimport { HIDOperations } from '../../../web-hid/HIDOperations.js';\r\nimport { ReportAbstractionLayer } from './ReportAbstractionLayer.js';\r\nimport { BootMode } from './reports.js';\r\n\r\nexport class SparkleController extends ReportAbstractionLayer {\r\n async bootloader() {\r\n await super.reboot(BootMode.BOOTSEL);\r\n }\r\n\r\n async connect() {\r\n const device = await getDevice();\r\n if (device) {\r\n await device.open();\r\n this.device = new HIDOperations(device);\r\n }\r\n }\r\n \r\n async draw(matrix) {\r\n await super.drawMatrix(matrix);\r\n }\r\n\r\n async verifyFirmware() {\r\n try {\r\n const info = await super.info();\r\n return (\r\n info.display_height == HEIGHT &&\r\n info.display_width == WIDTH\r\n );\r\n } catch {\r\n return false;\r\n }\r\n }\r\n\r\n async version() {\r\n const info = await super.info();\r\n if (info.version_major != undefined \r\n && info.version_minor != undefined\r\n && (info.version_major > 0 || info.version_minor > 0)) {\r\n return {\r\n major: info.version_major,\r\n minor: info.version_minor\r\n }\r\n } else {\r\n // Sparkle <=1.1.1: Glitter version unavailable \r\n return { major: 1, minor: 0 };\r\n }\r\n }\r\n}\r\n","import { DefaultController } from './supported-firmware/FrameworkComputer/inputmodule-rs/DefaultController.js';\r\nimport { SigrootController } from './supported-firmware/sigroot/FW_LED_Matrix_Firmware/SigrootController.js';\r\nimport { SparkleController } from './supported-firmware/vddCore/sparkle-fw16/SparkleController.js';\r\n\r\nexport class HardwareControllerFactory {\r\n static async detectSerial() {\r\n const c1 = new DefaultController();\r\n const c2 = new SigrootController();\r\n\r\n await c1.connect();\r\n if (await c1.verifyFirmware()) {\r\n return c1;\r\n }\r\n \r\n await c2.connect()\r\n if (await c2.verifyFirmware()) {\r\n return c2;\r\n } \r\n \r\n return null;\r\n }\r\n\r\n static async detectHID() {\r\n const c1 = new SparkleController();\r\n \r\n await c1.connect();\r\n if (await c1.verifyFirmware()) {\r\n return c1;\r\n } \r\n \r\n return null;\r\n }\r\n}\r\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","draw","matrix","index","output","fill","r","c","drawGrayscale","buffers","Array","from","_","floor","i","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","brightness","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","wake","sleep","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,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,GA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MAAMsC,OACzB,OACEA,EAAK2J,gBAAkBhN,QACvBqD,EAAK0J,eAAiBhN,KAE1B,CAAE,MACA,OAAO,CACT,CACF,CAEA,aAAMoH,GACJ,MAAM9D,QAAatC,MAAMsC,OACzB,OAA0B+E,MAAtB/E,EAAK8J,eACkB/E,MAAtB/E,EAAK+J,gBACJ/J,EAAK8J,cAAgB,GAAK9J,EAAK+J,cAAgB,GAC5C,CACL/F,MAAOhE,EAAK8J,cACZ7F,MAAOjE,EAAK+J,eAIP,CAAE/F,MAAO,EAAGC,MAAO,EAE9B,EC3CK,MAAMyH,EACX,yBAAaC,GACX,MAAMT,EAAK,IAAI9G,EACTgH,EAAK,IAAIjE,EAGf,aADM+D,EAAG5G,gBACC4G,EAAGpG,iBACJoG,SAGHE,EAAG9G,gBACC8G,EAAGtG,iBACJsG,EAGF,KACT,CAEA,sBAAaQ,GACX,MAAMV,EAAK,IAAIG,EAGf,aADMH,EAAG5G,gBACC4G,EAAGpG,iBACJoG,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\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","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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});
2
+ //# sourceMappingURL=led-matrix-controllers.umd.min.js.map
@@ -0,0 +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,E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