Skip to content

Commit 3a83d1e

Browse files
committed
Add Battery Service over BLE
Fix issue #733
1 parent f6b9383 commit 3a83d1e

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

Firmware/RTK_Everywhere/Bluetooth.ino

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@
3030
static volatile BTState bluetoothState = BT_OFF;
3131

3232
#ifdef COMPILE_BT
33+
34+
#include <BleBatteryService.h>
35+
3336
BTSerialInterface *bluetoothSerialSpp;
3437
BTSerialInterface *bluetoothSerialBle;
3538
BTSerialInterface *bluetoothSerialBleCommands; // Second BLE serial for CLI interface to mobile app
39+
BleBatteryService bluetoothBatteryService;
3640

3741
#define BLE_SERVICE_UUID "6e400001-b5a3-f393-e0a9-e50e24dcca9e"
3842
#define BLE_RX_UUID "6e400002-b5a3-f393-e0a9-e50e24dcca9e"
@@ -503,6 +507,7 @@ void bluetoothStart()
503507
deviceName, false, false, settings.sppRxQueueSize, settings.sppTxQueueSize, BLE_COMMAND_SERVICE_UUID,
504508
BLE_COMMAND_RX_UUID, BLE_COMMAND_TX_UUID); // localName, isMaster, disableBLE, rxBufferSize,
505509
// txBufferSize, serviceID, rxID, txID
510+
bluetoothBatteryService.begin();
506511
}
507512
else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP)
508513
{
@@ -522,7 +527,9 @@ void bluetoothStart()
522527
beginSuccess &= bluetoothSerialBleCommands->begin(
523528
deviceName, false, false, settings.sppRxQueueSize, settings.sppTxQueueSize, BLE_COMMAND_SERVICE_UUID,
524529
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();
526533
}
527534
else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP_ACCESSORY_MODE)
528535
{
@@ -750,3 +757,11 @@ void bluetoothPrintStatus()
750757

751758
systemPrintln();
752759
}
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+
}

Firmware/RTK_Everywhere/System.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ void updateBattery()
156156

157157
checkBatteryLevels();
158158

159+
bluetoothSendBatteryPercent(batteryLevelPercent); // Send over dedicated BLE service
160+
159161
// Display the battery data
160162
if (settings.enablePrintBatteryMessages)
161163
{
@@ -951,7 +953,7 @@ void gpioExpanderSelectImu()
951953
gpioExpanderSwitches->digitalWrite(gpioExpanderSwitch_S3, LOW);
952954
}
953955

954-
//Connect ESP32 UART2 to LoRa UART2 for configuration and bootloading/firmware updates
956+
// Connect ESP32 UART2 to LoRa UART2 for configuration and bootloading/firmware updates
955957
void gpioExpanderSelectLoraConfigure()
956958
{
957959
if (online.gpioExpanderSwitches == true)
@@ -990,7 +992,7 @@ bool gpioExpanderLoraIsOn()
990992
if (gpioExpanderSwitches->digitalRead(gpioExpanderSwitch_LoraEnable) == HIGH)
991993
return (true);
992994
}
993-
return(false);
995+
return (false);
994996
}
995997
void gpioExpanderLoraBootEnable()
996998
{

0 commit comments

Comments
 (0)