@@ -8,10 +8,8 @@ using namespace Pinetime::Controllers;
8
8
namespace {
9
9
// 0003yyxx-78fc-48fe-8e23-433b3a1942d0
10
10
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 }};
15
13
}
16
14
17
15
// 00030000-78fc-48fe-8e23-433b3a1942d0
@@ -45,11 +43,7 @@ MotionService::MotionService(Pinetime::System::SystemTask& system, Controllers::
45
43
.val_handle = &motionValuesHandle},
46
44
{0 }},
47
45
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},
53
47
{0 },
54
48
} {
55
49
// 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
72
66
73
67
int res = os_mbuf_append (context->om , &buffer, 4 );
74
68
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 ()};
77
71
78
72
int res = os_mbuf_append (context->om , buffer, 3 * sizeof (int16_t ));
79
73
return (res == 0 ) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
@@ -82,7 +76,8 @@ int MotionService::OnStepCountRequested(uint16_t connectionHandle, uint16_t attr
82
76
}
83
77
84
78
void MotionService::OnNewStepCountValue (uint32_t stepCount) {
85
- if (!stepCountNoficationEnabled) return ;
79
+ if (!stepCountNoficationEnabled)
80
+ return ;
86
81
87
82
uint32_t buffer = stepCount;
88
83
auto * om = ble_hs_mbuf_from_flat (&buffer, 4 );
@@ -96,9 +91,10 @@ void MotionService::OnNewStepCountValue(uint32_t stepCount) {
96
91
ble_gattc_notify_custom (connectionHandle, stepCountHandle, om);
97
92
}
98
93
void MotionService::OnNewMotionValues (int16_t x, int16_t y, int16_t z) {
99
- if (!motionValuesNoficationEnabled) return ;
94
+ if (!motionValuesNoficationEnabled)
95
+ return ;
100
96
101
- int16_t buffer[3 ] = { motionController.X (), motionController.Y (), motionController.Z () };
97
+ int16_t buffer[3 ] = {motionController.X (), motionController.Y (), motionController.Z ()};
102
98
auto * om = ble_hs_mbuf_from_flat (buffer, 3 * sizeof (int16_t ));
103
99
104
100
uint16_t connectionHandle = system .nimble ().connHandle ();
@@ -111,15 +107,15 @@ void MotionService::OnNewMotionValues(int16_t x, int16_t y, int16_t z) {
111
107
}
112
108
113
109
void MotionService::SubscribeNotification (uint16_t connectionHandle, uint16_t attributeHandle) {
114
- if (attributeHandle == stepCountHandle)
110
+ if (attributeHandle == stepCountHandle)
115
111
stepCountNoficationEnabled = true ;
116
- else if (attributeHandle == motionValuesHandle)
112
+ else if (attributeHandle == motionValuesHandle)
117
113
motionValuesNoficationEnabled = true ;
118
114
}
119
115
120
116
void MotionService::UnsubscribeNotification (uint16_t connectionHandle, uint16_t attributeHandle) {
121
- if (attributeHandle == stepCountHandle)
117
+ if (attributeHandle == stepCountHandle)
122
118
stepCountNoficationEnabled = false ;
123
- else if (attributeHandle == motionValuesHandle)
119
+ else if (attributeHandle == motionValuesHandle)
124
120
motionValuesNoficationEnabled = false ;
125
121
}
0 commit comments