How tianshang301/tianshangpulse works
TianshangPulse is ESP32 smartwatch firmware for offline PPG/IMU monitoring, gated on-device AF detection, and BLE delivery to a companion app. The main task initializes device services and coordinates sampling and inference: sensor data is windowed, preprocessed, quality/motion-gated, converted to beat features, then classified; qualifying results are cached and notified over BLE. The README also describes configurable UI, power modes, and offline batch sync. The UI currently shows placeholders, and the sampled inference code does not establish a live display-data path. Unsampled subsystems are included only where the tree and README support them.
Main entry points: main.c Task coordinator · gatt_server.c GATT server · sensor.c Sensor interface · inference_engine.cc AF inference
Components 20
Sensing
- Task coordinator
firmware/main/main.c - Sensor interface
firmware/main/sensors/sensor.c - PPG driver
firmware/main/sensors/max30102.c - IMU driver
firmware/main/sensors/mpu6886.c
Signal analysis
- PPG preprocessing
firmware/main/sensors/ppg_preprocess.c - Motion and SQI gate
firmware/main/sensors/signal_gate.c - Beat features
firmware/main/sensors/af_features.c - AF inference
firmware/main/tflite/inference_engine.cc - LR coefficients
firmware/main/af_lr_coefs.h
BLE connectivity
- GATT server
firmware/main/ble/gatt_server.c - BLE protocol
firmware/main/ble/protocol.c - BLE advertising
firmware/main/ble/adv.c - Offline event cache
firmware/main/ble/offline_cache.c
Device services
- UI manager
firmware/main/ui/ui_manager.c - Display driver
firmware/main/ui/display_driver.c - Power manager
firmware/main/power/power_manager.c
Other components
- Wearer
- MAX30102
- MPU6886
- Android app
Connections 23
- Wearer → MAX30102: wears
- MAX30102 → PPG driver: provides PPG
- MPU6886 → IMU driver: provides motion
- Task coordinator → Sensor interface: initializes and samples
- Sensor interface → PPG driver: reads PPG
- Sensor interface → IMU driver: reads IMU
- Task coordinator → Sensor interface: gets samples
- Task coordinator → PPG preprocessing: normalizes windows
- Task coordinator → Motion and SQI gate: evaluates motion and SQI
- Task coordinator → Beat features: extracts beat features
- Task coordinator → AF inference: runs and reads results
- AF inference → LR coefficients: scores with
- Task coordinator → GATT server: sends heart rate and anomalies
- Task coordinator → Offline event cache: queues anomaly events
- GATT server → BLE protocol: packs and parses
- GATT server → BLE advertising: starts and restarts
- GATT server → Offline event cache: reads batches and acknowledges
- Android app → GATT server: configures and syncs
- GATT server → Android app: notifies and serves events
- Task coordinator → UI manager: initializes
- UI manager → Display driver: initializes display
- Task coordinator → Power manager: initializes
- GATT server → Power manager: sets active on connect