mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-25 17:42:48 +00:00
WIP: Add battery level for Nimble
This commit is contained in:
parent
b3852322ef
commit
d6fc1c314f
@ -9,6 +9,7 @@
|
|||||||
#include <NimBLEDevice.h>
|
#include <NimBLEDevice.h>
|
||||||
|
|
||||||
NimBLECharacteristic *fromNumCharacteristic;
|
NimBLECharacteristic *fromNumCharacteristic;
|
||||||
|
NimBLECharacteristic *BatteryCharacteristic;
|
||||||
NimBLEServer *bleServer;
|
NimBLEServer *bleServer;
|
||||||
|
|
||||||
static bool passkeyShowing;
|
static bool passkeyShowing;
|
||||||
@ -181,6 +182,18 @@ void NimbleBluetooth::setupService()
|
|||||||
FromRadioCharacteristic->setCallbacks(fromRadioCallbacks);
|
FromRadioCharacteristic->setCallbacks(fromRadioCallbacks);
|
||||||
|
|
||||||
bleService->start();
|
bleService->start();
|
||||||
|
|
||||||
|
// Setup the battery service
|
||||||
|
NimBLEService *batteryService = bleServer->createService(NimBLEUUID((uint16_t)0x180f)); // 0x180F is the Battery Service
|
||||||
|
BatteryCharacteristic = batteryService->createCharacteristic( // 0x2A19 is the Battery Level characteristic)
|
||||||
|
(uint16_t)0x2a19, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY);
|
||||||
|
|
||||||
|
NimBLE2904 *batteryLevelDescriptor = (NimBLE2904 *)BatteryCharacteristic->createDescriptor((uint16_t)0x2904);
|
||||||
|
batteryLevelDescriptor->setFormat(NimBLE2904::FORMAT_UINT8);
|
||||||
|
batteryLevelDescriptor->setNamespace(1);
|
||||||
|
batteryLevelDescriptor->setUnit(0x27ad);
|
||||||
|
|
||||||
|
batteryService->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NimbleBluetooth::startAdvertising()
|
void NimbleBluetooth::startAdvertising()
|
||||||
@ -188,13 +201,15 @@ void NimbleBluetooth::startAdvertising()
|
|||||||
NimBLEAdvertising *pAdvertising = NimBLEDevice::getAdvertising();
|
NimBLEAdvertising *pAdvertising = NimBLEDevice::getAdvertising();
|
||||||
pAdvertising->reset();
|
pAdvertising->reset();
|
||||||
pAdvertising->addServiceUUID(MESH_SERVICE_UUID);
|
pAdvertising->addServiceUUID(MESH_SERVICE_UUID);
|
||||||
|
pAdvertising->addServiceUUID(NimBLEUUID((uint16_t)0x180f)); // 0x180F is the Battery Service
|
||||||
pAdvertising->start(0);
|
pAdvertising->start(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Given a level between 0-100, update the BLE attribute
|
/// Given a level between 0-100, update the BLE attribute
|
||||||
void updateBatteryLevel(uint8_t level)
|
void updateBatteryLevel(uint8_t level)
|
||||||
{
|
{
|
||||||
// blebas.write(level);
|
BatteryCharacteristic->setValue(&level, 1);
|
||||||
|
BatteryCharacteristic->notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NimbleBluetooth::clearBonds()
|
void NimbleBluetooth::clearBonds()
|
||||||
|
Loading…
Reference in New Issue
Block a user