feat: BtMonitor 监控 bluetoothctl 状态驱动 BT 指示灯
新增 lib/bt-monitor.js: - 每 3 秒轮询 bluetoothctl show + hcitool con - connected(ACL 连接存在)→ 常亮 - scanning/connecting(Discovering: yes)→ 闪烁 - 无 adapter / Powered: no / 静止 → 熄灭 client.js:启动时开启 BtMonitor,stop() 时清理 provisioning.js:移除所有 led.bt 调用,BT 灯统一由 BtMonitor 管理 Made-with: Cursor
This commit is contained in:
@@ -8,6 +8,7 @@ const { getBoxId } = require('./fingerprint');
|
||||
const { collect } = require('./metrics');
|
||||
const { getDashboardInfo, startTtyd, FrpcManager } = require('./frpc'); // getDashboardInfo 也用于心跳中定期刷新
|
||||
const { ProvisionManager } = require('./provisioning');
|
||||
const { BtMonitor } = require('./bt-monitor');
|
||||
const { hasInternet, getLocalIps } = require('./network');
|
||||
const led = require('./led');
|
||||
|
||||
@@ -32,8 +33,9 @@ class ClawClient {
|
||||
this._hbTimer = null;
|
||||
this._backoff = 1_000;
|
||||
this._stopped = false;
|
||||
this._frpc = new FrpcManager();
|
||||
this._dashInfo = {};
|
||||
this._frpc = new FrpcManager();
|
||||
this._btMonitor = null;
|
||||
this._dashInfo = {};
|
||||
this._hbCount = 0; // 心跳计数器,用于定期刷新 dashboard 信息
|
||||
this._externalIp = null; // 外网 IP
|
||||
this._location = null; // 地理位置(由 ipplus360 返回,如"北京市-北京市西城区")
|
||||
@@ -83,6 +85,10 @@ class ClawClient {
|
||||
|
||||
this._startSdNotify();
|
||||
|
||||
// 启动蓝牙状态监控(独立于网络,立即开始)
|
||||
this._btMonitor = new BtMonitor();
|
||||
this._btMonitor.start();
|
||||
|
||||
// 启动 AP 配网管理器(等待已保存 WiFi 自动连接,超时再开 AP)
|
||||
this._provisionMgr = new ProvisionManager(this._cfg.claw_id);
|
||||
this._connectionStarted = false;
|
||||
@@ -167,6 +173,7 @@ class ClawClient {
|
||||
this._clearPing();
|
||||
this._clearNetMonitor();
|
||||
if (this._sdTimer) { clearInterval(this._sdTimer); this._sdTimer = null; }
|
||||
if (this._btMonitor) { this._btMonitor.stop(); this._btMonitor = null; }
|
||||
if (this._provisionMgr) { this._provisionMgr.stop(); this._provisionMgr = null; }
|
||||
this._frpc.stop();
|
||||
if (this._ws) this._ws.terminate();
|
||||
|
||||
Reference in New Issue
Block a user