|
|
|
@ -8,10 +8,8 @@ using namespace Pinetime::Controllers;
|
|
|
|
|
namespace {
|
|
|
|
|
// 0003yyxx-78fc-48fe-8e23-433b3a1942d0
|
|
|
|
|
constexpr ble_uuid128_t CharUuid(uint8_t x, uint8_t y) {
|
|
|
|
|
return ble_uuid128_t{
|
|
|
|
|
.u = {.type = BLE_UUID_TYPE_128},
|
|
|
|
|
.value = { 0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, x, y, 0x03, 0x00 }
|
|
|
|
|
};
|
|
|
|
|
return ble_uuid128_t {.u = {.type = BLE_UUID_TYPE_128},
|
|
|
|
|
.value = {0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, x, y, 0x03, 0x00}};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 00030000-78fc-48fe-8e23-433b3a1942d0
|
|
|
|
@ -45,11 +43,7 @@ MotionService::MotionService(Pinetime::System::SystemTask& system, Controllers::
|
|
|
|
|
.val_handle = &motionValuesHandle},
|
|
|
|
|
{0}},
|
|
|
|
|
serviceDefinition {
|
|
|
|
|
{
|
|
|
|
|
.type = BLE_GATT_SVC_TYPE_PRIMARY,
|
|
|
|
|
.uuid = &motionServiceUuid.u,
|
|
|
|
|
.characteristics = characteristicDefinition
|
|
|
|
|
},
|
|
|
|
|
{.type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = &motionServiceUuid.u, .characteristics = characteristicDefinition},
|
|
|
|
|
{0},
|
|
|
|
|
} {
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
|
|
int res = os_mbuf_append(context->om, &buffer, 4);
|
|
|
|
|
return (res == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
|
|
|
|
|
} else if(attributeHandle == motionValuesHandle) {
|
|
|
|
|
int16_t buffer[3] = { motionController.X(), motionController.Y(), motionController.Z() };
|
|
|
|
|
} else if (attributeHandle == motionValuesHandle) {
|
|
|
|
|
int16_t buffer[3] = {motionController.X(), motionController.Y(), motionController.Z()};
|
|
|
|
|
|
|
|
|
|
int res = os_mbuf_append(context->om, buffer, 3 * sizeof(int16_t));
|
|
|
|
|
return (res == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
|
|
|
|
@ -82,7 +76,8 @@ int MotionService::OnStepCountRequested(uint16_t connectionHandle, uint16_t attr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MotionService::OnNewStepCountValue(uint32_t stepCount) {
|
|
|
|
|
if(!stepCountNoficationEnabled) return;
|
|
|
|
|
if (!stepCountNoficationEnabled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
uint32_t buffer = stepCount;
|
|
|
|
|
auto* om = ble_hs_mbuf_from_flat(&buffer, 4);
|
|
|
|
@ -96,9 +91,10 @@ void MotionService::OnNewStepCountValue(uint32_t stepCount) {
|
|
|
|
|
ble_gattc_notify_custom(connectionHandle, stepCountHandle, om);
|
|
|
|
|
}
|
|
|
|
|
void MotionService::OnNewMotionValues(int16_t x, int16_t y, int16_t z) {
|
|
|
|
|
if(!motionValuesNoficationEnabled) return;
|
|
|
|
|
if (!motionValuesNoficationEnabled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int16_t buffer[3] = { motionController.X(), motionController.Y(), motionController.Z() };
|
|
|
|
|
int16_t buffer[3] = {motionController.X(), motionController.Y(), motionController.Z()};
|
|
|
|
|
auto* om = ble_hs_mbuf_from_flat(buffer, 3 * sizeof(int16_t));
|
|
|
|
|
|
|
|
|
|
uint16_t connectionHandle = system.nimble().connHandle();
|
|
|
|
@ -111,15 +107,15 @@ void MotionService::OnNewMotionValues(int16_t x, int16_t y, int16_t z) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MotionService::SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) {
|
|
|
|
|
if(attributeHandle == stepCountHandle)
|
|
|
|
|
if (attributeHandle == stepCountHandle)
|
|
|
|
|
stepCountNoficationEnabled = true;
|
|
|
|
|
else if(attributeHandle == motionValuesHandle)
|
|
|
|
|
else if (attributeHandle == motionValuesHandle)
|
|
|
|
|
motionValuesNoficationEnabled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MotionService::UnsubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) {
|
|
|
|
|
if(attributeHandle == stepCountHandle)
|
|
|
|
|
if (attributeHandle == stepCountHandle)
|
|
|
|
|
stepCountNoficationEnabled = false;
|
|
|
|
|
else if(attributeHandle == motionValuesHandle)
|
|
|
|
|
else if (attributeHandle == motionValuesHandle)
|
|
|
|
|
motionValuesNoficationEnabled = false;
|
|
|
|
|
}
|
|
|
|
|