diff options
author | JF002 <JF002@users.noreply.github.com> | 2020-10-27 21:57:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-27 21:57:48 +0100 |
commit | cb9e8815d8bc6ce71fd8e97f3e3dae402658ce1f (patch) | |
tree | 1750edfed02f547102e468eca485caab3b08e98d /src/components/ble/AlertNotificationClient.cpp | |
parent | c5bf09d21b2ed8e2435ec625e351594f58713924 (diff) | |
parent | 7de43a16608e599369867cb3cfa7d5776a5b6380 (diff) |
Merge pull request #108 from JF002/notification-ui
Improved notification UI
Diffstat (limited to 'src/components/ble/AlertNotificationClient.cpp')
-rw-r--r-- | src/components/ble/AlertNotificationClient.cpp | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/src/components/ble/AlertNotificationClient.cpp b/src/components/ble/AlertNotificationClient.cpp index ddc72967..40970e0b 100644 --- a/src/components/ble/AlertNotificationClient.cpp +++ b/src/components/ble/AlertNotificationClient.cpp @@ -105,25 +105,21 @@ int AlertNotificationClient::OnDescriptorDiscoveryEventCallback(uint16_t connect void AlertNotificationClient::OnNotification(ble_gap_event *event) { if(event->notify_rx.attr_handle == newAlertHandle) { - // TODO implement this with more memory safety (and constexpr) - static const size_t maxBufferSize{21}; - static const size_t maxMessageSize{18}; - size_t bufferSize = min(OS_MBUF_PKTLEN(event->notify_rx.om), maxBufferSize); + constexpr size_t stringTerminatorSize = 1; // end of string '\0' + constexpr size_t headerSize = 3; + const auto maxMessageSize {NotificationManager::MaximumMessageSize()}; + const auto maxBufferSize{maxMessageSize + headerSize}; - uint8_t data[bufferSize]; - os_mbuf_copydata(event->notify_rx.om, 0, bufferSize, data); + const auto dbgPacketLen = OS_MBUF_PKTLEN(event->notify_rx.om); + size_t bufferSize = min(dbgPacketLen + stringTerminatorSize, maxBufferSize); + auto messageSize = min(maxMessageSize, (bufferSize-headerSize)); - char *s = (char *) &data[3]; - auto messageSize = min(maxMessageSize, (bufferSize-3)); + NotificationManager::Notification notif; + os_mbuf_copydata(event->notify_rx.om, headerSize, messageSize-1, notif.message.data()); + notif.message[messageSize-1] = '\0'; + notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert; + notificationManager.Push(std::move(notif)); - for (uint i = 0; i < messageSize-1; i++) { - if (s[i] == 0x00) { - s[i] = 0x0A; - } - } - s[messageSize-1] = '\0'; - - notificationManager.Push(Pinetime::Controllers::NotificationManager::Categories::SimpleAlert, s, messageSize); systemTask.PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification); } } |