feat(vfd): showConn blink on WS connecting, showErr0 on VPS unreachable
Made-with: Cursor
This commit is contained in:
@@ -125,6 +125,7 @@ class ClawClient {
|
|||||||
_connect() {
|
_connect() {
|
||||||
if (this._stopped) return;
|
if (this._stopped) return;
|
||||||
|
|
||||||
|
if (this._wsFailCount < 3) led.display.showConn();
|
||||||
log.info('clawd', `正在连接 ${this._cfg.server} ...`);
|
log.info('clawd', `正在连接 ${this._cfg.server} ...`);
|
||||||
const ws = new WebSocket(this._cfg.server, {
|
const ws = new WebSocket(this._cfg.server, {
|
||||||
handshakeTimeout: 10_000,
|
handshakeTimeout: 10_000,
|
||||||
@@ -160,7 +161,7 @@ class ClawClient {
|
|||||||
log.warn('clawd', `连接断开 (${code}),失败次数=${this._wsFailCount},${this._backoff / 1000}s 后重连...`);
|
log.warn('clawd', `连接断开 (${code}),失败次数=${this._wsFailCount},${this._backoff / 1000}s 后重连...`);
|
||||||
if (this._wsFailCount >= 3) {
|
if (this._wsFailCount >= 3) {
|
||||||
if (hasInternet()) {
|
if (hasInternet()) {
|
||||||
led.display.showErr('a'); // 有网但 VPS 不可达
|
led.display.showErr0(); // 有网但 VPS 不可达
|
||||||
} else {
|
} else {
|
||||||
led.display.showAP(); // 无网,AP 模式
|
led.display.showAP(); // 无网,AP 模式
|
||||||
}
|
}
|
||||||
|
|||||||
27
lib/led.js
27
lib/led.js
@@ -108,16 +108,25 @@ class Display {
|
|||||||
log.info('display', '显示屏 → AP');
|
log.info('display', '显示屏 → AP');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** WS 连接中(失败次数 < 3)→ 显示 "Conn" 闪烁 */
|
||||||
* 网络错误 → 显示错误码(ERR + 单字母代码)
|
showConn() {
|
||||||
* code='a' → ERRa(网络正常但 VPS 不可达)
|
|
||||||
* code='b' → ERRb(预留)
|
|
||||||
*/
|
|
||||||
showErr(code = 'a') {
|
|
||||||
this._stopBlink();
|
this._stopBlink();
|
||||||
const s = ('ERR' + code).slice(0, 4);
|
this._write('#m3Conn');
|
||||||
this._write('#m3' + s);
|
log.info('display', '显示屏 → Conn(闪烁)');
|
||||||
log.info('display', `显示屏 → ${s}`);
|
let visible = true;
|
||||||
|
const blink = () => {
|
||||||
|
visible = !visible;
|
||||||
|
this._write(visible ? '#m3Conn' : '#c1');
|
||||||
|
this._blinkTimer = setTimeout(blink, visible ? 1000 : 500);
|
||||||
|
};
|
||||||
|
this._blinkTimer = setTimeout(blink, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 网络正常但 VPS 不可达 → 显示 "Err0" */
|
||||||
|
showErr0() {
|
||||||
|
this._stopBlink();
|
||||||
|
this._write('#m3Err0');
|
||||||
|
log.info('display', '显示屏 → Err0');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 网络已连接 → 显示时间 */
|
/** 网络已连接 → 显示时间 */
|
||||||
|
|||||||
Reference in New Issue
Block a user