Skip to content

Commit 7f45538

Browse files
FintasticManRiksu9000
authored andcommitted
Apply clang-format to all C++ files
1 parent 718fbda commit 7f45538

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+479
-383
lines changed

.clang-format

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ AlignConsecutiveDeclarations: false
88
AlignEscapedNewlines: Right
99
AlignOperands: Align
1010
AlignTrailingComments: true
11-
AllowAllArgumentsOnNextLine: true
11+
AllowAllArgumentsOnNextLine: false
1212
AllowAllConstructorInitializersOnNextLine: true
13-
AllowAllParametersOfDeclarationOnNextLine: true
13+
AllowAllParametersOfDeclarationOnNextLine: false
1414
AllowShortBlocksOnASingleLine: Never
1515
AllowShortCaseLabelsOnASingleLine: false
1616
AllowShortFunctionsOnASingleLine: None
@@ -83,6 +83,8 @@ IndentGotoLabels: true
8383
IndentPPDirectives: BeforeHash
8484
IndentWidth: 2
8585
IndentWrappedFunctionNames: false
86+
# Requires Clang >= 15, could also cause incorrect code formatting:
87+
# InsertBraces: true
8688
JavaScriptQuotes: Leave
8789
JavaScriptWrapImports: true
8890
KeepEmptyLinesAtTheStartOfBlocks: true

