diff options
| author | JF <jf@codingfield.com> | 2020-11-10 19:32:36 (GMT) |
|---|---|---|
| committer | JF <jf@codingfield.com> | 2020-11-10 19:32:36 (GMT) |
| commit | 04abc91f157f5925ffa404728291a69893acf8cf (patch) | |
| tree | 5c887c6d22ba8d901022ebae395a7b6c165d9dc0 /src/components/ble/NotificationManager.h | |
| parent | 65ecb65b57bd55582c1aa1a5babd4d76df89e621 (diff) | |
| parent | f0e1f98823e41bfc2d9743fa8de70c882f26f93b (diff) | |
Merge branch 'develop' into master
Diffstat (limited to 'src/components/ble/NotificationManager.h')
| -rw-r--r-- | src/components/ble/NotificationManager.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/components/ble/NotificationManager.h b/src/components/ble/NotificationManager.h new file mode 100644 index 0000000..49fe830 --- /dev/null +++ b/src/components/ble/NotificationManager.h @@ -0,0 +1,43 @@ +#pragma once + +#include <array> +#include <atomic> + +namespace Pinetime { + namespace Controllers { + class NotificationManager { + public: + enum class Categories {Unknown, SimpleAlert, Email, News, IncomingCall, MissedCall, Sms, VoiceMail, Schedule, HighProriotyAlert, InstantMessage }; + static constexpr uint8_t MessageSize{100}; + + struct Notification { + using Id = uint8_t; + Id id; + bool valid = false; + uint8_t index; + std::array<char, MessageSize+1> message; + Categories category = Categories::Unknown; + }; + Notification::Id nextId {0}; + + void Push(Notification&& notif); + Notification GetLastNotification(); + Notification GetNext(Notification::Id id); + Notification GetPrevious(Notification::Id id); + bool ClearNewNotificationFlag(); + bool AreNewNotificationsAvailable(); + + static constexpr uint8_t MaximumMessageSize() { return MessageSize; }; + size_t NbNotifications() const; + + private: + Notification::Id GetNextId(); + static constexpr uint8_t TotalNbNotifications = 5; + std::array<Notification, TotalNbNotifications> notifications; + uint8_t readIndex = 0; + uint8_t writeIndex = 0; + bool empty = true; + std::atomic<bool> newNotification{false}; + }; + } +}
\ No newline at end of file |
