Rework characteristic handling
This commit is contained in:
parent
306aa25aad
commit
686e826f4e
|
@ -20,27 +20,28 @@ Pinetime::Controllers::MusicService::MusicService()
|
|||
msAlbumCharUuid.value[11] = msAlbumCharId[0];
|
||||
msAlbumCharUuid.value[12] = msAlbumCharId[1];
|
||||
|
||||
characteristicDefinition[0] = {(ble_uuid_t*)(&msEventCharUuid),
|
||||
characteristicDefinition[0] = { .uuid = (ble_uuid_t*)(&msEventCharUuid),
|
||||
.access_cb = MSCallback,
|
||||
.arg = this,
|
||||
.flags = BLE_GATT_CHR_F_NOTIFY | BLE_GATT_CHR_F_READ
|
||||
.flags = BLE_GATT_CHR_F_NOTIFY,
|
||||
.val_handle = &m_eventHandle
|
||||
};
|
||||
characteristicDefinition[1] = {(ble_uuid_t*)(&msStatusCharUuid),
|
||||
characteristicDefinition[1] = { .uuid = (ble_uuid_t*)(&msStatusCharUuid),
|
||||
.access_cb = MSCallback,
|
||||
.arg = this,
|
||||
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ
|
||||
};
|
||||
characteristicDefinition[2] = {(ble_uuid_t*)(&msTrackCharUuid),
|
||||
characteristicDefinition[2] = { .uuid = (ble_uuid_t*)(&msTrackCharUuid),
|
||||
.access_cb = MSCallback,
|
||||
.arg = this,
|
||||
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ
|
||||
};
|
||||
characteristicDefinition[3] = {(ble_uuid_t*)(&msArtistCharUuid),
|
||||
characteristicDefinition[3] = { .uuid = (ble_uuid_t*)(&msArtistCharUuid),
|
||||
.access_cb = MSCallback,
|
||||
.arg = this,
|
||||
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ
|
||||
};
|
||||
characteristicDefinition[4] = {(ble_uuid_t*)(&msAlbumCharUuid),
|
||||
characteristicDefinition[4] = { .uuid = (ble_uuid_t*)(&msAlbumCharUuid),
|
||||
.access_cb = MSCallback,
|
||||
.arg = this,
|
||||
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ
|
||||
|
@ -72,8 +73,6 @@ void Pinetime::Controllers::MusicService::Init()
|
|||
int Pinetime::Controllers::MusicService::OnCommand(uint16_t conn_handle, uint16_t attr_handle,
|
||||
struct ble_gatt_access_ctxt *ctxt) {
|
||||
|
||||
connectionHandle = conn_handle;
|
||||
|
||||
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
|
||||
size_t notifSize = OS_MBUF_PKTLEN(ctxt->om);
|
||||
uint8_t data[notifSize + 1];
|
||||
|
@ -112,12 +111,16 @@ void Pinetime::Controllers::MusicService::event(char event)
|
|||
struct os_mbuf *om;
|
||||
int ret;
|
||||
|
||||
uint16_t connectionHandle = 0;
|
||||
|
||||
om = ble_hs_mbuf_from_flat(&event, 1);
|
||||
|
||||
ble_gatts_find_chr((ble_uuid_t *) &msUuid, (ble_uuid_t *) &msEventCharUuid, nullptr,
|
||||
&eventCharacteristicHandle);
|
||||
ret = ble_gatts_find_svc((ble_uuid_t *) &msUuid, &connectionHandle);
|
||||
|
||||
ret = ble_gattc_notify_custom(connectionHandle, eventCharacteristicHandle, om);
|
||||
if (connectionHandle == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
ret = ble_gattc_notify_custom(connectionHandle, m_eventHandle, om);
|
||||
}
|
||||
|
||||
|
|
|
@ -39,9 +39,6 @@ namespace Pinetime {
|
|||
static constexpr uint8_t msTrackCharId[2] = {0x00, 0x05};
|
||||
static constexpr uint8_t msAlbumCharId[2] = {0x00, 0x06};
|
||||
|
||||
uint16_t connectionHandle = 0;
|
||||
uint16_t eventCharacteristicHandle = 0;
|
||||
|
||||
ble_uuid128_t msUuid {
|
||||
.u = { .type = BLE_UUID_TYPE_128 },
|
||||
.value = MUSIC_SERVICE_UUID_BASE
|
||||
|
@ -70,6 +67,8 @@ namespace Pinetime {
|
|||
|
||||
struct ble_gatt_chr_def characteristicDefinition[6];
|
||||
struct ble_gatt_svc_def serviceDefinition[2];
|
||||
|
||||
uint16_t m_eventHandle;
|
||||
|
||||
std::string m_artist;
|
||||
std::string m_album;
|
||||
|
|
|
@ -190,7 +190,7 @@ void DisplayApp::RunningState() {
|
|||
case Apps::Meter: currentScreen.reset(new Screens::Meter(this)); break;
|
||||
case Apps::Gauge: currentScreen.reset(new Screens::Gauge(this)); break;
|
||||
case Apps::Brightness : currentScreen.reset(new Screens::Brightness(this, brightnessController)); break;
|
||||
case Apps::Music : currentScreen.reset(new Screens::Music(this)); break;
|
||||
case Apps::Music : currentScreen.reset(new Screens::Music(this, systemTask.nimble().music())); break;
|
||||
}
|
||||
nextApp = Apps::None;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user