Skip to content

Commit 1bdaf58

Browse files
Update nav service UUID macro to constexpr functions
1 parent 6b95fd8 commit 1bdaf58

2 files changed

Lines changed: 20 additions & 28 deletions

File tree

src/components/ble/NavigationService.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,32 @@
2020

2121
#include "systemtask/SystemTask.h"
2222

23+
namespace {
24+
// 0001yyxx-78fc-48fe-8e23-433b3a1942d0
25+
constexpr ble_uuid128_t CharUuid(uint8_t x, uint8_t y) {
26+
return ble_uuid128_t {.u = {.type = BLE_UUID_TYPE_128},
27+
.value = {0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, x, y, 0x01, 0x00}};
28+
}
29+
30+
// 00010000-78fc-48fe-8e23-433b3a1942d0
31+
constexpr ble_uuid128_t BaseUuid() {
32+
return CharUuid(0x00, 0x00);
33+
}
34+
35+
constexpr ble_uuid128_t navUuid {BaseUuid()};
36+
37+
constexpr ble_uuid128_t navFlagCharUuid {CharUuid(0x01, 0x00)};
38+
constexpr ble_uuid128_t navNarrativeCharUuid {CharUuid(0x02, 0x00)};
39+
constexpr ble_uuid128_t navManDistCharUuid {CharUuid(0x03, 0x00)};
40+
constexpr ble_uuid128_t navProgressCharUuid {CharUuid(0x04, 0x00)};
41+
} // namespace
42+
2343
int NAVCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) {
2444
auto navService = static_cast<Pinetime::Controllers::NavigationService*>(arg);
2545
return navService->OnCommand(conn_handle, attr_handle, ctxt);
2646
}
2747

2848
Pinetime::Controllers::NavigationService::NavigationService(Pinetime::System::SystemTask& system) : m_system(system) {
29-
navFlagCharUuid.value[12] = navFlagCharId[0];
30-
navFlagCharUuid.value[13] = navFlagCharId[1];
31-
32-
navNarrativeCharUuid.value[12] = navNarrativeCharId[0];
33-
navNarrativeCharUuid.value[13] = navNarrativeCharId[1];
34-
35-
navManDistCharUuid.value[12] = navManDistCharId[0];
36-
navManDistCharUuid.value[13] = navManDistCharId[1];
37-
38-
navProgressCharUuid.value[12] = navProgressCharId[0];
39-
navProgressCharUuid.value[13] = navProgressCharId[1];
40-
4149
characteristicDefinition[0] = {
4250
.uuid = (ble_uuid_t*) (&navFlagCharUuid), .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
4351

src/components/ble/NavigationService.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
#undef max
2727
#undef min
2828

29-
// 00010000-78fc-48fe-8e23-433b3a1942d0
30-
#define NAVIGATION_SERVICE_UUID_BASE \
31-
{ 0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, 0x00, 0x00, 0x01, 0x00 }
32-
3329
namespace Pinetime {
3430
namespace System {
3531
class SystemTask;
@@ -53,18 +49,6 @@ namespace Pinetime {
5349
int getProgress();
5450

5551
private:
56-
static constexpr uint8_t navFlagCharId[2] = {0x01, 0x00};
57-
static constexpr uint8_t navNarrativeCharId[2] = {0x02, 0x00};
58-
static constexpr uint8_t navManDistCharId[2] = {0x03, 0x00};
59-
static constexpr uint8_t navProgressCharId[2] = {0x04, 0x00};
60-
61-
ble_uuid128_t navUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = NAVIGATION_SERVICE_UUID_BASE};
62-
63-
ble_uuid128_t navFlagCharUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = NAVIGATION_SERVICE_UUID_BASE};
64-
ble_uuid128_t navNarrativeCharUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = NAVIGATION_SERVICE_UUID_BASE};
65-
ble_uuid128_t navManDistCharUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = NAVIGATION_SERVICE_UUID_BASE};
66-
ble_uuid128_t navProgressCharUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = NAVIGATION_SERVICE_UUID_BASE};
67-
6852
struct ble_gatt_chr_def characteristicDefinition[5];
6953
struct ble_gatt_svc_def serviceDefinition[2];
7054

0 commit comments

Comments
 (0)