diff options
author | Ernesto Castellotti <mail@ernestocastellotti.it> | 2023-01-12 00:41:15 +0100 |
---|---|---|
committer | Simone <26844016+simonebortolin@users.noreply.github.com> | 2023-01-12 01:03:22 +0100 |
commit | e6ce89dfcc8b3a2a8016e011f3d7894bc5cf2747 (patch) | |
tree | 36ef026c388ce9bdddcda6b5bd9948e63efff954 /assets/js | |
parent | Remove outputErrorCallback from openPortLineBreak (diff) | |
download | hack-gpon.github.io-e6ce89dfcc8b3a2a8016e011f3d7894bc5cf2747.tar hack-gpon.github.io-e6ce89dfcc8b3a2a8016e011f3d7894bc5cf2747.tar.gz hack-gpon.github.io-e6ce89dfcc8b3a2a8016e011f3d7894bc5cf2747.tar.bz2 hack-gpon.github.io-e6ce89dfcc8b3a2a8016e011f3d7894bc5cf2747.tar.lz hack-gpon.github.io-e6ce89dfcc8b3a2a8016e011f3d7894bc5cf2747.tar.xz hack-gpon.github.io-e6ce89dfcc8b3a2a8016e011f3d7894bc5cf2747.tar.zst hack-gpon.github.io-e6ce89dfcc8b3a2a8016e011f3d7894bc5cf2747.zip |
Diffstat (limited to 'assets/js')
-rw-r--r-- | assets/js/serialUtil.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/assets/js/serialUtil.js b/assets/js/serialUtil.js index 6e9d155..9624619 100644 --- a/assets/js/serialUtil.js +++ b/assets/js/serialUtil.js @@ -2,6 +2,23 @@ function delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } +class LineBreakTransformer { + constructor() { + this.chunks = ""; + } + + transform(chunk, controller) { + this.chunks += chunk; + const lines = this.chunks.split("\n"); + this.chunks = lines.pop(); + lines.forEach((line) => controller.enqueue(line)); + } + + flush(controller) { + controller.enqueue(this.chunks); + } +} + async function openPortLineBreak(port, baudRate) { await port.open({ baudRate: baudRate }); const textDecoder = new TextDecoderStream(); |