gps related minor fixes
This commit is contained in:
@@ -45,6 +45,7 @@ class GPSService:
|
||||
|
||||
# Periodic status logging
|
||||
self._last_status_log = 0.0
|
||||
self._last_state_emit = 0.0
|
||||
self._fix_count = 0
|
||||
|
||||
def set_on_data(self, callback):
|
||||
@@ -165,11 +166,20 @@ class GPSService:
|
||||
timeout_s = "120s" if not self._has_ever_fixed else "10s"
|
||||
print(f"[GPS] No GPS fix after {timeout_s}, will retry connection")
|
||||
raise ConnectionError("No GPS fix within timeout")
|
||||
# Emit state periodically so UI knows we're alive
|
||||
now = time.time()
|
||||
if now - self._last_state_emit >= 5.0:
|
||||
self._last_state_emit = now
|
||||
with self._lock:
|
||||
self._latest = fix
|
||||
if self._on_data_callback:
|
||||
self._on_data_callback(fix)
|
||||
continue # Skip empty fixes
|
||||
|
||||
# Got real data — mark first fix, reset timeout to shorter window
|
||||
if not self._has_ever_fixed:
|
||||
self._has_ever_fixed = True
|
||||
self._last_state_emit = 0.0 # Force immediate emit on transition
|
||||
print("[GPS] First fix acquired")
|
||||
fix_timeout = time.time() + 10.0 # 10s timeout for signal loss
|
||||
|
||||
|
||||
@@ -139,6 +139,10 @@ def on_arduino_data(data):
|
||||
# Always include current GPIO state (UI dedupes)
|
||||
data = dict(data) # Don't mutate original
|
||||
data["theme_switch"] = gpio.theme_switch
|
||||
|
||||
# backend voltage offset correction
|
||||
if "voltage" in data:
|
||||
data["voltage"] += 0.2 # Calibration offset
|
||||
|
||||
def emit_fn(d):
|
||||
socketio.emit("arduino", d)
|
||||
|
||||
Reference in New Issue
Block a user