src/BootloaderVersion.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ const bool BootloaderVersion::IsValid() {
3131

3232
void BootloaderVersion::SetVersion(uint32_t v) {
3333
BootloaderVersion::version = v;
34-
snprintf(BootloaderVersion::versionString, BootloaderVersion::VERSION_STR_LEN, "%ld.%ld.%ld",
35-
BootloaderVersion::Major(), BootloaderVersion::Minor(), BootloaderVersion::Patch());
34+
snprintf(BootloaderVersion::versionString,
35+
BootloaderVersion::VERSION_STR_LEN,
36+
"%ld.%ld.%ld",
37+
BootloaderVersion::Major(),
38+
BootloaderVersion::Minor(),
39+
BootloaderVersion::Patch());
3640
}

src/BootloaderVersion.h

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace Pinetime {
1212
static const char* VersionString();
1313
static const bool IsValid();
1414
static void SetVersion(uint32_t v);
15+
1516
private:
1617
static uint32_t version;
1718
static constexpr size_t VERSION_STR_LEN = 12;

src/components/alarm/AlarmController.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ void AlarmController::ScheduleAlarm() {
5454

5555
auto now = dateTimeController.CurrentDateTime();
5656
alarmTime = now;
57-
time_t ttAlarmTime = std::chrono::system_clock::to_time_t(
58-
std::chrono::time_point_cast<std::chrono::system_clock::duration>(alarmTime));
57+
time_t ttAlarmTime = std::chrono::system_clock::to_time_t(std::chrono::time_point_cast<std::chrono::system_clock::duration>(alarmTime));
5958
tm* tmAlarmTime = std::localtime(&ttAlarmTime);
6059

6160
// If the time being set has already passed today,the alarm should be set for tomorrow

src/components/ble/AlertNotificationClient.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ namespace {
2626
return client->OnCharacteristicsDiscoveryEvent(conn_handle, error, chr);
2727
}
2828

29-
int OnAlertNotificationDescriptorDiscoveryEventCallback(
30-
uint16_t conn_handle, const struct ble_gatt_error* error, uint16_t chr_val_handle, const struct ble_gatt_dsc* dsc, void* arg) {
29+
int OnAlertNotificationDescriptorDiscoveryEventCallback(uint16_t conn_handle,
30+
const struct ble_gatt_error* error,
31+
uint16_t chr_val_handle,
32+
const struct ble_gatt_dsc* dsc,
33+
void* arg) {
3134
auto client = static_cast<AlertNotificationClient*>(arg);
3235
return client->OnDescriptorDiscoveryEventCallback(conn_handle, error, chr_val_handle, dsc);
3336
}

src/components/ble/BatteryInformationService.h

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace Pinetime {
1818

1919
int OnBatteryServiceRequested(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context);
2020
void NotifyBatteryLevel(uint16_t connectionHandle, uint8_t level);
21+
2122
private:
2223
Controllers::Battery& batteryController;
2324
static constexpr uint16_t batteryInformationServiceId {0x180F};

src/components/ble/CurrentTimeClient.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,21 @@ int CurrentTimeClient::OnCurrentTimeReadResult(uint16_t conn_handle, const ble_g
8585
// TODO check that attribute->handle equals the handle discovered in OnCharacteristicDiscoveryEvent
8686
CtsData result;
8787
os_mbuf_copydata(attribute->om, 0, sizeof(CtsData), &result);
88-
NRF_LOG_INFO(
89-
"Received data: %d-%d-%d %d:%d:%d", result.year, result.month, result.dayofmonth, result.hour, result.minute, result.second);
90-
dateTimeController.SetTime(
91-
result.year, result.month, result.dayofmonth, 0, result.hour, result.minute, result.second, nrf_rtc_counter_get(portNRF_RTC_REG));
88+
NRF_LOG_INFO("Received data: %d-%d-%d %d:%d:%d",
89+
result.year,
90+
result.month,
91+
result.dayofmonth,
92+
result.hour,
93+
result.minute,
94+
result.second);
95+
dateTimeController.SetTime(result.year,
96+
result.month,
97+
result.dayofmonth,
98+
0,
99+
result.hour,
100+
result.minute,
101+
result.second,
102+
nrf_rtc_counter_get(portNRF_RTC_REG));
92103
} else {
93104
NRF_LOG_INFO("Error retrieving current time: %d", error->status);
94105
}

src/components/ble/CurrentTimeService.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,22 @@ int CurrentTimeService::OnTimeAccessed(uint16_t conn_handle, uint16_t attr_handl
2929
CtsData result;
3030
os_mbuf_copydata(ctxt->om, 0, sizeof(CtsData), &result);
3131

32-
NRF_LOG_INFO(
33-
"Received data: %d-%d-%d %d:%d:%d", result.year, result.month, result.dayofmonth, result.hour, result.minute, result.second);
32+
NRF_LOG_INFO("Received data: %d-%d-%d %d:%d:%d",
33+
result.year,
34+
result.month,
35+
result.dayofmonth,
36+
result.hour,
37+
result.minute,
38+
result.second);
3439

35-
m_dateTimeController.SetTime(
36-
result.year, result.month, result.dayofmonth, 0, result.hour, result.minute, result.second, nrf_rtc_counter_get(portNRF_RTC_REG));
40+
m_dateTimeController.SetTime(result.year,
41+
result.month,
42+
result.dayofmonth,
43+
0,
44+
result.hour,
45+
result.minute,
46+
result.second,
47+
nrf_rtc_counter_get(portNRF_RTC_REG));
3748

3849
} else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
3950
CtsData currentDateTime;

src/components/ble/HeartRateService.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ int HeartRateService::OnHeartRateRequested(uint16_t connectionHandle, uint16_t a
5757
}
5858

5959
void HeartRateService::OnNewHeartRateValue(uint8_t heartRateValue) {
60-
if(!heartRateMeasurementNotificationEnable) return;
60+
if (!heartRateMeasurementNotificationEnable)
61+
return;
6162

6263
uint8_t buffer[2] = {0, heartRateController.HeartRate()}; // [0] = flags, [1] = hr value
6364
auto* om = ble_hs_mbuf_from_flat(buffer, 2);
@@ -72,11 +73,11 @@ void HeartRateService::OnNewHeartRateValue(uint8_t heartRateValue) {
7273
}
7374

7475
void HeartRateService::SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) {
75-
if(attributeHandle == heartRateMeasurementHandle)
76+
if (attributeHandle == heartRateMeasurementHandle)
7677
heartRateMeasurementNotificationEnable = true;
7778
}
7879

7980
void HeartRateService::UnsubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) {
80-
if(attributeHandle == heartRateMeasurementHandle)
81+
if (attributeHandle == heartRateMeasurementHandle)
8182
heartRateMeasurementNotificationEnable = false;
8283
}

src/components/ble/MotionService.cpp

+14-18
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ using namespace Pinetime::Controllers;
88
namespace {
99
// 0003yyxx-78fc-48fe-8e23-433b3a1942d0
1010
constexpr ble_uuid128_t CharUuid(uint8_t x, uint8_t y) {
11-
return ble_uuid128_t{
12-
.u = {.type = BLE_UUID_TYPE_128},
13-
.value = { 0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, x, y, 0x03, 0x00 }
14-
};
11+
return ble_uuid128_t {.u = {.type = BLE_UUID_TYPE_128},
12+
.value = {0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, x, y, 0x03, 0x00}};
1513
}
1614

1715
// 00030000-78fc-48fe-8e23-433b3a1942d0
@@ -45,11 +43,7 @@ MotionService::MotionService(Pinetime::System::SystemTask& system, Controllers::
4543
.val_handle = &motionValuesHandle},
4644
{0}},
4745
serviceDefinition {
48-
{
49-
.type = BLE_GATT_SVC_TYPE_PRIMARY,
50-
.uuid = &motionServiceUuid.u,
51-
.characteristics = characteristicDefinition
52-
},
46+
{.type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = &motionServiceUuid.u, .characteristics = characteristicDefinition},
5347
{0},
5448
} {
5549
// 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
7266

7367
int res = os_mbuf_append(context->om, &buffer, 4);
7468
return (res == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
75-
} else if(attributeHandle == motionValuesHandle) {
76-
int16_t buffer[3] = { motionController.X(), motionController.Y(), motionController.Z() };
69+
} else if (attributeHandle == motionValuesHandle) {
70+
int16_t buffer[3] = {motionController.X(), motionController.Y(), motionController.Z()};
7771

7872
int res = os_mbuf_append(context->om, buffer, 3 * sizeof(int16_t));
7973
return (res == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
@@ -82,7 +76,8 @@ int MotionService::OnStepCountRequested(uint16_t connectionHandle, uint16_t attr
8276
}
8377

8478
void MotionService::OnNewStepCountValue(uint32_t stepCount) {
85-
if(!stepCountNoficationEnabled) return;
79+
if (!stepCountNoficationEnabled)
80+
return;
8681

8782
uint32_t buffer = stepCount;
8883
auto* om = ble_hs_mbuf_from_flat(&buffer, 4);
@@ -96,9 +91,10 @@ void MotionService::OnNewStepCountValue(uint32_t stepCount) {
9691
ble_gattc_notify_custom(connectionHandle, stepCountHandle, om);
9792
}
9893
void MotionService::OnNewMotionValues(int16_t x, int16_t y, int16_t z) {
99-
if(!motionValuesNoficationEnabled) return;
94+
if (!motionValuesNoficationEnabled)
95+
return;
10096

101-
int16_t buffer[3] = { motionController.X(), motionController.Y(), motionController.Z() };
97+
int16_t buffer[3] = {motionController.X(), motionController.Y(), motionController.Z()};
10298
auto* om = ble_hs_mbuf_from_flat(buffer, 3 * sizeof(int16_t));
10399

104100
uint16_t connectionHandle = system.nimble().connHandle();
@@ -111,15 +107,15 @@ void MotionService::OnNewMotionValues(int16_t x, int16_t y, int16_t z) {
111107
}
112108

113109
void MotionService::SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) {
114-
if(attributeHandle == stepCountHandle)
110+
if (attributeHandle == stepCountHandle)
115111
stepCountNoficationEnabled = true;
116-
else if(attributeHandle == motionValuesHandle)
112+
else if (attributeHandle == motionValuesHandle)
117113
motionValuesNoficationEnabled = true;
118114
}
119115

120116
void MotionService::UnsubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) {
121-
if(attributeHandle == stepCountHandle)
117+
if (attributeHandle == stepCountHandle)
122118
stepCountNoficationEnabled = false;
123-
else if(attributeHandle == motionValuesHandle)
119+
else if (attributeHandle == motionValuesHandle)
124120
motionValuesNoficationEnabled = false;
125121
}

src/components/ble/MusicService.cpp

+10-11
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222
namespace {
2323
// 0000yyxx-78fc-48fe-8e23-433b3a1942d0
2424
constexpr ble_uuid128_t CharUuid(uint8_t x, uint8_t y) {
25-
return ble_uuid128_t{
26-
.u = {.type = BLE_UUID_TYPE_128},
27-
.value = { 0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, x, y, 0x00, 0x00 }
28-
};
25+
return ble_uuid128_t {.u = {.type = BLE_UUID_TYPE_128},
26+
.value = {0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, x, y, 0x00, 0x00}};
2927
}
3028

3129
// 00000000-78fc-48fe-8e23-433b3a1942d0
@@ -111,8 +109,7 @@ Pinetime::Controllers::MusicService::MusicService(Pinetime::System::SystemTask&
111109
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
112110
characteristicDefinition[13] = {0};
113111

114-
serviceDefinition[0] = {
115-
.type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = &msUuid.u, .characteristics = characteristicDefinition};
112+
serviceDefinition[0] = {.type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = &msUuid.u, .characteristics = characteristicDefinition};
116113
serviceDefinition[1] = {0};
117114
}
118115

@@ -137,9 +134,9 @@ int Pinetime::Controllers::MusicService::OnCommand(uint16_t conn_handle, uint16_
137134
os_mbuf_copydata(ctxt->om, 0, bufferSize, data);
138135

139136
if (notifSize > bufferSize) {
140-
data[bufferSize-1] = '.';
141-
data[bufferSize-2] = '.';
142-
data[bufferSize-3] = '.';
137+
data[bufferSize - 1] = '.';
138+
data[bufferSize - 2] = '.';
139+
data[bufferSize - 3] = '.';
143140
}
144141
data[bufferSize] = '\0';
145142

@@ -157,7 +154,8 @@ int Pinetime::Controllers::MusicService::OnCommand(uint16_t conn_handle, uint16_
157154
if (playing) {
158155
trackProgressUpdateTime = xTaskGetTickCount();
159156
} else {
160-
trackProgress += static_cast<int>((static_cast<float>(xTaskGetTickCount() - trackProgressUpdateTime) / 1024.0f) * getPlaybackSpeed());
157+
trackProgress +=
158+
static_cast<int>((static_cast<float>(xTaskGetTickCount() - trackProgressUpdateTime) / 1024.0f) * getPlaybackSpeed());
161159
}
162160
} else if (ble_uuid_cmp(ctxt->chr->uuid, &msRepeatCharUuid.u) == 0) {
163161
repeat = s[0];
@@ -201,7 +199,8 @@ float Pinetime::Controllers::MusicService::getPlaybackSpeed() const {
201199

202200
int Pinetime::Controllers::MusicService::getProgress() const {
203201
if (isPlaying()) {
204-
return trackProgress + static_cast<int>((static_cast<float>(xTaskGetTickCount() - trackProgressUpdateTime) / 1024.0f) * getPlaybackSpeed());
202+
return trackProgress +
203+
static_cast<int>((static_cast<float>(xTaskGetTickCount() - trackProgressUpdateTime) / 1024.0f) * getPlaybackSpeed());
205204
}
206205
return trackProgress;
207206
}

src/components/ble/NavigationService.cpp

+17-9
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,23 @@ namespace {
4646
} // namespace
4747

4848
Pinetime::Controllers::NavigationService::NavigationService(Pinetime::System::SystemTask& system) : m_system(system) {
49-
characteristicDefinition[0] = {
50-
.uuid = &navFlagCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
51-
52-
characteristicDefinition[1] = {
53-
.uuid = &navNarrativeCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
54-
characteristicDefinition[2] = {
55-
.uuid = &navManDistCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
56-
characteristicDefinition[3] = {
57-
.uuid = &navProgressCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
49+
characteristicDefinition[0] = {.uuid = &navFlagCharUuid.u,
50+
.access_cb = NAVCallback,
51+
.arg = this,
52+
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
53+
54+
characteristicDefinition[1] = {.uuid = &navNarrativeCharUuid.u,
55+
.access_cb = NAVCallback,
56+
.arg = this,
57+
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
58+
characteristicDefinition[2] = {.uuid = &navManDistCharUuid.u,
59+
.access_cb = NAVCallback,
60+
.arg = this,
61+
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
62+
characteristicDefinition[3] = {.uuid = &navProgressCharUuid.u,
63+
.access_cb = NAVCallback,
64+
.arg = this,
65+
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
5866

5967
characteristicDefinition[4] = {0};
6068

src/components/ble/NimbleController.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) {
223223
currentTimeClient.Reset();
224224
alertNotificationClient.Reset();
225225
connectionHandle = BLE_HS_CONN_HANDLE_NONE;
226-
if(bleController.IsConnected()) {
226+
if (bleController.IsConnected()) {
227227
bleController.Disconnect();
228228
fastAdvCount = 0;
229229
StartAdvertising();

src/components/ble/weather/WeatherService.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ namespace Pinetime {
127127
{.uuid = &weatherControlCharUuid.u, .access_cb = WeatherCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ},
128128
{nullptr}};
129129
const struct ble_gatt_svc_def serviceDefinition[2] = {
130-
{.type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = &weatherUuid.u, .characteristics = characteristicDefinition}, {0}};
130+
{.type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = &weatherUuid.u, .characteristics = characteristicDefinition},
131+
{0}};
131132

132133
uint16_t eventHandle {};
133134

src/components/datetime/DateTimeController.cpp

+18-12
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ void DateTime::SetCurrentTime(std::chrono::time_point<std::chrono::system_clock,
1919
UpdateTime(previousSystickCounter); // Update internal state without updating the time
2020
}
2121

22-
void DateTime::SetTime(
23-
uint16_t year, uint8_t month, uint8_t day, uint8_t dayOfWeek, uint8_t hour, uint8_t minute, uint8_t second, uint32_t systickCounter) {
22+
void DateTime::SetTime(uint16_t year,
23+
uint8_t month,
24+
uint8_t day,
25+
uint8_t dayOfWeek,
26+
uint8_t hour,
27+
uint8_t minute,
28+
uint8_t second,
29+
uint32_t systickCounter) {
2430
std::tm tm = {
2531
/* .tm_sec = */ second,
2632
/* .tm_min = */ minute,
@@ -129,16 +135,16 @@ std::string DateTime::FormattedTime() {
129135
// Return time as a string in 12- or 24-hour format
130136
char buff[9];
131137
if (settingsController.GetClockType() == ClockType::H12) {
132-
uint8_t hour12;
133-
const char* amPmStr;
134-
if (hour < 12) {
135-
hour12 = (hour == 0) ? 12 : hour;
136-
amPmStr = "AM";
137-
} else {
138-
hour12 = (hour == 12) ? 12 : hour - 12;
139-
amPmStr = "PM";
140-
}
141-
sprintf(buff, "%i:%02i %s", hour12, minute, amPmStr);
138+
uint8_t hour12;
139+
const char* amPmStr;
140+
if (hour < 12) {
141+
hour12 = (hour == 0) ? 12 : hour;
142+
amPmStr = "AM";
143+
} else {
144+
hour12 = (hour == 12) ? 12 : hour - 12;
145+
amPmStr = "PM";
146+
}
147+
sprintf(buff, "%i:%02i %s", hour12, minute, amPmStr);
142148
} else {
143149
sprintf(buff, "%02i:%02i", hour, minute);
144150
}

src/components/fs/FS.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ int FS::DirRewind(lfs_dir_t* dir) {
9595
int FS::DirCreate(const char* path) {
9696
return lfs_mkdir(&lfs, path);
9797
}
98-
int FS::Rename(const char* oldPath, const char* newPath){
99-
return lfs_rename(&lfs,oldPath,newPath);
98+
int FS::Rename(const char* oldPath, const char* newPath) {
99+
return lfs_rename(&lfs, oldPath, newPath);
100100
}
101101
int FS::Stat(const char* path, lfs_info* info) {
102102
return lfs_stat(&lfs, path, info);

0 commit comments

Comments
 (0)