Apply clang-format to all C++ files
This commit is contained in:
committed by
Riku Isokoski
parent
718fbdab98
commit
7f45538eb5
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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[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[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};
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user