30
30
static volatile BTState bluetoothState = BT_OFF;
31
31
32
32
#ifdef COMPILE_BT
33
+
34
+ #include < BleBatteryService.h>
35
+
33
36
BTSerialInterface *bluetoothSerialSpp;
34
37
BTSerialInterface *bluetoothSerialBle;
35
38
BTSerialInterface *bluetoothSerialBleCommands; // Second BLE serial for CLI interface to mobile app
39
+ BleBatteryService bluetoothBatteryService;
36
40
37
41
#define BLE_SERVICE_UUID " 6e400001-b5a3-f393-e0a9-e50e24dcca9e"
38
42
#define BLE_RX_UUID " 6e400002-b5a3-f393-e0a9-e50e24dcca9e"
@@ -503,6 +507,7 @@ void bluetoothStart()
503
507
deviceName, false , false , settings.sppRxQueueSize , settings.sppTxQueueSize , BLE_COMMAND_SERVICE_UUID,
504
508
BLE_COMMAND_RX_UUID, BLE_COMMAND_TX_UUID); // localName, isMaster, disableBLE, rxBufferSize,
505
509
// txBufferSize, serviceID, rxID, txID
510
+ bluetoothBatteryService.begin ();
506
511
}
507
512
else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP)
508
513
{
@@ -522,7 +527,9 @@ void bluetoothStart()
522
527
beginSuccess &= bluetoothSerialBleCommands->begin (
523
528
deviceName, false , false , settings.sppRxQueueSize , settings.sppTxQueueSize , BLE_COMMAND_SERVICE_UUID,
524
529
BLE_COMMAND_RX_UUID, BLE_COMMAND_TX_UUID); // localName, isMaster, disableBLE, rxBufferSize,
525
- // txBufferSize, serviceID, rxID, txID
530
+ // txBufferSize, serviceID, rxID, txID
531
+
532
+ bluetoothBatteryService.begin ();
526
533
}
527
534
else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP_ACCESSORY_MODE)
528
535
{
@@ -750,3 +757,11 @@ void bluetoothPrintStatus()
750
757
751
758
systemPrintln ();
752
759
}
760
+
761
+ // Send over dedicated BLE service
762
+ void bluetoothSendBatteryPercent (int batteryLevelPercent)
763
+ {
764
+ #ifdef COMPILE_BT
765
+ bluetoothBatteryService.reportBatteryPercent (batteryLevelPercent);
766
+ #endif // COMPILE_BT
767
+ }
0 commit comments