diff options
| author | Jean-François Milants <jf@codingfield.com> | 2021-04-04 10:10:47 (GMT) |
|---|---|---|
| committer | Jean-François Milants <jf@codingfield.com> | 2021-04-04 10:10:47 (GMT) |
| commit | 03de1c67393fcb99b5987514be6f470349c57c0f (patch) | |
| tree | 5eacb0614b667ff62f417c390109482ed7e0a07d /src/components/ble/NotificationManager.cpp | |
| parent | 58a2d000c4d49d96121894d6dd6bb861d7564bea (diff) | |
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.
Diffstat (limited to 'src/components/ble/NotificationManager.cpp')
| -rw-r--r-- | src/components/ble/NotificationManager.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/components/ble/NotificationManager.cpp b/src/components/ble/NotificationManager.cpp index 36abf02..88e83b9 100644 --- a/src/components/ble/NotificationManager.cpp +++ b/src/components/ble/NotificationManager.cpp @@ -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 {}; +} |
