From fb8a408f936621e70f58540a9ad5d4acbe8479f1 Mon Sep 17 00:00:00 2001 From: stswangzhiping <59632378+stswangzhiping@users.noreply.github.com> Date: Fri, 3 Apr 2026 19:01:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(led):=20VFD=20=E7=AE=A1=E9=81=93=E7=94=A8?= =?UTF-8?q?=20O=5FNONBLOCK=20=E9=98=B2=E6=AD=A2=E4=BA=8B=E4=BB=B6=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF=E9=98=BB=E5=A1=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FIFO 写入改为 O_WRONLY | O_NONBLOCK: - 无读端(vfdservice 关闭读端后)openSync 立即抛 ENXIO 而非永久阻塞 - showPin blink timer 每 500-1000ms 自动重试,vfdservice 恢复读后 即可成功显示 PIN,彻底解决"长时间激活后解绑 PIN 不闪"问题 同时移除 66b94d8 加的 showTime keepalive: - keepalive 用的也是阻塞 openSync,vfdservice 关闭读端时反而会 在 setTimeout 回调里阻塞整个事件循环,比不加更危险 Made-with: Cursor --- lib/led.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/led.js b/lib/led.js index c778597..a03debf 100644 --- a/lib/led.js +++ b/lib/led.js @@ -46,6 +46,9 @@ function vfdTitleNormalize(raw) { .padEnd(4, ' '); } +// O_WRONLY | O_NONBLOCK:FIFO 无读端时立即抛 ENXIO 而非永久阻塞事件循环 +const VFD_OPEN_FLAGS = fs.constants.O_WRONLY | fs.constants.O_NONBLOCK; + function writeVfdPipeTitle(text4) { if (!vfdPipePresent()) return; const seg = vfdTitleNormalize(text4); @@ -58,7 +61,7 @@ function writeVfdPipeTitle(text4) { return; } try { - const fd = fs.openSync(VFD_PIPE, 'w'); + const fd = fs.openSync(VFD_PIPE, VFD_OPEN_FLAGS); fs.writeSync(fd, data); fs.closeSync(fd); } catch (e) { @@ -71,7 +74,7 @@ function writeVfdPipeClock() { const data = Buffer.alloc(VFD_BUF_SIZE); data.writeUInt16LE(VFD_MODE_CLOCK, 0); try { - const fd = fs.openSync(VFD_PIPE, 'w'); + const fd = fs.openSync(VFD_PIPE, VFD_OPEN_FLAGS); fs.writeSync(fd, data); fs.closeSync(fd); } catch (e) { @@ -256,13 +259,6 @@ class Display { this._stopBlink(); writeVfdPipeClock(); log.info('display', '显示屏 → 时间'); - // 每 30s 刷新一次,保持 vfdservice 持续从管道读取, - // 防止长时间无写入后管道"冷却",导致后续 showPin 写入阻塞 - const refresh = () => { - writeVfdPipeClock(); - this._blinkTimer = setTimeout(refresh, 30_000); - }; - this._blinkTimer = setTimeout(refresh, 30_000); } showPin(pin) {