refactor(display): tie VFD display to WS connection state only

Made-with: Cursor
This commit is contained in:
stswangzhiping
2026-03-18 21:17:36 +08:00
parent a737101c2e
commit 959a2b67f2
2 changed files with 7 additions and 11 deletions

View File

@@ -131,6 +131,7 @@ class ClawClient {
this._backoff = 1_000;
this._sendConnect();
this._startPing();
led.display.showTime(); // 连上云端 → 显示时间
});
ws.on('message', (data) => {
@@ -150,6 +151,7 @@ class ClawClient {
this._clearPing();
if (!this._stopped) {
log.warn('clawd', `连接断开 (${code})${this._backoff / 1000}s 后重连...`);
led.display.showAP(); // 断开云端 → 显示 AP
setTimeout(() => this._connect(), this._backoff);
this._backoff = Math.min(this._backoff * 2, MAX_BACKOFF_MS);
}

View File

@@ -33,7 +33,6 @@ class ProvisionManager extends EventEmitter {
async start() {
led.off(); // 初始状态:灭灯
led.display.showAP(); // 默认显示 AP等网络就绪后切换到时间
// WiFi 已连接 → 直接进入 STA 模式
if (isWifiStaConnected()) {
@@ -72,7 +71,6 @@ class ProvisionManager extends EventEmitter {
if (hasInternet()) {
// WiFi 灯只在 STA 模式下亮(有线有网而 WiFi 在 AP 模式时不亮)
if (this._state === 'sta') led.on();
led.display.showTime(); // 网络就绪 → 显示时间
this.emit('network-ready');
} else {
log.warn('provision', 'hasInternet() 返回 falseLED 保持熄灭');
@@ -111,7 +109,6 @@ class ProvisionManager extends EventEmitter {
if (this._state === 'ap') return;
led.off(); // AP 模式WiFi 未连接,灭灯
led.display.showAP(); // 显示屏切换到 "AP "
try {
// AP 模式下无法扫描 WiFi必须在开 AP 之前扫描并缓存
@@ -157,7 +154,6 @@ class ProvisionManager extends EventEmitter {
this._state = 'sta';
log.info('provision', `WiFi 已连接: ${ssid}`);
led.on(); // 连接成功 → 常亮
led.display.showTime(); // 显示屏切换到时间
this.emit('network-ready');
return result;
}
@@ -192,13 +188,11 @@ class ProvisionManager extends EventEmitter {
if (this._state === 'sta') {
if (hasInternet()) {
led.on();
led.display.showTime();
} else {
led.off(); // WiFi 已连接但无互联网
led.display.showAP(); // 无互联网时显示 AP
}
}
// AP 模式下 led/display 已在 _enterAP() 中设置,无需重复操作
// AP 模式下 led 已在 _enterAP() 中熄灭,无需重复操作
}, MONITOR_INTERVAL_MS);
}