@@ -8,10 +8,8 @@ using namespace Pinetime::Controllers;
88namespace {
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
8478void 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 );
@@ -95,31 +90,33 @@ void MotionService::OnNewStepCountValue(uint32_t stepCount) {
9590
9691 ble_gattc_notify_custom (connectionHandle, stepCountHandle, om);
9792}
98- void MotionService::OnNewMotionValues (int16_t x, int16_t y, int16_t z) {
99- if (!motionValuesNoficationEnabled) return ;
93+ void MotionService::OnNewMotionValues (int16_t * samples, uint16_t samples_length) {
94+ if (!motionValuesNoficationEnabled)
95+ return ;
10096
101- int16_t buffer[ 3 ] = { motionController. X (), motionController. Y (), motionController. Z () };
102- auto * om = ble_hs_mbuf_from_flat (buffer, 3 * sizeof (int16_t ));
97+ if (samples_length > 0 && samples != nullptr ) {
98+ auto * om = ble_hs_mbuf_from_flat (samples, samples_length * 3 * sizeof (int16_t ));
10399
104- uint16_t connectionHandle = system.nimble ().connHandle ();
100+ uint16_t connectionHandle = system.nimble ().connHandle ();
105101
106- if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
107- return ;
108- }
102+ if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
103+ return ;
104+ }
109105
110- ble_gattc_notify_custom (connectionHandle, motionValuesHandle, om);
106+ ble_gattc_notify_custom (connectionHandle, motionValuesHandle, om);
107+ }
111108}
112109
113110void MotionService::SubscribeNotification (uint16_t connectionHandle, uint16_t attributeHandle) {
114- if (attributeHandle == stepCountHandle)
111+ if (attributeHandle == stepCountHandle)
115112 stepCountNoficationEnabled = true ;
116- else if (attributeHandle == motionValuesHandle)
113+ else if (attributeHandle == motionValuesHandle)
117114 motionValuesNoficationEnabled = true ;
118115}
119116
120117void MotionService::UnsubscribeNotification (uint16_t connectionHandle, uint16_t attributeHandle) {
121- if (attributeHandle == stepCountHandle)
118+ if (attributeHandle == stepCountHandle)
122119 stepCountNoficationEnabled = false ;
123- else if (attributeHandle == motionValuesHandle)
120+ else if (attributeHandle == motionValuesHandle)
124121 motionValuesNoficationEnabled = false ;
125122}
0 commit comments