feat: add SETUP/APPS status LEDs (b2/b1), toggle on activation

Made-with: Cursor
This commit is contained in:
stswangzhiping
2026-03-18 20:25:54 +08:00
parent 06b670d5ec
commit 90bba5f348
2 changed files with 54 additions and 6 deletions

View File

@@ -9,6 +9,7 @@ const { collect } = require('./metrics');
const { getDashboardInfo, startTtyd, FrpcManager } = require('./frpc'); // getDashboardInfo 也用于心跳中定期刷新
const { ProvisionManager } = require('./provisioning');
const { hasInternet } = require('./network');
const led = require('./led');
const MAX_BACKOFF_MS = 60_000;
const PONG_TIMEOUT_MS = 15_000;
@@ -61,6 +62,9 @@ class ClawClient {
async start() {
log.info('clawd', `启动中... 服务器 = ${this._cfg.server}`);
// 启动时默认 SETUP 亮(未激活状态),连接成功后按实际状态切换
led.status.setSetup();
this._startSdNotify();
// 启动 AP 配网管理器(等待已保存 WiFi 自动连接,超时再开 AP
@@ -105,6 +109,7 @@ class ClawClient {
if (this._provisionMgr) { this._provisionMgr.stop(); this._provisionMgr = null; }
this._frpc.stop();
if (this._ws) this._ws.terminate();
led.status.off(); // 进程退出,两灯全灭
this._sdNotify('STOPPING=1');
log.info('clawd', '已停止');
log.close();
@@ -234,6 +239,7 @@ class ClawClient {
}
if (msg.status === 'inactive') {
led.status.setSetup(); // 未激活 → SETUP 亮
const id = String(msg.claw_id).padEnd(6);
const pin = String(msg.pin);
log.info('clawd', '');
@@ -245,6 +251,7 @@ class ClawClient {
log.info('clawd', '');
log.info('clawd', '等待激活,心跳正常运行...');
} else {
led.status.setApps(); // 已激活 → APPS 亮
log.info('clawd', `已激活 claw_id = ${msg.claw_id}`);
}