mirror of
https://github.com/mattintech/pyBTMCP.git
synced 2026-07-11 12:01:53 +00:00
Firmware: - Fixed WiFi reconnection bug after power cycle by adding WiFi.persistent(false) and disabling auto-connect/auto-reconnect - Fixed AP mode not broadcasting by properly handling WIFI_AP_STA mode transitions - Refactored to service-oriented architecture: - device_state: Central state management with event callbacks - config_service: NVS persistence (renamed from config_manager) - wifi_service: WiFi STA/AP management (extracted from main.cpp) - mqtt_service: MQTT client and message routing (extracted from main.cpp) - ble_service: BLE GATT services (renamed from ble_services) - web_service: HTTP configuration portal (renamed from web_portal) - main.cpp reduced from ~470 lines to ~60 lines (thin orchestrator) - Each service is self-contained with setup()/loop() pattern Backend: - Added heart rate variation endpoint - UI improvements Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
59 lines
1.5 KiB
C++
59 lines
1.5 KiB
C++
#ifndef BLE_SERVICE_H
|
|
#define BLE_SERVICE_H
|
|
|
|
#include <Arduino.h>
|
|
|
|
// ============================================
|
|
// BLE Service UUIDs (Bluetooth SIG standard)
|
|
// ============================================
|
|
#define HEART_RATE_SERVICE_UUID "180D"
|
|
#define HEART_RATE_MEASUREMENT_UUID "2A37"
|
|
#define BODY_SENSOR_LOCATION_UUID "2A38"
|
|
#define BATTERY_SERVICE_UUID "180F"
|
|
#define BATTERY_LEVEL_UUID "2A19"
|
|
#define FITNESS_MACHINE_SERVICE_UUID "1826"
|
|
#define TREADMILL_DATA_UUID "2ACD"
|
|
#define FITNESS_MACHINE_FEATURE_UUID "2ACC"
|
|
|
|
// ============================================
|
|
// BLE Service
|
|
// Manages BLE advertising and GATT services
|
|
// ============================================
|
|
class BleService {
|
|
public:
|
|
static BleService& getInstance();
|
|
|
|
// Prevent copying
|
|
BleService(const BleService&) = delete;
|
|
BleService& operator=(const BleService&) = delete;
|
|
|
|
// Lifecycle
|
|
void setup();
|
|
void loop();
|
|
|
|
// Configuration
|
|
void setupHeartRate();
|
|
void setupTreadmill();
|
|
void stop();
|
|
|
|
// Notifications
|
|
void notifyHeartRate(uint8_t bpm);
|
|
void notifyTreadmill(uint16_t speed, int16_t incline, uint32_t distance);
|
|
void updateBattery(uint8_t level);
|
|
|
|
// State
|
|
bool isClientConnected() const { return deviceConnected; }
|
|
|
|
private:
|
|
BleService() = default;
|
|
|
|
bool deviceConnected = false;
|
|
unsigned long lastNotify = 0;
|
|
|
|
void initBLE();
|
|
};
|
|
|
|
#define bleService BleService::getInstance()
|
|
|
|
#endif // BLE_SERVICE_H
|