diff options
| author | Avamander <avamander@gmail.com> | 2020-10-02 21:44:27 +0300 |
|---|---|---|
| committer | Avamander <avamander@gmail.com> | 2020-10-02 21:44:27 +0300 |
| commit | 40a643d203d2d21834dd2b35d83419a56a3939b6 (patch) | |
| tree | 522947ffe2e7c10f6e8c45a6e7d1e58d3521829b /src/Components/Ble/BatteryInformationService.cpp | |
| parent | 455d8319e4af521de4e24cfa423a4c06c4378a8d (diff) | |
Renamed Components/ to components/
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 c86830b8..00000000 --- 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 |
