440ae412b9
Fix bug in message handling that would ignore the last character of the notification.
43 lines
1.4 KiB
C++
43 lines
1.4 KiB
C++
#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;
|
|
uint8_t number = TotalNbNotifications;
|
|
std::array<char, MessageSize+1> message;
|
|
Categories category = Categories::Unknown;
|
|
};
|
|
Notification::Id nextId {0};
|
|
|
|
void Push(Categories category, const char* message, uint8_t messageSize);
|
|
Notification GetLastNotification();
|
|
Notification GetNext(Notification::Id id);
|
|
Notification GetPrevious(Notification::Id id);
|
|
bool ClearNewNotificationFlag();
|
|
bool AreNewNotificationsAvailable();
|
|
|
|
static constexpr uint8_t MaximumMessageSize() { return MessageSize; };
|
|
|
|
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};
|
|
};
|
|
}
|
|
} |