feat(display): PIN 显示时加闪烁效果(亮1s灭0.5s)

Made-with: Cursor
This commit is contained in:
stswangzhiping
2026-03-19 09:13:07 +08:00
parent b4fa850445
commit fba9d401c2

View File

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