From fba9d401c2548262d29be503d833245130373772 Mon Sep 17 00:00:00 2001 From: stswangzhiping <59632378+stswangzhiping@users.noreply.github.com> Date: Thu, 19 Mar 2026 09:13:07 +0800 Subject: [PATCH] =?UTF-8?q?feat(display):=20PIN=20=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E6=97=B6=E5=8A=A0=E9=97=AA=E7=83=81=E6=95=88=E6=9E=9C=EF=BC=88?= =?UTF-8?q?=E4=BA=AE1s=E7=81=AD0.5s=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Made-with: Cursor --- lib/led.js | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/led.js b/lib/led.js index fed9f69..319567b 100644 --- a/lib/led.js +++ b/lib/led.js @@ -97,24 +97,46 @@ const DISPLAY_PATH = '/sys/devices/platform/openvfd/attr/led'; * #s1 系统时钟模式,显示当前时间 */ class Display { + constructor() { + this._blinkTimer = null; + } + /** 网络断开 / AP 模式 → 显示 "AP " */ showAP() { + this._stopBlink(); this._write('#m3AP '); log.info('display', '显示屏 → AP'); } /** 网络已连接 → 显示时间 */ showTime() { + this._stopBlink(); this._write('#s1'); log.info('display', '显示屏 → 时间'); } - /** 未激活 + 连网 → 显示 PIN 码(4 位数字) */ + /** 未激活 + 连网 → 显示 PIN 码(4 位数字)并闪烁 */ showPin(pin) { + this._stopBlink(); const s = String(pin || '').padStart(4, '0').slice(-4); - // #m2 模式支持数字,4字符直接跟在模式号后(无空格) this._write('#m2' + s); - log.info('display', `显示屏 → PIN: ${s}`); + log.info('display', `显示屏 → PIN: ${s}(闪烁)`); + // 亮 1s → 灭 0.5s → 循环 + let visible = true; + const blink = () => { + visible = !visible; + this._write(visible ? '#m2' + s : '#c1'); + this._blinkTimer = setTimeout(blink, visible ? 1000 : 500); + }; + this._blinkTimer = setTimeout(blink, 1000); + } + + _stopBlink() { + if (this._blinkTimer) { + clearTimeout(this._blinkTimer); + clearInterval(this._blinkTimer); + this._blinkTimer = null; + } } _write(val) {