mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-27 10:21:40 +00:00
expose battery level via the standard BLE battery service
This commit is contained in:
parent
c5851a4a0c
commit
60470211e5
@ -122,7 +122,7 @@ BLEService *createBatteryService(BLEServer *server)
|
|||||||
addWithDesc(pBattery, batteryLevelC, "Percentage 0 - 100");
|
addWithDesc(pBattery, batteryLevelC, "Percentage 0 - 100");
|
||||||
batteryLevelC->addDescriptor(addBLEDescriptor(new BLE2902())); // Needed so clients can request notification
|
batteryLevelC->addDescriptor(addBLEDescriptor(new BLE2902())); // Needed so clients can request notification
|
||||||
|
|
||||||
// I don't think we need to advertise this
|
// I don't think we need to advertise this? and some phones only see the first thing advertised anyways...
|
||||||
// server->getAdvertising()->addServiceUUID(pBattery->getUUID());
|
// server->getAdvertising()->addServiceUUID(pBattery->getUUID());
|
||||||
pBattery->start();
|
pBattery->start();
|
||||||
|
|
||||||
@ -135,8 +135,8 @@ BLEService *createBatteryService(BLEServer *server)
|
|||||||
*/
|
*/
|
||||||
void updateBatteryLevel(uint8_t level)
|
void updateBatteryLevel(uint8_t level)
|
||||||
{
|
{
|
||||||
// Pretend to update battery levels - fixme do elsewhere
|
|
||||||
if (batteryLevelC) {
|
if (batteryLevelC) {
|
||||||
|
DEBUG_MSG("set BLE battery level %u\n", level);
|
||||||
batteryLevelC->setValue(&level, 1);
|
batteryLevelC->setValue(&level, 1);
|
||||||
batteryLevelC->notify();
|
batteryLevelC->notify();
|
||||||
}
|
}
|
||||||
@ -215,7 +215,7 @@ class MySecurity : public BLESecurityCallbacks
|
|||||||
|
|
||||||
BLEServer *pServer;
|
BLEServer *pServer;
|
||||||
|
|
||||||
BLEService *pDevInfo, *pUpdate;
|
BLEService *pDevInfo, *pUpdate, *pBattery;
|
||||||
|
|
||||||
void deinitBLE()
|
void deinitBLE()
|
||||||
{
|
{
|
||||||
@ -230,6 +230,9 @@ void deinitBLE()
|
|||||||
pUpdate->executeDelete();
|
pUpdate->executeDelete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pBattery->stop();
|
||||||
|
pBattery->executeDelete();
|
||||||
|
|
||||||
pDevInfo->stop();
|
pDevInfo->stop();
|
||||||
pDevInfo->executeDelete();
|
pDevInfo->executeDelete();
|
||||||
|
|
||||||
@ -242,6 +245,7 @@ void deinitBLE()
|
|||||||
if (pUpdate != NULL)
|
if (pUpdate != NULL)
|
||||||
delete pUpdate;
|
delete pUpdate;
|
||||||
delete pDevInfo;
|
delete pDevInfo;
|
||||||
|
delete pBattery;
|
||||||
delete pServer;
|
delete pServer;
|
||||||
|
|
||||||
batteryLevelC = NULL; // Don't let anyone generate bogus notifies
|
batteryLevelC = NULL; // Don't let anyone generate bogus notifies
|
||||||
@ -279,8 +283,7 @@ BLEServer *initBLE(StartBluetoothPinScreenCallback startBtPinScreen, StopBluetoo
|
|||||||
|
|
||||||
pDevInfo = createDeviceInfomationService(pServer, hwVendor, swVersion, hwVersion);
|
pDevInfo = createDeviceInfomationService(pServer, hwVendor, swVersion, hwVersion);
|
||||||
|
|
||||||
// We now let users create the battery service only if they really want (not all devices have a battery)
|
pBattery = createBatteryService(pServer);
|
||||||
// BLEService *pBattery = createBatteryService(pServer);
|
|
||||||
|
|
||||||
// #define BLE_SOFTWARE_UPDATE
|
// #define BLE_SOFTWARE_UPDATE
|
||||||
#ifdef BLE_SOFTWARE_UPDATE
|
#ifdef BLE_SOFTWARE_UPDATE
|
||||||
|
@ -35,5 +35,8 @@ BLECharacteristic *addBLECharacteristic(BLECharacteristic *c);
|
|||||||
/// Add a characteristic that we will delete when we restart
|
/// Add a characteristic that we will delete when we restart
|
||||||
BLEDescriptor *addBLEDescriptor(BLEDescriptor *c);
|
BLEDescriptor *addBLEDescriptor(BLEDescriptor *c);
|
||||||
|
|
||||||
|
/// Given a level between 0-100, update the BLE attribute
|
||||||
|
void updateBatteryLevel(uint8_t level);
|
||||||
|
|
||||||
/// Any bluetooth objects you allocate _must_ come from this pool if you want to be able to call deinitBLE()
|
/// Any bluetooth objects you allocate _must_ come from this pool if you want to be able to call deinitBLE()
|
||||||
extern SimpleAllocator btPool;
|
extern SimpleAllocator btPool;
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "mesh-pb-constants.h"
|
#include "mesh-pb-constants.h"
|
||||||
#include "power.h"
|
#include "power.h"
|
||||||
|
#include "BluetoothUtil.h" // needed for updateBatteryLevel, FIXME, eventually when we pull mesh out into a lib we shouldn't be whacking bluetooth from here
|
||||||
|
|
||||||
/*
|
/*
|
||||||
receivedPacketQueue - this is a queue of messages we've received from the mesh, which we are keeping to deliver to the phone.
|
receivedPacketQueue - this is a queue of messages we've received from the mesh, which we are keeping to deliver to the phone.
|
||||||
@ -281,6 +282,8 @@ void MeshService::sendOurPosition(NodeNum dest, bool wantReplies)
|
|||||||
sendToMesh(p);
|
sendToMesh(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int MeshService::onGPSChanged(void *unused)
|
int MeshService::onGPSChanged(void *unused)
|
||||||
{
|
{
|
||||||
// DEBUG_MSG("got gps notify\n");
|
// DEBUG_MSG("got gps notify\n");
|
||||||
@ -301,6 +304,7 @@ int MeshService::onGPSChanged(void *unused)
|
|||||||
|
|
||||||
// Include our current battery voltage in our position announcement
|
// Include our current battery voltage in our position announcement
|
||||||
pos.battery_level = powerStatus.batteryChargePercent;
|
pos.battery_level = powerStatus.batteryChargePercent;
|
||||||
|
updateBatteryLevel(pos.battery_level);
|
||||||
|
|
||||||
// We limit our GPS broadcasts to a max rate
|
// We limit our GPS broadcasts to a max rate
|
||||||
static uint32_t lastGpsSend;
|
static uint32_t lastGpsSend;
|
||||||
|
Loading…
Reference in New Issue
Block a user