mirror of
https://github.com/smittix/intercept.git
synced 2026-07-02 14:58:58 -07:00
fix: meshcore serial connection and battery calculation issues
- Fix _pollUntilConnected overwriting real error with generic timeout message — stop polling once backend reaches error state - Fix battery % calculation: was battery_mv/42 (71% at empty); now (battery_mv-3000)/12 for a proper 0-100% LiPo curve - Improve auto-detect: scan available ports rather than blindly using /dev/ttyUSB0; update label to show fallback so users know what to expect - Add port refresh button (↻) — previously required switching modes and back if device was plugged in after panel opened - Add baud rate selector to serial config strip (default 115200, options up to 921600) and wire it through to the connect request Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -100,7 +100,15 @@ class AsyncWorker:
|
||||
cfg = self._config
|
||||
|
||||
if isinstance(cfg, SerialConfig):
|
||||
port = cfg.port or "/dev/ttyUSB0"
|
||||
from utils.meshcore import list_serial_ports
|
||||
|
||||
if cfg.port:
|
||||
port = cfg.port
|
||||
else:
|
||||
# Auto-detect: prefer ttyUSB0, then first available port
|
||||
candidates = list_serial_ports()
|
||||
port = next((p for p in candidates if "ttyUSB0" in p), None) or \
|
||||
(candidates[0] if candidates else "/dev/ttyUSB0")
|
||||
self._mc = await MeshCore.create_serial(port=port, baudrate=cfg.baud, debug=False)
|
||||
transport, device = "serial", port
|
||||
elif isinstance(cfg, TCPConfig):
|
||||
@@ -205,7 +213,8 @@ class AsyncWorker:
|
||||
p = event.payload
|
||||
node_id = "self" # stats_core is always for the local node
|
||||
battery_mv = p.get("battery_mv")
|
||||
battery_pct = min(int(battery_mv / 42), 100) if battery_mv else None # rough: 4200mv = 100%
|
||||
# LiPo linear approximation: 3000mV = 0%, 4200mV = 100%
|
||||
battery_pct = max(0, min(int((battery_mv - 3000) / 12), 100)) if battery_mv else None
|
||||
t = MeshcoreTelemetry(
|
||||
node_id=node_id,
|
||||
timestamp=datetime.now(timezone.utc),
|
||||
|
||||
Reference in New Issue
Block a user