refactor(display): tie VFD display to WS connection state only
Made-with: Cursor
This commit is contained in:
@@ -131,6 +131,7 @@ class ClawClient {
|
|||||||
this._backoff = 1_000;
|
this._backoff = 1_000;
|
||||||
this._sendConnect();
|
this._sendConnect();
|
||||||
this._startPing();
|
this._startPing();
|
||||||
|
led.display.showTime(); // 连上云端 → 显示时间
|
||||||
});
|
});
|
||||||
|
|
||||||
ws.on('message', (data) => {
|
ws.on('message', (data) => {
|
||||||
@@ -150,6 +151,7 @@ class ClawClient {
|
|||||||
this._clearPing();
|
this._clearPing();
|
||||||
if (!this._stopped) {
|
if (!this._stopped) {
|
||||||
log.warn('clawd', `连接断开 (${code}),${this._backoff / 1000}s 后重连...`);
|
log.warn('clawd', `连接断开 (${code}),${this._backoff / 1000}s 后重连...`);
|
||||||
|
led.display.showAP(); // 断开云端 → 显示 AP
|
||||||
setTimeout(() => this._connect(), this._backoff);
|
setTimeout(() => this._connect(), this._backoff);
|
||||||
this._backoff = Math.min(this._backoff * 2, MAX_BACKOFF_MS);
|
this._backoff = Math.min(this._backoff * 2, MAX_BACKOFF_MS);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,7 @@ class ProvisionManager extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async start() {
|
async start() {
|
||||||
led.off(); // 初始状态:灭灯
|
led.off(); // 初始状态:灭灯
|
||||||
led.display.showAP(); // 默认显示 AP(等网络就绪后切换到时间)
|
|
||||||
|
|
||||||
// WiFi 已连接 → 直接进入 STA 模式
|
// WiFi 已连接 → 直接进入 STA 模式
|
||||||
if (isWifiStaConnected()) {
|
if (isWifiStaConnected()) {
|
||||||
@@ -72,7 +71,6 @@ class ProvisionManager extends EventEmitter {
|
|||||||
if (hasInternet()) {
|
if (hasInternet()) {
|
||||||
// WiFi 灯只在 STA 模式下亮(有线有网而 WiFi 在 AP 模式时不亮)
|
// WiFi 灯只在 STA 模式下亮(有线有网而 WiFi 在 AP 模式时不亮)
|
||||||
if (this._state === 'sta') led.on();
|
if (this._state === 'sta') led.on();
|
||||||
led.display.showTime(); // 网络就绪 → 显示时间
|
|
||||||
this.emit('network-ready');
|
this.emit('network-ready');
|
||||||
} else {
|
} else {
|
||||||
log.warn('provision', 'hasInternet() 返回 false,LED 保持熄灭');
|
log.warn('provision', 'hasInternet() 返回 false,LED 保持熄灭');
|
||||||
@@ -110,8 +108,7 @@ class ProvisionManager extends EventEmitter {
|
|||||||
_enterAP() {
|
_enterAP() {
|
||||||
if (this._state === 'ap') return;
|
if (this._state === 'ap') return;
|
||||||
|
|
||||||
led.off(); // AP 模式:WiFi 未连接,灭灯
|
led.off(); // AP 模式:WiFi 未连接,灭灯
|
||||||
led.display.showAP(); // 显示屏切换到 "AP "
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// AP 模式下无法扫描 WiFi,必须在开 AP 之前扫描并缓存
|
// AP 模式下无法扫描 WiFi,必须在开 AP 之前扫描并缓存
|
||||||
@@ -156,8 +153,7 @@ class ProvisionManager extends EventEmitter {
|
|||||||
if (result.success) {
|
if (result.success) {
|
||||||
this._state = 'sta';
|
this._state = 'sta';
|
||||||
log.info('provision', `WiFi 已连接: ${ssid}`);
|
log.info('provision', `WiFi 已连接: ${ssid}`);
|
||||||
led.on(); // 连接成功 → 常亮
|
led.on(); // 连接成功 → 常亮
|
||||||
led.display.showTime(); // 显示屏切换到时间
|
|
||||||
this.emit('network-ready');
|
this.emit('network-ready');
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -192,13 +188,11 @@ class ProvisionManager extends EventEmitter {
|
|||||||
if (this._state === 'sta') {
|
if (this._state === 'sta') {
|
||||||
if (hasInternet()) {
|
if (hasInternet()) {
|
||||||
led.on();
|
led.on();
|
||||||
led.display.showTime();
|
|
||||||
} else {
|
} else {
|
||||||
led.off(); // WiFi 已连接但无互联网
|
led.off(); // WiFi 已连接但无互联网
|
||||||
led.display.showAP(); // 无互联网时显示 AP
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// AP 模式下 led/display 已在 _enterAP() 中设置,无需重复操作
|
// AP 模式下 led 已在 _enterAP() 中熄灭,无需重复操作
|
||||||
}, MONITOR_INTERVAL_MS);
|
}, MONITOR_INTERVAL_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user