Calibration tool : lecture config XIAO au démarrage

Lit la caractéristique configChar au démarrage de la connexion BLE
pour synchroniser les seuils Python avec les valeurs sauvegardées
en flash sur le XIAO (accel, gyro, audio).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
j.foucher 2026-02-18 13:49:34 +01:00
parent 6e1241f6bb
commit 2fadb3e6e2

View File

@ -142,7 +142,18 @@ async def ble_loop():
await client.start_notify(DEBUG_CHAR_UUID, debug_callback)
await client.start_notify(SHOT_CHAR_UUID, shot_callback)
ble_status = f"{display_name} ({addr})"
# À la connexion : envoyer config + activer debug FULL automatiquement
# À la connexion : lire la config sauvegardée dans le XIAO (flash)
try:
raw = await client.read_gatt_char(CONFIG_CHAR_UUID)
if len(raw) >= 22:
vals = struct.unpack_from('<ffH', raw, 0)
thresholds["accel"] = round(vals[0], 1)
thresholds["gyro"] = round(vals[1], 1)
thresholds["audio"] = int(vals[2])
print(f"📥 Config lue depuis XIAO → Accel:{thresholds['accel']:.1f}G Gyro:{thresholds['gyro']:.0f}°/s Audio:{thresholds['audio']}")
except Exception as ex:
print(f"⚠️ Lecture config XIAO impossible: {ex}")
# Envoyer debug FULL (sans écraser les seuils du XIAO)
try:
payload = build_config_payload(include_debug=True)
await client.write_gatt_char(CONFIG_CHAR_UUID, payload, response=True)