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) {