From 33046948b994ac8620c337de4ffd029029688cb5 Mon Sep 17 00:00:00 2001 From: stswangzhiping <59632378+stswangzhiping@users.noreply.github.com> Date: Thu, 19 Mar 2026 08:37:00 +0800 Subject: [PATCH] =?UTF-8?q?fix(display):=20=E7=94=A8=20printf=20=E4=BB=A3?= =?UTF-8?q?=E6=9B=BF=20echo=EF=BC=8C=E4=BF=AE=E5=A4=8D=20VFD=20=E5=86=99?= =?UTF-8?q?=E5=85=A5=E5=A4=B1=E8=B4=A5=E5=8F=8A=E6=95=B0=E5=AD=97=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=81=8F=E7=A7=BB=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Made-with: Cursor --- lib/led.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/led.js b/lib/led.js index ca24380..94a972b 100644 --- a/lib/led.js +++ b/lib/led.js @@ -97,9 +97,9 @@ const DISPLAY_PATH = '/sys/devices/platform/openvfd/attr/led'; * #s1 系统时钟模式,显示当前时间 */ class Display { - /** 网络断开 / AP 模式 → 显示 "AP " */ + /** 网络断开 / AP 模式 → 显示 "AP " */ showAP() { - this._write('#m3 AP '); + this._write('#m3AP '); log.info('display', '显示屏 → AP'); } @@ -113,14 +113,15 @@ class Display { showPinMiddle4(pin) { const s = String(pin || ''); const mid4 = s.length >= 6 ? s.slice(1, 5) : s.padStart(4, '0').slice(-4); - this._write('#m3 ' + mid4); + // 不加空格分隔符,内容直接跟在 #m3 后,否则空格占用第一个显示位 + this._write('#m3' + mid4); log.info('display', `显示屏 → PIN 中间4位: ${mid4}`); } _write(val) { try { - // 用 shell 管道写入,与 echo "..." | tee ... 行为完全一致 - execSync(`echo "${val}" | tee ${DISPLAY_PATH} > /dev/null`, { timeout: 3000 }); + // 用 printf 避免 echo 的换行符导致 sysfs 写入失败 + execSync(`printf '%s' "${val}" | tee ${DISPLAY_PATH} > /dev/null`, { timeout: 3000 }); } catch (e) { log.warn('display', `写入失败: ${e.message}`); }