diff options
| author | JF002 <JF002@users.noreply.github.com> | 2020-10-04 10:21:22 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-04 10:21:22 (GMT) |
| commit | 39954bbd3afb592a0c3109e3479594183e8d0778 (patch) | |
| tree | 58efd04aa38b8dc7989c51fe3c9cdb9a3fb46a54 /src/Components/Ble/BatteryInformationService.cpp | |
| parent | 5adc97702c326d0252df6da75ce4ac244a4b3553 (diff) | |
| parent | 6c86d1d9d706706fcb6f214aba8259e61ed68755 (diff) | |
Merge pull request #68 from Avamander/patch-1
Rename folders to follow a consistent style
Diffstat (limited to 'src/Components/Ble/BatteryInformationService.cpp')
| -rw-r--r-- | src/Components/Ble/BatteryInformationService.cpp | 62 |
1 files changed, 0 insertions, 62 deletions
diff --git a/src/Components/Ble/BatteryInformationService.cpp b/src/Components/Ble/BatteryInformationService.cpp deleted file mode 100644 index c86830b..0000000 --- a/src/Components/Ble/BatteryInformationService.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "BatteryInformationService.h" -#include "../Battery/BatteryController.h" - -using namespace Pinetime::Controllers; - -constexpr ble_uuid16_t BatteryInformationService::batteryInformationServiceUuid; -constexpr ble_uuid16_t BatteryInformationService::batteryLevelUuid; - - - -int BatteryInformationServiceCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) { - auto* batteryInformationService = static_cast<BatteryInformationService*>(arg); - return batteryInformationService->OnBatteryServiceRequested(conn_handle, attr_handle, ctxt); -} - -BatteryInformationService::BatteryInformationService(Controllers::Battery& batteryController) : - batteryController{batteryController}, - characteristicDefinition{ - { - .uuid = (ble_uuid_t *) &batteryLevelUuid, - .access_cb = BatteryInformationServiceCallback, - .arg = this, - .flags = BLE_GATT_CHR_F_READ, - .val_handle = &batteryLevelHandle - }, - { - 0 - } - }, - serviceDefinition{ - { - /* Device Information Service */ - .type = BLE_GATT_SVC_TYPE_PRIMARY, - .uuid = (ble_uuid_t *) &batteryInformationServiceUuid, - .characteristics = characteristicDefinition - }, - { - 0 - }, - }{ - -} - -void BatteryInformationService::Init() { - int res = 0; - res = ble_gatts_count_cfg(serviceDefinition); - ASSERT(res == 0); - - res = ble_gatts_add_svcs(serviceDefinition); - ASSERT(res == 0); -} - -int BatteryInformationService::OnBatteryServiceRequested(uint16_t connectionHandle, uint16_t attributeHandle, - ble_gatt_access_ctxt *context) { - if(attributeHandle == batteryLevelHandle) { - NRF_LOG_INFO("BATTERY : handle = %d", batteryLevelHandle); - static uint8_t batteryValue = batteryController.PercentRemaining(); - int res = os_mbuf_append(context->om, &batteryValue, 1); - return (res == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; - } - return 0; -}
\ No newline at end of file |
