diff options
author | Finlay Davidson <finlay.davidson@coderclass.nl> | 2022-05-09 17:16:08 +0200 |
---|---|---|
committer | Riku Isokoski <riksu9000@gmail.com> | 2022-06-05 09:15:46 +0300 |
commit | 7f45538eb53235ab4015fcf13533796c8759c7bc (patch) | |
tree | 79d9a2f60e8fb13cb5356bcc5c6e93259449530b /src/components/ble | |
parent | 718fbdab98ae80923a548ac03b7843f5d618a4f6 (diff) |
Apply clang-format to all C++ files
Diffstat (limited to 'src/components/ble')
-rw-r--r-- | src/components/ble/AlertNotificationClient.cpp | 7 | ||||
-rw-r--r-- | src/components/ble/BatteryInformationService.h | 1 | ||||
-rw-r--r-- | src/components/ble/CurrentTimeClient.cpp | 19 | ||||
-rw-r--r-- | src/components/ble/CurrentTimeService.cpp | 19 | ||||
-rw-r--r-- | src/components/ble/HeartRateService.cpp | 7 | ||||
-rw-r--r-- | src/components/ble/MotionService.cpp | 32 | ||||
-rw-r--r-- | src/components/ble/MusicService.cpp | 21 | ||||
-rw-r--r-- | src/components/ble/NavigationService.cpp | 26 | ||||
-rw-r--r-- | src/components/ble/NimbleController.cpp | 2 | ||||
-rw-r--r-- | src/components/ble/weather/WeatherService.h | 3 |
10 files changed, 84 insertions, 53 deletions
diff --git a/src/components/ble/AlertNotificationClient.cpp b/src/components/ble/AlertNotificationClient.cpp index 335845e3..095fdef6 100644 --- a/src/components/ble/AlertNotificationClient.cpp +++ b/src/components/ble/AlertNotificationClient.cpp @@ -26,8 +26,11 @@ namespace { return client->OnCharacteristicsDiscoveryEvent(conn_handle, error, chr); } - int OnAlertNotificationDescriptorDiscoveryEventCallback( - uint16_t conn_handle, const struct ble_gatt_error* error, uint16_t chr_val_handle, const struct ble_gatt_dsc* dsc, void* arg) { + int OnAlertNotificationDescriptorDiscoveryEventCallback(uint16_t conn_handle, + const struct ble_gatt_error* error, + uint16_t chr_val_handle, + const struct ble_gatt_dsc* dsc, + void* arg) { auto client = static_cast<AlertNotificationClient*>(arg); return client->OnDescriptorDiscoveryEventCallback(conn_handle, error, chr_val_handle, dsc); } diff --git a/src/components/ble/BatteryInformationService.h b/src/components/ble/BatteryInformationService.h index 1303fd6c..c6fc52e4 100644 --- a/src/components/ble/BatteryInformationService.h +++ b/src/components/ble/BatteryInformationService.h @@ -18,6 +18,7 @@ namespace Pinetime { int OnBatteryServiceRequested(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context); void NotifyBatteryLevel(uint16_t connectionHandle, uint8_t level); + private: Controllers::Battery& batteryController; static constexpr uint16_t batteryInformationServiceId {0x180F}; diff --git a/src/components/ble/CurrentTimeClient.cpp b/src/components/ble/CurrentTimeClient.cpp index dd8171b9..53e98cb6 100644 --- a/src/components/ble/CurrentTimeClient.cpp +++ b/src/components/ble/CurrentTimeClient.cpp @@ -85,10 +85,21 @@ int CurrentTimeClient::OnCurrentTimeReadResult(uint16_t conn_handle, const ble_g // TODO check that attribute->handle equals the handle discovered in OnCharacteristicDiscoveryEvent CtsData result; os_mbuf_copydata(attribute->om, 0, sizeof(CtsData), &result); - NRF_LOG_INFO( - "Received data: %d-%d-%d %d:%d:%d", result.year, result.month, result.dayofmonth, result.hour, result.minute, result.second); - dateTimeController.SetTime( - result.year, result.month, result.dayofmonth, 0, result.hour, result.minute, result.second, nrf_rtc_counter_get(portNRF_RTC_REG)); + NRF_LOG_INFO("Received data: %d-%d-%d %d:%d:%d", + result.year, + result.month, + result.dayofmonth, + result.hour, + result.minute, + result.second); + dateTimeController.SetTime(result.year, + result.month, + result.dayofmonth, + 0, + result.hour, + result.minute, + result.second, + nrf_rtc_counter_get(portNRF_RTC_REG)); } else { NRF_LOG_INFO("Error retrieving current time: %d", error->status); } diff --git a/src/components/ble/CurrentTimeService.cpp b/src/components/ble/CurrentTimeService.cpp index e509aeaf..8430d1bc 100644 --- a/src/components/ble/CurrentTimeService.cpp +++ b/src/components/ble/CurrentTimeService.cpp @@ -29,11 +29,22 @@ int CurrentTimeService::OnTimeAccessed(uint16_t conn_handle, uint16_t attr_handl CtsData result; os_mbuf_copydata(ctxt->om, 0, sizeof(CtsData), &result); - NRF_LOG_INFO( - "Received data: %d-%d-%d %d:%d:%d", result.year, result.month, result.dayofmonth, result.hour, result.minute, result.second); + NRF_LOG_INFO("Received data: %d-%d-%d %d:%d:%d", + result.year, + result.month, + result.dayofmonth, + result.hour, + result.minute, + result.second); - m_dateTimeController.SetTime( - result.year, result.month, result.dayofmonth, 0, result.hour, result.minute, result.second, nrf_rtc_counter_get(portNRF_RTC_REG)); + m_dateTimeController.SetTime(result.year, + result.month, + result.dayofmonth, + 0, + result.hour, + result.minute, + result.second, + nrf_rtc_counter_get(portNRF_RTC_REG)); } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) { CtsData currentDateTime; diff --git a/src/components/ble/HeartRateService.cpp b/src/components/ble/HeartRateService.cpp index 4824a6b3..d49a02c8 100644 --- a/src/components/ble/HeartRateService.cpp +++ b/src/components/ble/HeartRateService.cpp @@ -57,7 +57,8 @@ int HeartRateService::OnHeartRateRequested(uint16_t connectionHandle, uint16_t a } void HeartRateService::OnNewHeartRateValue(uint8_t heartRateValue) { - if(!heartRateMeasurementNotificationEnable) return; + if (!heartRateMeasurementNotificationEnable) + return; uint8_t buffer[2] = {0, heartRateController.HeartRate()}; // [0] = flags, [1] = hr value auto* om = ble_hs_mbuf_from_flat(buffer, 2); @@ -72,11 +73,11 @@ void HeartRateService::OnNewHeartRateValue(uint8_t heartRateValue) { } void HeartRateService::SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) { - if(attributeHandle == heartRateMeasurementHandle) + if (attributeHandle == heartRateMeasurementHandle) heartRateMeasurementNotificationEnable = true; } void HeartRateService::UnsubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) { - if(attributeHandle == heartRateMeasurementHandle) + if (attributeHandle == heartRateMeasurementHandle) heartRateMeasurementNotificationEnable = false; }
\ No newline at end of file diff --git a/src/components/ble/MotionService.cpp b/src/components/ble/MotionService.cpp index 87923c23..121ad3b0 100644 --- a/src/components/ble/MotionService.cpp +++ b/src/components/ble/MotionService.cpp @@ -8,10 +8,8 @@ using namespace Pinetime::Controllers; namespace { // 0003yyxx-78fc-48fe-8e23-433b3a1942d0 constexpr ble_uuid128_t CharUuid(uint8_t x, uint8_t y) { - return ble_uuid128_t{ - .u = {.type = BLE_UUID_TYPE_128}, - .value = { 0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, x, y, 0x03, 0x00 } - }; + return ble_uuid128_t {.u = {.type = BLE_UUID_TYPE_128}, + .value = {0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, x, y, 0x03, 0x00}}; } // 00030000-78fc-48fe-8e23-433b3a1942d0 @@ -45,11 +43,7 @@ MotionService::MotionService(Pinetime::System::SystemTask& system, Controllers:: .val_handle = &motionValuesHandle}, {0}}, serviceDefinition { - { - .type = BLE_GATT_SVC_TYPE_PRIMARY, - .uuid = &motionServiceUuid.u, - .characteristics = characteristicDefinition - }, + {.type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = &motionServiceUuid.u, .characteristics = characteristicDefinition}, {0}, } { // TODO refactor to prevent this loop dependency (service depends on controller and controller depends on service) @@ -72,8 +66,8 @@ int MotionService::OnStepCountRequested(uint16_t connectionHandle, uint16_t attr int res = os_mbuf_append(context->om, &buffer, 4); return (res == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; - } else if(attributeHandle == motionValuesHandle) { - int16_t buffer[3] = { motionController.X(), motionController.Y(), motionController.Z() }; + } else if (attributeHandle == motionValuesHandle) { + int16_t buffer[3] = {motionController.X(), motionController.Y(), motionController.Z()}; int res = os_mbuf_append(context->om, buffer, 3 * sizeof(int16_t)); return (res == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; @@ -82,7 +76,8 @@ int MotionService::OnStepCountRequested(uint16_t connectionHandle, uint16_t attr } void MotionService::OnNewStepCountValue(uint32_t stepCount) { - if(!stepCountNoficationEnabled) return; + if (!stepCountNoficationEnabled) + return; uint32_t buffer = stepCount; auto* om = ble_hs_mbuf_from_flat(&buffer, 4); @@ -96,9 +91,10 @@ void MotionService::OnNewStepCountValue(uint32_t stepCount) { ble_gattc_notify_custom(connectionHandle, stepCountHandle, om); } void MotionService::OnNewMotionValues(int16_t x, int16_t y, int16_t z) { - if(!motionValuesNoficationEnabled) return; + if (!motionValuesNoficationEnabled) + return; - int16_t buffer[3] = { motionController.X(), motionController.Y(), motionController.Z() }; + int16_t buffer[3] = {motionController.X(), motionController.Y(), motionController.Z()}; auto* om = ble_hs_mbuf_from_flat(buffer, 3 * sizeof(int16_t)); uint16_t connectionHandle = system.nimble().connHandle(); @@ -111,15 +107,15 @@ void MotionService::OnNewMotionValues(int16_t x, int16_t y, int16_t z) { } void MotionService::SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) { - if(attributeHandle == stepCountHandle) + if (attributeHandle == stepCountHandle) stepCountNoficationEnabled = true; - else if(attributeHandle == motionValuesHandle) + else if (attributeHandle == motionValuesHandle) motionValuesNoficationEnabled = true; } void MotionService::UnsubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) { - if(attributeHandle == stepCountHandle) + if (attributeHandle == stepCountHandle) stepCountNoficationEnabled = false; - else if(attributeHandle == motionValuesHandle) + else if (attributeHandle == motionValuesHandle) motionValuesNoficationEnabled = false; } diff --git a/src/components/ble/MusicService.cpp b/src/components/ble/MusicService.cpp index 60747e91..fc7cef01 100644 --- a/src/components/ble/MusicService.cpp +++ b/src/components/ble/MusicService.cpp @@ -22,10 +22,8 @@ namespace { // 0000yyxx-78fc-48fe-8e23-433b3a1942d0 constexpr ble_uuid128_t CharUuid(uint8_t x, uint8_t y) { - return ble_uuid128_t{ - .u = {.type = BLE_UUID_TYPE_128}, - .value = { 0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, x, y, 0x00, 0x00 } - }; + return ble_uuid128_t {.u = {.type = BLE_UUID_TYPE_128}, + .value = {0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, x, y, 0x00, 0x00}}; } // 00000000-78fc-48fe-8e23-433b3a1942d0 @@ -111,8 +109,7 @@ Pinetime::Controllers::MusicService::MusicService(Pinetime::System::SystemTask& .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; characteristicDefinition[13] = {0}; - serviceDefinition[0] = { - .type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = &msUuid.u, .characteristics = characteristicDefinition}; + serviceDefinition[0] = {.type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = &msUuid.u, .characteristics = characteristicDefinition}; serviceDefinition[1] = {0}; } @@ -137,9 +134,9 @@ int Pinetime::Controllers::MusicService::OnCommand(uint16_t conn_handle, uint16_ os_mbuf_copydata(ctxt->om, 0, bufferSize, data); if (notifSize > bufferSize) { - data[bufferSize-1] = '.'; - data[bufferSize-2] = '.'; - data[bufferSize-3] = '.'; + data[bufferSize - 1] = '.'; + data[bufferSize - 2] = '.'; + data[bufferSize - 3] = '.'; } data[bufferSize] = '\0'; @@ -157,7 +154,8 @@ int Pinetime::Controllers::MusicService::OnCommand(uint16_t conn_handle, uint16_ if (playing) { trackProgressUpdateTime = xTaskGetTickCount(); } else { - trackProgress += static_cast<int>((static_cast<float>(xTaskGetTickCount() - trackProgressUpdateTime) / 1024.0f) * getPlaybackSpeed()); + trackProgress += + static_cast<int>((static_cast<float>(xTaskGetTickCount() - trackProgressUpdateTime) / 1024.0f) * getPlaybackSpeed()); } } else if (ble_uuid_cmp(ctxt->chr->uuid, &msRepeatCharUuid.u) == 0) { repeat = s[0]; @@ -201,7 +199,8 @@ float Pinetime::Controllers::MusicService::getPlaybackSpeed() const { int Pinetime::Controllers::MusicService::getProgress() const { if (isPlaying()) { - return trackProgress + static_cast<int>((static_cast<float>(xTaskGetTickCount() - trackProgressUpdateTime) / 1024.0f) * getPlaybackSpeed()); + return trackProgress + + static_cast<int>((static_cast<float>(xTaskGetTickCount() - trackProgressUpdateTime) / 1024.0f) * getPlaybackSpeed()); } return trackProgress; } diff --git a/src/components/ble/NavigationService.cpp b/src/components/ble/NavigationService.cpp index 5418b9e5..76143686 100644 --- a/src/components/ble/NavigationService.cpp +++ b/src/components/ble/NavigationService.cpp @@ -46,15 +46,23 @@ namespace { } // namespace Pinetime::Controllers::NavigationService::NavigationService(Pinetime::System::SystemTask& system) : m_system(system) { - characteristicDefinition[0] = { - .uuid = &navFlagCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; - - characteristicDefinition[1] = { - .uuid = &navNarrativeCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; - characteristicDefinition[2] = { - .uuid = &navManDistCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; - characteristicDefinition[3] = { - .uuid = &navProgressCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; + characteristicDefinition[0] = {.uuid = &navFlagCharUuid.u, + .access_cb = NAVCallback, + .arg = this, + .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; + + characteristicDefinition[1] = {.uuid = &navNarrativeCharUuid.u, + .access_cb = NAVCallback, + .arg = this, + .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; + characteristicDefinition[2] = {.uuid = &navManDistCharUuid.u, + .access_cb = NAVCallback, + .arg = this, + .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; + characteristicDefinition[3] = {.uuid = &navProgressCharUuid.u, + .access_cb = NAVCallback, + .arg = this, + .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; characteristicDefinition[4] = {0}; diff --git a/src/components/ble/NimbleController.cpp b/src/components/ble/NimbleController.cpp index d2d6dc03..52f4e4ce 100644 --- a/src/components/ble/NimbleController.cpp +++ b/src/components/ble/NimbleController.cpp @@ -223,7 +223,7 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) { currentTimeClient.Reset(); alertNotificationClient.Reset(); connectionHandle = BLE_HS_CONN_HANDLE_NONE; - if(bleController.IsConnected()) { + if (bleController.IsConnected()) { bleController.Disconnect(); fastAdvCount = 0; StartAdvertising(); diff --git a/src/components/ble/weather/WeatherService.h b/src/components/ble/weather/WeatherService.h index eca70cbd..e37417da 100644 --- a/src/components/ble/weather/WeatherService.h +++ b/src/components/ble/weather/WeatherService.h @@ -127,7 +127,8 @@ namespace Pinetime { {.uuid = &weatherControlCharUuid.u, .access_cb = WeatherCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}, {nullptr}}; const struct ble_gatt_svc_def serviceDefinition[2] = { - {.type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = &weatherUuid.u, .characteristics = characteristicDefinition}, {0}}; + {.type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = &weatherUuid.u, .characteristics = characteristicDefinition}, + {0}}; uint16_t eventHandle {}; |