Add support for notification title. The notification buffer must contain the title and the message separated by a '\0' character.
If the buffer does not contain any \0, the whole buffer is considered to be the message of the notification. A default title will be displayed in the notification app.
This commit is contained in:
@@ -165,6 +165,7 @@ void AlertNotificationClient::OnNotification(ble_gap_event *event) {
|
||||
NotificationManager::Notification notif;
|
||||
os_mbuf_copydata(event->notify_rx.om, headerSize, messageSize - 1, notif.message.data());
|
||||
notif.message[messageSize - 1] = '\0';
|
||||
notif.size = messageSize;
|
||||
notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
|
||||
notificationManager.Push(std::move(notif));
|
||||
|
||||
|
@@ -75,6 +75,7 @@ int AlertNotificationService::OnAlert(uint16_t conn_handle, uint16_t attr_handle
|
||||
os_mbuf_copydata(ctxt->om, headerSize, messageSize-1, notif.message.data());
|
||||
os_mbuf_copydata(ctxt->om, 0, 1, &category);
|
||||
notif.message[messageSize-1] = '\0';
|
||||
notif.size = messageSize;
|
||||
|
||||
// TODO convert all ANS categories to NotificationController categories
|
||||
switch(category) {
|
||||
|
@@ -191,7 +191,6 @@ int Pinetime::Controllers::MusicService::OnCommand(uint16_t conn_handle, uint16_
|
||||
data[notifSize] = '\0';
|
||||
os_mbuf_copydata(ctxt->om, 0, notifSize, data);
|
||||
char *s = (char *) &data[0];
|
||||
NRF_LOG_INFO("DATA : %s", s);
|
||||
if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t *) &msArtistCharUuid) == 0) {
|
||||
artistName = s;
|
||||
} else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t *) &msTrackCharUuid) == 0) {
|
||||
|
@@ -101,7 +101,6 @@ int Pinetime::Controllers::NavigationService::OnCommand(uint16_t conn_handle, ui
|
||||
data[notifSize] = '\0';
|
||||
os_mbuf_copydata(ctxt->om, 0, notifSize, data);
|
||||
char *s = (char *) &data[0];
|
||||
NRF_LOG_INFO("DATA : %s", s);
|
||||
if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t *) &navFlagCharUuid) == 0) {
|
||||
m_flag = s;
|
||||
} else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t *) &navNarrativeCharUuid) == 0) {
|
||||
|
@@ -87,3 +87,19 @@ size_t NotificationManager::NbNotifications() const {
|
||||
return std::count_if(notifications.begin(), notifications.end(), [](const Notification& n){ return n.valid;});
|
||||
}
|
||||
|
||||
const char* NotificationManager::Notification::Message() const {
|
||||
const char* itField = std::find(message.begin(), message.begin()+size-1, '\0');
|
||||
if(itField != message.begin()+size-1) {
|
||||
const char* ptr = (itField)+1;
|
||||
return ptr;
|
||||
}
|
||||
return const_cast<char*>(message.data());
|
||||
}
|
||||
|
||||
const char* NotificationManager::Notification::Title() const {
|
||||
const char * itField = std::find(message.begin(), message.begin()+size-1, '\0');
|
||||
if(itField != message.begin()+size-1) {
|
||||
return message.data();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
@@ -17,8 +17,12 @@ namespace Pinetime {
|
||||
Id id;
|
||||
bool valid = false;
|
||||
uint8_t index;
|
||||
uint8_t size;
|
||||
std::array<char, MessageSize+1> message;
|
||||
Categories category = Categories::Unknown;
|
||||
|
||||
const char* Message() const;
|
||||
const char* Title() const;
|
||||
};
|
||||
Notification::Id nextId {0};
|
||||
|
||||
|
Reference in New Issue
Block a user