|
20 | 20 |
|
21 | 21 | #include "systemtask/SystemTask.h" |
22 | 22 |
|
23 | | -int NAVCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) { |
24 | | - auto navService = static_cast<Pinetime::Controllers::NavigationService*>(arg); |
25 | | - return navService->OnCommand(conn_handle, attr_handle, ctxt); |
26 | | -} |
27 | | - |
28 | | -Pinetime::Controllers::NavigationService::NavigationService(Pinetime::System::SystemTask& system) : m_system(system) { |
29 | | - navUuid.value[14] = navId[0]; |
30 | | - navUuid.value[15] = navId[1]; |
| 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 | + } |
31 | 29 |
|
32 | | - navFlagCharUuid.value[12] = navFlagCharId[0]; |
33 | | - navFlagCharUuid.value[13] = navFlagCharId[1]; |
34 | | - navFlagCharUuid.value[14] = navId[0]; |
35 | | - navFlagCharUuid.value[15] = navId[1]; |
| 30 | + // 00010000-78fc-48fe-8e23-433b3a1942d0 |
| 31 | + constexpr ble_uuid128_t BaseUuid() { |
| 32 | + return CharUuid(0x00, 0x00); |
| 33 | + } |
36 | 34 |
|
37 | | - navNarrativeCharUuid.value[12] = navNarrativeCharId[0]; |
38 | | - navNarrativeCharUuid.value[13] = navNarrativeCharId[1]; |
39 | | - navNarrativeCharUuid.value[14] = navId[0]; |
40 | | - navNarrativeCharUuid.value[15] = navId[1]; |
| 35 | + constexpr ble_uuid128_t navUuid {BaseUuid()}; |
41 | 36 |
|
42 | | - navManDistCharUuid.value[12] = navManDistCharId[0]; |
43 | | - navManDistCharUuid.value[13] = navManDistCharId[1]; |
44 | | - navManDistCharUuid.value[14] = navId[0]; |
45 | | - navManDistCharUuid.value[15] = navId[1]; |
| 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)}; |
46 | 41 |
|
47 | | - navProgressCharUuid.value[12] = navProgressCharId[0]; |
48 | | - navProgressCharUuid.value[13] = navProgressCharId[1]; |
49 | | - navProgressCharUuid.value[14] = navId[0]; |
50 | | - navProgressCharUuid.value[15] = navId[1]; |
| 42 | + int NAVCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) { |
| 43 | + auto navService = static_cast<Pinetime::Controllers::NavigationService*>(arg); |
| 44 | + return navService->OnCommand(conn_handle, attr_handle, ctxt); |
| 45 | + } |
| 46 | +} // namespace |
51 | 47 |
|
| 48 | +Pinetime::Controllers::NavigationService::NavigationService(Pinetime::System::SystemTask& system) : m_system(system) { |
52 | 49 | characteristicDefinition[0] = { |
53 | 50 | .uuid = &navFlagCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; |
54 | 51 |
|
|
0 commit comments