InfiniTime.git

ref: 0.13.0

src/components/ble/NotificationManager.h


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once

#include <array>
#include <atomic>
#include <cstddef>
#include <cstdint>

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();
      bool IsVibrationEnabled();
      void ToggleVibrations();

      static constexpr size_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};
        bool vibrationEnabled = true;
    };
  }
}