From 95ff285991d399498d9bd7f60a503ef7665822ce Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Sat, 18 Jun 2022 12:54:41 +0300 Subject: Remove backup brightness feature (#1180) This feature is not needed and is probably more likely to cause issues. It's better to just use brightnessController.Set(settingsController.GetBrightness()); --- src/components/brightness/BrightnessController.cpp | 10 +--------- src/components/brightness/BrightnessController.h | 4 ---- 2 files changed, 1 insertion(+), 13 deletions(-) (limited to 'src/components') diff --git a/src/components/brightness/BrightnessController.cpp b/src/components/brightness/BrightnessController.cpp index 2d9f980a..0392158c 100644 --- a/src/components/brightness/BrightnessController.cpp +++ b/src/components/brightness/BrightnessController.cpp @@ -74,14 +74,6 @@ BrightnessController::Levels BrightnessController::Level() const { return level; } -void BrightnessController::Backup() { - backupLevel = level; -} - -void BrightnessController::Restore() { - Set(backupLevel); -} - void BrightnessController::Step() { switch (level) { case Levels::Low: @@ -123,4 +115,4 @@ const char* BrightnessController::ToString() { default: return "???"; } -} \ No newline at end of file +} diff --git a/src/components/brightness/BrightnessController.h b/src/components/brightness/BrightnessController.h index 0d7ac2ff..7f86759a 100644 --- a/src/components/brightness/BrightnessController.h +++ b/src/components/brightness/BrightnessController.h @@ -15,15 +15,11 @@ namespace Pinetime { void Higher(); void Step(); - void Backup(); - void Restore(); - const char* GetIcon(); const char* ToString(); private: Levels level = Levels::High; - Levels backupLevel = Levels::High; }; } } -- cgit v1.2.3-70-g09d2 From 2c75e7aad8aa8d7b50dd3ea795bdc2938992aa69 Mon Sep 17 00:00:00 2001 From: Simon Willshire Date: Thu, 19 May 2022 13:59:09 -0400 Subject: Dismiss notifications by swiping right Add a new interface `NotificationManager::Dismiss(id)` to delete a notification with the specified `id`. The animate the notification dismiss the `RightAnim` transition to a black screen is used. After the dismiss the new message is swiped in from below or above. If we dismiss the oldest message (when we are at 5/5, or 3/3), then the new message after a dismiss should appear to come from below. Otherwise (when we are at 2/3) the new message after a dismiss should appear to come from above. Rework the index code to show the index of the currently viewed notification. Instead of calculating the index relative to the oldest `id` introduce a new interface `NotificationManager::IndexOf(id)`. This is done because the `id` of the notifications in the buffer aren't continuous anymore (as some messages could have been dismissed). Rework notification ring buffer to have a beginIdx and a size internally to make the dismissal of notifications easier. Fixes: https://github.com/InfiniTimeOrg/InfiniTime/issues/176 Co-authored-by: Simon Willshire Co-authored-by: Reinhold Gschweicher --- src/components/ble/NotificationManager.cpp | 145 +++++++++++++++--------- src/components/ble/NotificationManager.h | 31 +++-- src/displayapp/screens/Notifications.cpp | 175 +++++++++++++++++++++-------- src/displayapp/screens/Notifications.h | 18 ++- 4 files changed, 255 insertions(+), 114 deletions(-) (limited to 'src/components') diff --git a/src/components/ble/NotificationManager.cpp b/src/components/ble/NotificationManager.cpp index ec99c4ed..223f6221 100644 --- a/src/components/ble/NotificationManager.cpp +++ b/src/components/ble/NotificationManager.cpp @@ -1,6 +1,7 @@ #include "components/ble/NotificationManager.h" #include #include +#include using namespace Pinetime::Controllers; @@ -9,73 +10,117 @@ constexpr uint8_t NotificationManager::MessageSize; void NotificationManager::Push(NotificationManager::Notification&& notif) { notif.id = GetNextId(); notif.valid = true; - notifications[writeIndex] = std::move(notif); - writeIndex = (writeIndex + 1 < TotalNbNotifications) ? writeIndex + 1 : 0; - if (!empty) - readIndex = (readIndex + 1 < TotalNbNotifications) ? readIndex + 1 : 0; - else - empty = false; - newNotification = true; -} - -NotificationManager::Notification NotificationManager::GetLastNotification() { - NotificationManager::Notification notification = notifications[readIndex]; - notification.index = 1; - return notification; + if (beginIdx > 0) { + --beginIdx; + } else { + beginIdx = notifications.size() - 1; + } + notifications[beginIdx] = std::move(notif); + if (size < notifications.size()) { + size++; + } } NotificationManager::Notification::Id NotificationManager::GetNextId() { return nextId++; } -NotificationManager::Notification NotificationManager::GetNext(NotificationManager::Notification::Id id) { - auto currentIterator = std::find_if(notifications.begin(), notifications.end(), [id](const Notification& n) { - return n.valid && n.id == id; - }); - if (currentIterator == notifications.end() || currentIterator->id != id) - return Notification {}; - - auto& lastNotification = notifications[readIndex]; - - NotificationManager::Notification result; - - if (currentIterator == (notifications.end() - 1)) - result = *(notifications.begin()); - else - result = *(currentIterator + 1); - - if (result.id <= id) +NotificationManager::Notification NotificationManager::GetLastNotification() const { + if (this->IsEmpty()) { return {}; + } + return this->At(0); +} - result.index = (lastNotification.id - result.id) + 1; - return result; +const NotificationManager::Notification& NotificationManager::At(NotificationManager::Notification::Idx idx) const { + if (idx >= notifications.size()) { + assert(false); + return notifications.at(beginIdx); // this should not happen + } + size_t read_idx = (beginIdx + idx) % notifications.size(); + return notifications.at(read_idx); } -NotificationManager::Notification NotificationManager::GetPrevious(NotificationManager::Notification::Id id) { - auto currentIterator = std::find_if(notifications.begin(), notifications.end(), [id](const Notification& n) { - return n.valid && n.id == id; - }); - if (currentIterator == notifications.end() || currentIterator->id != id) - return Notification {}; +NotificationManager::Notification& NotificationManager::At(NotificationManager::Notification::Idx idx) { + if (idx >= notifications.size()) { + assert(false); + return notifications.at(beginIdx); // this should not happen + } + size_t read_idx = (beginIdx + idx) % notifications.size(); + return notifications.at(read_idx); +} - auto& lastNotification = notifications[readIndex]; +NotificationManager::Notification::Idx NotificationManager::IndexOf(NotificationManager::Notification::Id id) const { + for (NotificationManager::Notification::Idx idx = 0; idx < this->size; idx++) { + const NotificationManager::Notification& notification = this->At(idx); + if (notification.id == id) { + return idx; + } + } + return size; +} - NotificationManager::Notification result; +NotificationManager::Notification NotificationManager::Get(NotificationManager::Notification::Id id) const { + NotificationManager::Notification::Idx idx = this->IndexOf(id); + if (idx == this->size) { + return {}; + } + return this->At(idx); +} - if (currentIterator == notifications.begin()) - result = *(notifications.end() - 1); - else - result = *(currentIterator - 1); +NotificationManager::Notification NotificationManager::GetNext(NotificationManager::Notification::Id id) const { + NotificationManager::Notification::Idx idx = this->IndexOf(id); + if (idx == this->size) { + return {}; + } + if (idx == 0 || idx > notifications.size()) { + return {}; + } + return this->At(idx - 1); +} - if (result.id >= id) +NotificationManager::Notification NotificationManager::GetPrevious(NotificationManager::Notification::Id id) const { + NotificationManager::Notification::Idx idx = this->IndexOf(id); + if (idx == this->size) { + return {}; + } + if (static_cast(idx + 1) >= notifications.size()) { return {}; + } + return this->At(idx + 1); +} + +void NotificationManager::DismissIdx(NotificationManager::Notification::Idx idx) { + if (this->IsEmpty()) { + return; + } + if (idx >= size) { + assert(false); + return; // this should not happen + } + if (idx == 0) { // just remove the first element, don't need to change the other elements + notifications.at(beginIdx).valid = false; + beginIdx = (beginIdx + 1) % notifications.size(); + } else { + // overwrite the specified entry by moving all later messages one index to the front + for (size_t i = idx; i < size - 1; ++i) { + this->At(i) = this->At(i + 1); + } + this->At(size - 1).valid = false; + } + --size; +} - result.index = (lastNotification.id - result.id) + 1; - return result; +void NotificationManager::Dismiss(NotificationManager::Notification::Id id) { + NotificationManager::Notification::Idx idx = this->IndexOf(id); + if (idx == this->size) { + return; + } + this->DismissIdx(idx); } -bool NotificationManager::AreNewNotificationsAvailable() { +bool NotificationManager::AreNewNotificationsAvailable() const { return newNotification; } @@ -84,9 +129,7 @@ bool NotificationManager::ClearNewNotificationFlag() { } size_t NotificationManager::NbNotifications() const { - return std::count_if(notifications.begin(), notifications.end(), [](const Notification& n) { - return n.valid; - }); + return size; } const char* NotificationManager::Notification::Message() const { diff --git a/src/components/ble/NotificationManager.h b/src/components/ble/NotificationManager.h index 40f174ea..4c199dbf 100644 --- a/src/components/ble/NotificationManager.h +++ b/src/components/ble/NotificationManager.h @@ -26,9 +26,9 @@ namespace Pinetime { struct Notification { using Id = uint8_t; - Id id; + using Idx = uint8_t; + Id id = 0; bool valid = false; - uint8_t index; uint8_t size; std::array message; Categories category = Categories::Unknown; @@ -36,27 +36,38 @@ namespace Pinetime { const char* Message() const; const char* Title() const; }; - Notification::Id nextId {0}; void Push(Notification&& notif); - Notification GetLastNotification(); - Notification GetNext(Notification::Id id); - Notification GetPrevious(Notification::Id id); + Notification GetLastNotification() const; + Notification Get(Notification::Id id) const; + Notification GetNext(Notification::Id id) const; + Notification GetPrevious(Notification::Id id) const; + // Return the index of the notification with the specified id, if not found return NbNotifications() + Notification::Idx IndexOf(Notification::Id id) const; bool ClearNewNotificationFlag(); - bool AreNewNotificationsAvailable(); + bool AreNewNotificationsAvailable() const; + void Dismiss(Notification::Id id); static constexpr size_t MaximumMessageSize() { return MessageSize; }; + bool IsEmpty() const { + return size == 0; + } size_t NbNotifications() const; private: + Notification::Id nextId {0}; Notification::Id GetNextId(); + const Notification& At(Notification::Idx idx) const; + Notification& At(Notification::Idx idx); + void DismissIdx(Notification::Idx idx); + static constexpr uint8_t TotalNbNotifications = 5; std::array notifications; - uint8_t readIndex = 0; - uint8_t writeIndex = 0; - bool empty = true; + size_t beginIdx = TotalNbNotifications - 1; // index of the newest notification + size_t size = 0; // number of valid notifications in buffer + std::atomic newNotification {false}; }; } diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp index d7fe93a0..9c0d28a8 100644 --- a/src/displayapp/screens/Notifications.cpp +++ b/src/displayapp/screens/Notifications.cpp @@ -3,6 +3,7 @@ #include "components/ble/MusicService.h" #include "components/ble/AlertNotificationService.h" #include "displayapp/screens/Symbols.h" +#include using namespace Pinetime::Applications::Screens; extern lv_font_t jetbrains_mono_extrabold_compressed; @@ -20,30 +21,23 @@ Notifications::Notifications(DisplayApp* app, motorController {motorController}, systemTask {systemTask}, mode {mode} { + notificationManager.ClearNewNotificationFlag(); auto notification = notificationManager.GetLastNotification(); if (notification.valid) { currentId = notification.id; currentItem = std::make_unique(notification.Title(), notification.Message(), - notification.index, + 1, notification.category, notificationManager.NbNotifications(), - mode, alertNotificationService, motorController); validDisplay = true; } else { - currentItem = std::make_unique("Notification", - "No notification to display", - 0, - notification.category, - notificationManager.NbNotifications(), - Modes::Preview, - alertNotificationService, - motorController); + currentItem = std::make_unique(alertNotificationService, motorController); + validDisplay = false; } - if (mode == Modes::Preview) { systemTask.PushMessage(System::Messages::DisableSleeping); if (notification.category == Controllers::NotificationManager::Categories::IncomingCall) { @@ -77,7 +71,7 @@ Notifications::~Notifications() { void Notifications::Refresh() { if (mode == Modes::Preview && timeoutLine != nullptr) { TickType_t tick = xTaskGetTickCount(); - int32_t pos = 240 - ((tick - timeoutTickCountStart) / (timeoutLength / 240)); + int32_t pos = LV_HOR_RES - ((tick - timeoutTickCountStart) / (timeoutLength / LV_HOR_RES)); if (pos <= 0) { running = false; } else { @@ -85,6 +79,40 @@ void Notifications::Refresh() { lv_line_set_points(timeoutLine, timeoutLinePoints, 2); } } + + if (dismissingNotification) { + dismissingNotification = false; + auto notification = notificationManager.Get(currentId); + if (!notification.valid) { + notification = notificationManager.GetLastNotification(); + } + currentId = notification.id; + + if (!notification.valid) { + validDisplay = false; + } + + currentItem.reset(nullptr); + if (afterDismissNextMessageFromAbove) { + app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down); + } else { + app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up); + } + + if (validDisplay) { + Controllers::NotificationManager::Notification::Idx currentIdx = notificationManager.IndexOf(currentId); + currentItem = std::make_unique(notification.Title(), + notification.Message(), + currentIdx + 1, + notification.category, + notificationManager.NbNotifications(), + alertNotificationService, + motorController); + } else { + currentItem = std::make_unique(alertNotificationService, motorController); + } + } + running = currentItem->IsRunning() && running; } @@ -108,52 +136,82 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) { } switch (event) { + case Pinetime::Applications::TouchEvents::SwipeRight: + if (validDisplay) { + Controllers::NotificationManager::Notification previousNotification; + auto previousMessage = notificationManager.GetPrevious(currentId); + auto nextMessage = notificationManager.GetNext(currentId); + if (!previousMessage.valid) { + // dismissed last message (like 5/5), need to go one message down (like 4/4) + afterDismissNextMessageFromAbove = false; // show next message coming from below + } else { + afterDismissNextMessageFromAbove = true; // show next message coming from above + } + notificationManager.Dismiss(currentId); + if (previousMessage.valid) { + currentId = previousMessage.id; + } else if (nextMessage.valid) { + currentId = nextMessage.id; + } else { + // don't update id, won't be found be refresh and try to load latest message or no message box + } + currentItem.reset(nullptr); + app->SetFullRefresh(DisplayApp::FullRefreshDirections::RightAnim); + // create black "inTransition" screen + currentItem = std::make_unique(alertNotificationService, motorController, true); + dismissingNotification = true; + return true; + } + return false; case Pinetime::Applications::TouchEvents::SwipeDown: { Controllers::NotificationManager::Notification previousNotification; - if (validDisplay) + if (validDisplay) { previousNotification = notificationManager.GetPrevious(currentId); - else + } else { previousNotification = notificationManager.GetLastNotification(); + } - if (!previousNotification.valid) + if (!previousNotification.valid) { return true; + } - validDisplay = true; currentId = previousNotification.id; + Controllers::NotificationManager::Notification::Idx currentIdx = notificationManager.IndexOf(currentId); + validDisplay = true; currentItem.reset(nullptr); app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down); currentItem = std::make_unique(previousNotification.Title(), previousNotification.Message(), - previousNotification.index, + currentIdx + 1, previousNotification.category, notificationManager.NbNotifications(), - mode, alertNotificationService, motorController); } return true; case Pinetime::Applications::TouchEvents::SwipeUp: { Controllers::NotificationManager::Notification nextNotification; - if (validDisplay) + if (validDisplay) { nextNotification = notificationManager.GetNext(currentId); - else + } else { nextNotification = notificationManager.GetLastNotification(); + } if (!nextNotification.valid) { running = false; return false; } - validDisplay = true; currentId = nextNotification.id; + Controllers::NotificationManager::Notification::Idx currentIdx = notificationManager.IndexOf(currentId); + validDisplay = true; currentItem.reset(nullptr); app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up); currentItem = std::make_unique(nextNotification.Title(), nextNotification.Message(), - nextNotification.index, + currentIdx + 1, nextNotification.category, notificationManager.NbNotifications(), - mode, alertNotificationService, motorController); } @@ -170,33 +228,54 @@ namespace { } } +Notifications::NotificationItem::NotificationItem(Pinetime::Controllers::AlertNotificationService& alertNotificationService, + Pinetime::Controllers::MotorController& motorController, + bool isTransition) + : NotificationItem("Notification", + "No notification to display", + 0, + Controllers::NotificationManager::Categories::Unknown, + 0, + alertNotificationService, + motorController, + isTransition) { +} + Notifications::NotificationItem::NotificationItem(const char* title, const char* msg, uint8_t notifNr, Controllers::NotificationManager::Categories category, uint8_t notifNb, - Modes mode, Pinetime::Controllers::AlertNotificationService& alertNotificationService, - Pinetime::Controllers::MotorController& motorController) - : mode {mode}, alertNotificationService {alertNotificationService}, motorController {motorController} { - lv_obj_t* container1 = lv_cont_create(lv_scr_act(), NULL); - - lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x38, 0x38, 0x38)); - lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); - lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); - lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); - - lv_obj_set_pos(container1, 0, 50); - lv_obj_set_size(container1, LV_HOR_RES, 190); - - lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); - lv_cont_set_fit(container1, LV_FIT_NONE); - - lv_obj_t* alert_count = lv_label_create(lv_scr_act(), nullptr); + Pinetime::Controllers::MotorController& motorController, + bool isTransition) + : alertNotificationService {alertNotificationService}, motorController {motorController} { + if (isTransition) { + return; // nothing to do, just a black box + } + container = lv_cont_create(lv_scr_act(), nullptr); + lv_obj_set_size(container, LV_HOR_RES, LV_VER_RES); + lv_obj_set_style_local_bg_color(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); + lv_obj_set_style_local_pad_all(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); + lv_obj_set_style_local_pad_inner(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); + lv_obj_set_style_local_border_width(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); + + subject_container = lv_cont_create(container, nullptr); + lv_obj_set_style_local_bg_color(subject_container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x38, 0x38, 0x38)); + lv_obj_set_style_local_pad_all(subject_container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); + lv_obj_set_style_local_pad_inner(subject_container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); + lv_obj_set_style_local_border_width(subject_container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); + + lv_obj_set_pos(subject_container, 0, 50); + lv_obj_set_size(subject_container, LV_HOR_RES, LV_VER_RES - 50); + lv_cont_set_layout(subject_container, LV_LAYOUT_COLUMN_LEFT); + lv_cont_set_fit(subject_container, LV_FIT_NONE); + + lv_obj_t* alert_count = lv_label_create(container, nullptr); lv_label_set_text_fmt(alert_count, "%i/%i", notifNr, notifNb); lv_obj_align(alert_count, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 16); - lv_obj_t* alert_type = lv_label_create(lv_scr_act(), nullptr); + lv_obj_t* alert_type = lv_label_create(container, nullptr); lv_obj_set_style_local_text_color(alert_type, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xb0, 0xb0, 0xb0)); if (title == nullptr) { lv_label_set_text_static(alert_type, "Notification"); @@ -217,27 +296,27 @@ Notifications::NotificationItem::NotificationItem(const char* title, ///////// switch (category) { default: { - lv_obj_t* alert_subject = lv_label_create(container1, nullptr); + lv_obj_t* alert_subject = lv_label_create(subject_container, nullptr); lv_obj_set_style_local_text_color(alert_subject, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xff, 0xb0, 0x0)); lv_label_set_long_mode(alert_subject, LV_LABEL_LONG_BREAK); lv_obj_set_width(alert_subject, LV_HOR_RES - 20); lv_label_set_text(alert_subject, msg); } break; case Controllers::NotificationManager::Categories::IncomingCall: { - lv_obj_set_height(container1, 108); - lv_obj_t* alert_subject = lv_label_create(container1, nullptr); + lv_obj_set_height(subject_container, 108); + lv_obj_t* alert_subject = lv_label_create(subject_container, nullptr); lv_obj_set_style_local_text_color(alert_subject, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xff, 0xb0, 0x0)); lv_label_set_long_mode(alert_subject, LV_LABEL_LONG_BREAK); lv_obj_set_width(alert_subject, LV_HOR_RES - 20); lv_label_set_text_static(alert_subject, "Incoming call from"); - lv_obj_t* alert_caller = lv_label_create(container1, nullptr); + lv_obj_t* alert_caller = lv_label_create(subject_container, nullptr); lv_obj_align(alert_caller, alert_subject, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); lv_label_set_long_mode(alert_caller, LV_LABEL_LONG_BREAK); lv_obj_set_width(alert_caller, LV_HOR_RES - 20); lv_label_set_text(alert_caller, msg); - bt_accept = lv_btn_create(lv_scr_act(), nullptr); + bt_accept = lv_btn_create(container, nullptr); bt_accept->user_data = this; lv_obj_set_event_cb(bt_accept, CallEventHandler); lv_obj_set_size(bt_accept, 76, 76); @@ -246,7 +325,7 @@ Notifications::NotificationItem::NotificationItem(const char* title, lv_label_set_text_static(label_accept, Symbols::phone); lv_obj_set_style_local_bg_color(bt_accept, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x0, 0xb0, 0x0)); - bt_reject = lv_btn_create(lv_scr_act(), nullptr); + bt_reject = lv_btn_create(container, nullptr); bt_reject->user_data = this; lv_obj_set_event_cb(bt_reject, CallEventHandler); lv_obj_set_size(bt_reject, 76, 76); @@ -255,7 +334,7 @@ Notifications::NotificationItem::NotificationItem(const char* title, lv_label_set_text_static(label_reject, Symbols::phoneSlash); lv_obj_set_style_local_bg_color(bt_reject, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); - bt_mute = lv_btn_create(lv_scr_act(), nullptr); + bt_mute = lv_btn_create(container, nullptr); bt_mute->user_data = this; lv_obj_set_event_cb(bt_mute, CallEventHandler); lv_obj_set_size(bt_mute, 76, 76); diff --git a/src/displayapp/screens/Notifications.h b/src/displayapp/screens/Notifications.h index 74160356..d3088f80 100644 --- a/src/displayapp/screens/Notifications.h +++ b/src/displayapp/screens/Notifications.h @@ -33,14 +33,17 @@ namespace Pinetime { class NotificationItem { public: + NotificationItem(Pinetime::Controllers::AlertNotificationService& alertNotificationService, + Pinetime::Controllers::MotorController& motorController, + bool isTransition = false); NotificationItem(const char* title, const char* msg, uint8_t notifNr, Controllers::NotificationManager::Categories, uint8_t notifNb, - Modes mode, Pinetime::Controllers::AlertNotificationService& alertNotificationService, - Pinetime::Controllers::MotorController& motorController); + Pinetime::Controllers::MotorController& motorController, + bool isTransition = false); ~NotificationItem(); bool IsRunning() const { return running; @@ -48,16 +51,17 @@ namespace Pinetime { void OnCallButtonEvent(lv_obj_t*, lv_event_t event); private: - lv_obj_t* container1; + lv_obj_t* container; + lv_obj_t* subject_container; lv_obj_t* bt_accept; lv_obj_t* bt_mute; lv_obj_t* bt_reject; lv_obj_t* label_accept; lv_obj_t* label_mute; lv_obj_t* label_reject; - Modes mode; Pinetime::Controllers::AlertNotificationService& alertNotificationService; Pinetime::Controllers::MotorController& motorController; + bool running = true; }; @@ -68,15 +72,19 @@ namespace Pinetime { System::SystemTask& systemTask; Modes mode = Modes::Normal; std::unique_ptr currentItem; - Controllers::NotificationManager::Notification::Id currentId; + Pinetime::Controllers::NotificationManager::Notification::Id currentId; bool validDisplay = false; + bool afterDismissNextMessageFromAbove = false; lv_point_t timeoutLinePoints[2] {{0, 1}, {239, 1}}; lv_obj_t* timeoutLine = nullptr; TickType_t timeoutTickCountStart; + static const TickType_t timeoutLength = pdMS_TO_TICKS(7000); bool interacted = true; + bool dismissingNotification = false; + lv_task_t* taskRefresh; }; } -- cgit v1.2.3-70-g09d2 From 69563ed03155eb861f8b8ada1df1325995fab51b Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Sun, 21 Aug 2022 14:52:38 +0300 Subject: Add sleep mode which disables notifications, touch- and motion wakeup (#1261) --- src/components/settings/Settings.h | 4 +- src/displayapp/fonts/fonts.json | 2 +- src/displayapp/screens/Symbols.h | 1 + src/displayapp/screens/settings/QuickSettings.cpp | 55 ++++++++++++++--------- src/displayapp/screens/settings/QuickSettings.h | 2 +- src/systemtask/SystemTask.cpp | 25 ++++++----- 6 files changed, 54 insertions(+), 35 deletions(-) (limited to 'src/components') diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 3b113ead..478408f6 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -9,7 +9,7 @@ namespace Pinetime { class Settings { public: enum class ClockType : uint8_t { H24, H12 }; - enum class Notification : uint8_t { ON, OFF }; + enum class Notification : uint8_t { On, Off, Sleep }; enum class ChimesOption : uint8_t { None, Hours, HalfHours }; enum class WakeUpMode : uint8_t { SingleTap = 0, @@ -219,7 +219,7 @@ namespace Pinetime { uint32_t screenTimeOut = 15000; ClockType clockType = ClockType::H24; - Notification notificationStatus = Notification::ON; + Notification notificationStatus = Notification::On; uint8_t clockFace = 0; ChimesOption chimesOption = ChimesOption::None; diff --git a/src/displayapp/fonts/fonts.json b/src/displayapp/fonts/fonts.json index 7c429625..006b8849 100644 --- a/src/displayapp/fonts/fonts.json +++ b/src/displayapp/fonts/fonts.json @@ -58,7 +58,7 @@ "sources": [ { "file": "material-design-icons/MaterialIcons-Regular.ttf", - "range": "0xf00b, 0xe3aa-0xe3ac, 0xe7f6-0xe7f7, 0xe8b8" + "range": "0xf00b, 0xe3aa-0xe3ac, 0xe7f6-0xe7f7, 0xe8b8, 0xef44" } ], "bpp": 1, diff --git a/src/displayapp/screens/Symbols.h b/src/displayapp/screens/Symbols.h index c6e76e36..1180ec6f 100644 --- a/src/displayapp/screens/Symbols.h +++ b/src/displayapp/screens/Symbols.h @@ -37,6 +37,7 @@ namespace Pinetime { static constexpr const char* chartLine = "\xEF\x88\x81"; static constexpr const char* eye = "\xEF\x81\xAE"; static constexpr const char* home = "\xEF\x80\x95"; + static constexpr const char* sleep = "\xEE\xBD\x84"; // lv_font_sys_48.c static constexpr const char* settings = "\xEE\xA2\xB8"; diff --git a/src/displayapp/screens/settings/QuickSettings.cpp b/src/displayapp/screens/settings/QuickSettings.cpp index fba5e876..b76affc9 100644 --- a/src/displayapp/screens/settings/QuickSettings.cpp +++ b/src/displayapp/screens/settings/QuickSettings.cpp @@ -10,13 +10,21 @@ using namespace Pinetime::Applications::Screens; namespace { void ButtonEventHandler(lv_obj_t* obj, lv_event_t event) { auto* screen = static_cast(obj->user_data); - screen->OnButtonEvent(obj, event); + if (event == LV_EVENT_CLICKED) { + screen->OnButtonEvent(obj); + } } void lv_update_task(struct _lv_task_t* task) { auto* user_data = static_cast(task->user_data); user_data->UpdateScreen(); } + + enum class ButtonState : lv_state_t { + NotificationsOn = LV_STATE_CHECKED, + NotificationsOff = LV_STATE_DEFAULT, + Sleep = 0x40, + }; } QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app, @@ -79,19 +87,24 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app, btn3 = lv_btn_create(lv_scr_act(), nullptr); btn3->user_data = this; lv_obj_set_event_cb(btn3, ButtonEventHandler); - lv_btn_set_checkable(btn3, true); lv_obj_add_style(btn3, LV_BTN_PART_MAIN, &btn_style); + lv_obj_set_style_local_bg_color(btn3, LV_BTN_PART_MAIN, static_cast(ButtonState::NotificationsOff), LV_COLOR_RED); + static constexpr lv_color_t violet = LV_COLOR_MAKE(0x60, 0x00, 0xff); + lv_obj_set_style_local_bg_color(btn3, LV_BTN_PART_MAIN, static_cast(ButtonState::Sleep), violet); lv_obj_set_size(btn3, buttonWidth, buttonHeight); lv_obj_align(btn3, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, buttonXOffset, 0); btn3_lvl = lv_label_create(btn3, nullptr); lv_obj_set_style_local_text_font(btn3_lvl, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48); - if (settingsController.GetNotificationStatus() == Controllers::Settings::Notification::ON) { - lv_obj_add_state(btn3, LV_STATE_CHECKED); + if (settingsController.GetNotificationStatus() == Controllers::Settings::Notification::On) { lv_label_set_text_static(btn3_lvl, Symbols::notificationsOn); - } else { + lv_obj_set_state(btn3, static_cast(ButtonState::NotificationsOn)); + } else if (settingsController.GetNotificationStatus() == Controllers::Settings::Notification::Off) { lv_label_set_text_static(btn3_lvl, Symbols::notificationsOff); + } else { + lv_label_set_text_static(btn3_lvl, Symbols::sleep); + lv_obj_set_state(btn3, static_cast(ButtonState::Sleep)); } btn4 = lv_btn_create(lv_scr_act(), nullptr); @@ -122,31 +135,33 @@ void QuickSettings::UpdateScreen() { statusIcons.Update(); } -void QuickSettings::OnButtonEvent(lv_obj_t* object, lv_event_t event) { - if (object == btn2 && event == LV_EVENT_CLICKED) { - - running = false; +void QuickSettings::OnButtonEvent(lv_obj_t* object) { + if (object == btn2) { app->StartApp(Apps::FlashLight, DisplayApp::FullRefreshDirections::Up); - - } else if (object == btn1 && event == LV_EVENT_CLICKED) { + } else if (object == btn1) { brightness.Step(); lv_label_set_text_static(btn1_lvl, brightness.GetIcon()); settingsController.SetBrightness(brightness.Level()); - } else if (object == btn3 && event == LV_EVENT_VALUE_CHANGED) { + } else if (object == btn3) { - if (lv_obj_get_state(btn3, LV_BTN_PART_MAIN) & LV_STATE_CHECKED) { - settingsController.SetNotificationStatus(Controllers::Settings::Notification::ON); - motorController.RunForDuration(35); - lv_label_set_text_static(btn3_lvl, Symbols::notificationsOn); - } else { - settingsController.SetNotificationStatus(Controllers::Settings::Notification::OFF); + if (settingsController.GetNotificationStatus() == Controllers::Settings::Notification::On) { + settingsController.SetNotificationStatus(Controllers::Settings::Notification::Off); lv_label_set_text_static(btn3_lvl, Symbols::notificationsOff); + lv_obj_set_state(btn3, static_cast(ButtonState::NotificationsOff)); + } else if (settingsController.GetNotificationStatus() == Controllers::Settings::Notification::Off) { + settingsController.SetNotificationStatus(Controllers::Settings::Notification::Sleep); + lv_label_set_text_static(btn3_lvl, Symbols::sleep); + lv_obj_set_state(btn3, static_cast(ButtonState::Sleep)); + } else { + settingsController.SetNotificationStatus(Controllers::Settings::Notification::On); + lv_label_set_text_static(btn3_lvl, Symbols::notificationsOn); + lv_obj_set_state(btn3, static_cast(ButtonState::NotificationsOn)); + motorController.RunForDuration(35); } - } else if (object == btn4 && event == LV_EVENT_CLICKED) { - running = false; + } else if (object == btn4) { settingsController.SetSettingsMenu(0); app->StartApp(Apps::Settings, DisplayApp::FullRefreshDirections::Up); } diff --git a/src/displayapp/screens/settings/QuickSettings.h b/src/displayapp/screens/settings/QuickSettings.h index cd342b0c..f555d034 100644 --- a/src/displayapp/screens/settings/QuickSettings.h +++ b/src/displayapp/screens/settings/QuickSettings.h @@ -27,7 +27,7 @@ namespace Pinetime { ~QuickSettings() override; - void OnButtonEvent(lv_obj_t* object, lv_event_t event); + void OnButtonEvent(lv_obj_t* object); void UpdateScreen(); diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index d3f12789..1c871fd2 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -251,7 +251,8 @@ void SystemTask::Work() { case Messages::TouchWakeUp: { if (touchHandler.GetNewTouchInfo()) { auto gesture = touchHandler.GestureGet(); - if (gesture != Pinetime::Applications::TouchEvents::None && + if (settingsController.GetNotificationStatus() != Controllers::Settings::Notification::Sleep && + gesture != Pinetime::Applications::TouchEvents::None && ((gesture == Pinetime::Applications::TouchEvents::DoubleTap && settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) || (gesture == Pinetime::Applications::TouchEvents::Tap && @@ -280,7 +281,7 @@ void SystemTask::Work() { } break; case Messages::OnNewNotification: - if (settingsController.GetNotificationStatus() == Pinetime::Controllers::Settings::Notification::ON) { + if (settingsController.GetNotificationStatus() == Pinetime::Controllers::Settings::Notification::On) { if (state == SystemTaskState::Sleeping) { GoToRunning(); } else { @@ -388,7 +389,8 @@ void SystemTask::Work() { break; case Messages::OnNewHour: using Pinetime::Controllers::AlarmController; - if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::Hours && + if (settingsController.GetNotificationStatus() != Controllers::Settings::Notification::Sleep && + settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::Hours && alarmController.State() != AlarmController::AlarmState::Alerting) { if (state == SystemTaskState::Sleeping) { GoToRunning(); @@ -399,7 +401,8 @@ void SystemTask::Work() { break; case Messages::OnNewHalfHour: using Pinetime::Controllers::AlarmController; - if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::HalfHours && + if (settingsController.GetNotificationStatus() != Controllers::Settings::Notification::Sleep && + settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::HalfHours && alarmController.State() != AlarmController::AlarmState::Alerting) { if (state == SystemTaskState::Sleeping) { GoToRunning(); @@ -483,13 +486,13 @@ void SystemTask::UpdateMotion() { motionController.IsSensorOk(motionSensor.IsOk()); motionController.Update(motionValues.x, motionValues.y, motionValues.z, motionValues.steps); - if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) && - motionController.Should_RaiseWake(state == SystemTaskState::Sleeping)) { - GoToRunning(); - } - if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) && - motionController.Should_ShakeWake(settingsController.GetShakeThreshold())) { - GoToRunning(); + if (settingsController.GetNotificationStatus() != Controllers::Settings::Notification::Sleep) { + if ((settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) && + motionController.Should_RaiseWake(state == SystemTaskState::Sleeping)) || + (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) && + motionController.Should_ShakeWake(settingsController.GetShakeThreshold()))) { + GoToRunning(); + } } } -- cgit v1.2.3-70-g09d2