From 28bc4344193cda2936ff0f69ae51aa79a7840998 Mon Sep 17 00:00:00 2001 From: JF Date: Sun, 18 Oct 2020 17:35:36 +0200 Subject: [PATCH 1/7] [WIP] New notification app that uses software scrolling effect. --- src/CMakeLists.txt | 2 + src/displayapp/Apps.h | 2 +- src/displayapp/DisplayApp.cpp | 2 + src/displayapp/screens/ApplicationList.cpp | 2 +- src/displayapp/screens/Notifications.cpp | 145 +++++++++++++++++++++ src/displayapp/screens/Notifications.h | 36 +++++ src/main.cpp | 2 +- 7 files changed, 188 insertions(+), 3 deletions(-) create mode 100644 src/displayapp/screens/Notifications.cpp create mode 100644 src/displayapp/screens/Notifications.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2f38ec58..4647e92d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -341,6 +341,7 @@ list(APPEND SOURCE_FILES displayapp/screens/Music.cpp displayapp/screens/FirmwareValidation.cpp displayapp/screens/ApplicationList.cpp + displayapp/screens/Notifications.cpp main.cpp drivers/St7789.cpp drivers/SpiNorFlash.cpp @@ -419,6 +420,7 @@ set(INCLUDE_FILES displayapp/screens/FirmwareValidation.h displayapp/screens/ApplicationList.h displayapp/Apps.h + displayapp/screens/Notifications.h drivers/St7789.h drivers/SpiNorFlash.h drivers/SpiMaster.h diff --git a/src/displayapp/Apps.h b/src/displayapp/Apps.h index 3842e4e5..bfa799ba 100644 --- a/src/displayapp/Apps.h +++ b/src/displayapp/Apps.h @@ -2,6 +2,6 @@ namespace Pinetime { namespace Applications { - enum class Apps {None, Launcher, Clock, SysInfo, Meter, Gauge, Brightness, Music, FirmwareValidation, Paint}; + enum class Apps {None, Launcher, Clock, SysInfo, Meter, Gauge, Brightness, Music, FirmwareValidation, Paint, Notifications}; } } \ No newline at end of file diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index d65e4f92..6653fa3d 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -8,6 +8,7 @@ #include #include "components/datetime/DateTimeController.h" #include +#include "displayapp/screens/Notifications.h" #include "displayapp/screens/Tile.h" #include "displayapp/screens/Meter.h" #include "displayapp/screens/Gauge.h" @@ -202,6 +203,7 @@ void DisplayApp::RunningState() { case Apps::Brightness : currentScreen.reset(new Screens::Brightness(this, brightnessController)); break; case Apps::Music : currentScreen.reset(new Screens::Music(this, systemTask.nimble().music())); break; case Apps::FirmwareValidation: currentScreen.reset(new Screens::FirmwareValidation(this, validator)); break; + case Apps::Notifications: currentScreen.reset(new Screens::Notifications(this)); break; } nextApp = Apps::None; } diff --git a/src/displayapp/screens/ApplicationList.cpp b/src/displayapp/screens/ApplicationList.cpp index 71ba91c4..27590b97 100644 --- a/src/displayapp/screens/ApplicationList.cpp +++ b/src/displayapp/screens/ApplicationList.cpp @@ -58,7 +58,7 @@ std::unique_ptr ApplicationList::CreateScreen2() { {{Symbols::tachometer, Apps::Gauge}, {Symbols::asterisk, Apps::Meter}, {Symbols::paintbrush, Apps::Paint}, - {Symbols::none, Apps::None}, + {Symbols::shoe, Apps::Notifications}, {Symbols::none, Apps::None}, {Symbols::none, Apps::None} } diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp new file mode 100644 index 00000000..fd1225f3 --- /dev/null +++ b/src/displayapp/screens/Notifications.cpp @@ -0,0 +1,145 @@ +#include "Notifications.h" +#include "displayapp/DisplayApp.h" +#include + +using namespace Pinetime::Applications::Screens; + +Notifications::Notifications(DisplayApp* app) : Screen(app) { + + app->SetTouchMode(DisplayApp::TouchModes::Polling); +} + +Notifications::~Notifications() { + lv_obj_clean(lv_scr_act()); +} + +bool Notifications::Refresh() { + return running; +} + +void Notifications::OnObjectEvent(lv_obj_t *obj, lv_event_t event, uint32_t buttonId) { + +} + +bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) { return true; } + + +bool Notifications::OnButtonPushed() { + app->StartApp(Apps::Clock); + running = false; + return true; +} + + +Notifications::ListWidget::ListWidget() { + static lv_point_t valid_pos[] = {{0,0}, {0,1}}; + page = lv_tileview_create(lv_scr_act(), NULL); + lv_obj_set_size(page, LV_HOR_RES, LV_VER_RES); + lv_obj_align(page, NULL, LV_ALIGN_CENTER, 0, 0); + lv_tileview_set_valid_positions(page, valid_pos, 2); + + static lv_style_t pageStyle; + lv_style_copy(&pageStyle, lv_tileview_get_style(page, LV_TILEVIEW_STYLE_MAIN)); + + lv_tileview_set_style(page, LV_TILEVIEW_STYLE_MAIN, &pageStyle); + + + lv_obj_t* container1 = lv_cont_create(page, NULL); + static lv_style_t contStyle; + lv_style_copy(&contStyle, lv_cont_get_style(container1, LV_CONT_STYLE_MAIN)); + contStyle.body.padding.inner = 20; + lv_cont_set_style(container1, LV_CONT_STYLE_MAIN, &contStyle); + lv_obj_set_width(container1, LV_HOR_RES); + lv_obj_set_pos(container1, 0, 0); + lv_cont_set_layout(container1, LV_LAYOUT_COL_M); + lv_cont_set_fit2(container1, LV_FIT_FLOOD, LV_FIT_TIGHT); + + lv_tileview_add_element(page, container1); + + + lv_obj_t* t1 = lv_label_create(container1, NULL); + + static lv_style_t titleStyle; + static lv_style_t textStyle; + lv_style_copy(&titleStyle, lv_label_get_style(t1, LV_LABEL_STYLE_MAIN)); + lv_style_copy(&textStyle, lv_label_get_style(t1, LV_LABEL_STYLE_MAIN)); + + //titleStyle.body.main_color = LV_COLOR_RED; + //titleStyle.body.grad_color = LV_COLOR_RED; + titleStyle.body.padding.inner = 5; + + //textStyle.body.main_color = LV_COLOR_BLUE; + //textStyle.body.grad_color = LV_COLOR_BLUE; + textStyle.body.padding.inner = 5; + + lv_label_set_style(t1, LV_LABEL_STYLE_MAIN, &titleStyle); + lv_label_set_long_mode(t1, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(t1, true); + lv_obj_set_width(t1, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right) ); + lv_label_set_text(t1, "Message"); + + + lv_obj_t* l1 = lv_label_create(container1, NULL); + lv_label_set_style(l1, LV_PAGE_STYLE_BG, &textStyle); + lv_label_set_long_mode(l1, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(l1, true); + lv_obj_set_width(l1, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right) ); + lv_label_set_text(l1, "Marcel Pickett: Did you bring your ticket?"); + + /*---*/ + lv_obj_t* container2 = lv_cont_create(page, NULL); + lv_cont_set_style(container2, LV_CONT_STYLE_MAIN, &contStyle); + lv_obj_set_width(container2, LV_HOR_RES); + lv_obj_set_pos(container2, 0, lv_obj_get_y(container1) + lv_obj_get_height(container1)+5); + lv_cont_set_layout(container2, LV_LAYOUT_COL_M); + lv_cont_set_fit2(container2, LV_FIT_FLOOD, LV_FIT_TIGHT); + lv_tileview_add_element(page, container2); + + lv_obj_t* t2 = lv_label_create(container2, NULL); + lv_label_set_style(t2, LV_PAGE_STYLE_BG, &titleStyle); + lv_label_set_long_mode(t2, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(t2, true); + lv_obj_set_width(t2, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right) ); + lv_label_set_text(t2, "Alarm"); + + + lv_obj_t* l2 = lv_label_create(container2, NULL); + lv_label_set_style(l2, LV_PAGE_STYLE_BG, &textStyle); + lv_label_set_long_mode(l2, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(l2, true); + lv_obj_set_width(l2, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right) ); + lv_label_set_text(l2, "Missed: 09:30"); + + /*****/ + lv_obj_t* container3 = lv_cont_create(page, NULL); + lv_cont_set_style(container3, LV_CONT_STYLE_MAIN, &contStyle); + lv_obj_set_width(container3, LV_HOR_RES); + lv_obj_set_pos(container3, 0, lv_obj_get_y(container2) + lv_obj_get_height(container2)+5); + lv_cont_set_layout(container3, LV_LAYOUT_COL_M); + lv_cont_set_fit2(container3, LV_FIT_FLOOD, LV_FIT_TIGHT); + lv_tileview_add_element(page, container3); + + lv_obj_t* t3 = lv_label_create(container3, NULL); + lv_label_set_style(t3, LV_PAGE_STYLE_BG, &titleStyle); + lv_label_set_long_mode(t3, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(t3, true); + lv_obj_set_width(t3, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right) ); + lv_label_set_text(t3, "Spotify"); + + + lv_obj_t* l3 = lv_label_create(container3, NULL); + lv_label_set_style(l3, LV_PAGE_STYLE_BG, &textStyle); + lv_label_set_long_mode(l3, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(l3, true); + lv_obj_set_width(l3, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right) ); + lv_label_set_text(l3, "Now playing: Bame game - Kanye West"); + + + + + + + + + +} diff --git a/src/displayapp/screens/Notifications.h b/src/displayapp/screens/Notifications.h new file mode 100644 index 00000000..b4d0beda --- /dev/null +++ b/src/displayapp/screens/Notifications.h @@ -0,0 +1,36 @@ +#pragma once + +#include +#include "Screen.h" +#include +#include "Modal.h" +#include +#include + +namespace Pinetime { + namespace Applications { + namespace Screens { + class Notifications : public Screen { + public: + explicit Notifications(DisplayApp* app); + ~Notifications() override; + + bool Refresh() override; + bool OnButtonPushed() override; + void OnObjectEvent(lv_obj_t* obj, lv_event_t event, uint32_t buttonId); + bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; + + private: + class ListWidget { + public: + ListWidget(); + private: + lv_obj_t* page = nullptr; + }; + + bool running = true; + ListWidget list; + }; + } + } +} diff --git a/src/main.cpp b/src/main.cpp index e3243362..45aac6de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,7 +29,7 @@ #if NRF_LOG_ENABLED -#include "Logging/NrfLogger.h" +#include "logging/NrfLogger.h" Pinetime::Logging::NrfLogger logger; #else #include "logging/DummyLogger.h" From 55427d83b87960903cd6213ac9c73e694ee547bd Mon Sep 17 00:00:00 2001 From: JF Date: Mon, 19 Oct 2020 21:46:41 +0200 Subject: [PATCH 2/7] [WIP] Add new notification UI that use HW scrolling effects. Both notification apps are available in the menu, we can compare them. --- src/CMakeLists.txt | 5 +- src/displayapp/Apps.h | 2 +- src/displayapp/DisplayApp.cpp | 2 + src/displayapp/screens/ApplicationList.cpp | 4 +- src/displayapp/screens/Notifications.cpp | 222 ++++++++++++------ src/displayapp/screens/Notifications.h | 36 +-- .../screens/Notifications_swscroll.cpp | 145 ++++++++++++ .../screens/Notifications_swscroll.h | 36 +++ 8 files changed, 356 insertions(+), 96 deletions(-) create mode 100644 src/displayapp/screens/Notifications_swscroll.cpp create mode 100644 src/displayapp/screens/Notifications_swscroll.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4647e92d..36c69311 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -342,6 +342,7 @@ list(APPEND SOURCE_FILES displayapp/screens/FirmwareValidation.cpp displayapp/screens/ApplicationList.cpp displayapp/screens/Notifications.cpp + displayapp/screens/Notifications_swscroll.cpp main.cpp drivers/St7789.cpp drivers/SpiNorFlash.cpp @@ -420,7 +421,8 @@ set(INCLUDE_FILES displayapp/screens/FirmwareValidation.h displayapp/screens/ApplicationList.h displayapp/Apps.h - displayapp/screens/Notifications.h + displayapp/screens/Notifications.h + displayapp/screens/Notifications_swscroll.h.h drivers/St7789.h drivers/SpiNorFlash.h drivers/SpiMaster.h @@ -749,7 +751,6 @@ elseif (USE_OPENOCD) COMMENT "flashing ${EXECUTABLE_NAME}.hex" ) else () - message() add_custom_target(FLASH_ERASE COMMAND ${OPENOCD_BIN_PATH} -f interface/stlink.cfg -c 'transport select hla_swd' -f target/nrf52.cfg -c init -c halt -c 'nrf5 mass_erase' -c reset -c shutdown COMMENT "erasing flashing" diff --git a/src/displayapp/Apps.h b/src/displayapp/Apps.h index bfa799ba..8241b188 100644 --- a/src/displayapp/Apps.h +++ b/src/displayapp/Apps.h @@ -2,6 +2,6 @@ namespace Pinetime { namespace Applications { - enum class Apps {None, Launcher, Clock, SysInfo, Meter, Gauge, Brightness, Music, FirmwareValidation, Paint, Notifications}; + enum class Apps {None, Launcher, Clock, SysInfo, Meter, Gauge, Brightness, Music, FirmwareValidation, Paint, Notifications, Notifications2}; } } \ No newline at end of file diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 6653fa3d..ab4a5a7d 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -9,6 +9,7 @@ #include "components/datetime/DateTimeController.h" #include #include "displayapp/screens/Notifications.h" +#include "displayapp/screens/Notifications_swscroll.h" #include "displayapp/screens/Tile.h" #include "displayapp/screens/Meter.h" #include "displayapp/screens/Gauge.h" @@ -204,6 +205,7 @@ void DisplayApp::RunningState() { case Apps::Music : currentScreen.reset(new Screens::Music(this, systemTask.nimble().music())); break; case Apps::FirmwareValidation: currentScreen.reset(new Screens::FirmwareValidation(this, validator)); break; case Apps::Notifications: currentScreen.reset(new Screens::Notifications(this)); break; + case Apps::Notifications2: currentScreen.reset(new Screens::Notifications2(this)); break; } nextApp = Apps::None; } diff --git a/src/displayapp/screens/ApplicationList.cpp b/src/displayapp/screens/ApplicationList.cpp index 27590b97..8d986062 100644 --- a/src/displayapp/screens/ApplicationList.cpp +++ b/src/displayapp/screens/ApplicationList.cpp @@ -58,8 +58,8 @@ std::unique_ptr ApplicationList::CreateScreen2() { {{Symbols::tachometer, Apps::Gauge}, {Symbols::asterisk, Apps::Meter}, {Symbols::paintbrush, Apps::Paint}, - {Symbols::shoe, Apps::Notifications}, - {Symbols::none, Apps::None}, + {Symbols::shoe, Apps::Notifications}, + {Symbols::shoe, Apps::Notifications2}, {Symbols::none, Apps::None} } }; diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp index fd1225f3..3cd26353 100644 --- a/src/displayapp/screens/Notifications.cpp +++ b/src/displayapp/screens/Notifications.cpp @@ -1,12 +1,16 @@ -#include "Notifications.h" -#include "displayapp/DisplayApp.h" #include - +#include +#include +#include "Notifications.h" using namespace Pinetime::Applications::Screens; -Notifications::Notifications(DisplayApp* app) : Screen(app) { +Notifications::Notifications(DisplayApp* app) : Screen(app), screens{app, { + [this]() -> std::unique_ptr { return CreateScreen1(); }, + [this]() -> std::unique_ptr { return CreateScreen2(); }, + [this]() -> std::unique_ptr { return CreateScreen3(); } +} +} { - app->SetTouchMode(DisplayApp::TouchModes::Polling); } Notifications::~Notifications() { @@ -14,132 +18,196 @@ Notifications::~Notifications() { } bool Notifications::Refresh() { + screens.Refresh(); return running; } -void Notifications::OnObjectEvent(lv_obj_t *obj, lv_event_t event, uint32_t buttonId) { - +bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + return screens.OnTouchEvent(event); } -bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) { return true; } - bool Notifications::OnButtonPushed() { - app->StartApp(Apps::Clock); running = false; return true; } +std::unique_ptr Notifications::CreateScreen1() { + return std::unique_ptr(new Notifications::NotificationItem(app, "Message", "Marcel Pickett: Did you bring your ticket?", "Shot notif", "Short text", 1, 3)); +} -Notifications::ListWidget::ListWidget() { - static lv_point_t valid_pos[] = {{0,0}, {0,1}}; - page = lv_tileview_create(lv_scr_act(), NULL); - lv_obj_set_size(page, LV_HOR_RES, LV_VER_RES); - lv_obj_align(page, NULL, LV_ALIGN_CENTER, 0, 0); - lv_tileview_set_valid_positions(page, valid_pos, 2); +std::unique_ptr Notifications::CreateScreen2() { + return std::unique_ptr(new Notifications::NotificationItem(app, "Alarm", "Missed: 09:30", 2, 3)); +} - static lv_style_t pageStyle; - lv_style_copy(&pageStyle, lv_tileview_get_style(page, LV_TILEVIEW_STYLE_MAIN)); +std::unique_ptr Notifications::CreateScreen3() { + return std::unique_ptr(new Notifications::NotificationItem(app, "Spotify", "Now playing: Bame game - Kanye West", 3, 3)); +} - lv_tileview_set_style(page, LV_TILEVIEW_STYLE_MAIN, &pageStyle); +Notifications::NotificationItem::NotificationItem(Pinetime::Applications::DisplayApp *app, const char *title, const char* msg, uint8_t notifNr, uint8_t notifNb) : + Screen(app), notifNr{notifNr}, notifNb{notifNb} { - - lv_obj_t* container1 = lv_cont_create(page, NULL); + lv_obj_t* container1 = lv_cont_create(lv_scr_act(), NULL); static lv_style_t contStyle; lv_style_copy(&contStyle, lv_cont_get_style(container1, LV_CONT_STYLE_MAIN)); contStyle.body.padding.inner = 20; lv_cont_set_style(container1, LV_CONT_STYLE_MAIN, &contStyle); lv_obj_set_width(container1, LV_HOR_RES); + lv_obj_set_height(container1, LV_VER_RES); lv_obj_set_pos(container1, 0, 0); - lv_cont_set_layout(container1, LV_LAYOUT_COL_M); - lv_cont_set_fit2(container1, LV_FIT_FLOOD, LV_FIT_TIGHT); + lv_cont_set_layout(container1, LV_LAYOUT_OFF); + lv_cont_set_fit2(container1, LV_FIT_FLOOD, LV_FIT_FLOOD); - lv_tileview_add_element(page, container1); lv_obj_t* t1 = lv_label_create(container1, NULL); static lv_style_t titleStyle; static lv_style_t textStyle; + static lv_style_t bottomStyle; lv_style_copy(&titleStyle, lv_label_get_style(t1, LV_LABEL_STYLE_MAIN)); lv_style_copy(&textStyle, lv_label_get_style(t1, LV_LABEL_STYLE_MAIN)); - - //titleStyle.body.main_color = LV_COLOR_RED; - //titleStyle.body.grad_color = LV_COLOR_RED; + lv_style_copy(&bottomStyle, lv_label_get_style(t1, LV_LABEL_STYLE_MAIN)); titleStyle.body.padding.inner = 5; - - //textStyle.body.main_color = LV_COLOR_BLUE; - //textStyle.body.grad_color = LV_COLOR_BLUE; textStyle.body.padding.inner = 5; + titleStyle.body.grad_color = LV_COLOR_GRAY; + titleStyle.body.main_color = LV_COLOR_GRAY; + textStyle.body.border.part = LV_BORDER_NONE; + + //bottomStyle.body.padding.inner = 5; + bottomStyle.body.main_color = LV_COLOR_GREEN; + bottomStyle.body.grad_color = LV_COLOR_GREEN; + bottomStyle.body.border.part = LV_BORDER_TOP; + bottomStyle.body.border.color = LV_COLOR_RED; + lv_label_set_style(t1, LV_LABEL_STYLE_MAIN, &titleStyle); lv_label_set_long_mode(t1, LV_LABEL_LONG_BREAK); lv_label_set_body_draw(t1, true); lv_obj_set_width(t1, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right) ); - lv_label_set_text(t1, "Message"); + lv_label_set_text(t1, title); + lv_obj_set_pos(t1, titleStyle.body.padding.left, titleStyle.body.padding.top); + auto titleHeight = lv_obj_get_height(t1); lv_obj_t* l1 = lv_label_create(container1, NULL); - lv_label_set_style(l1, LV_PAGE_STYLE_BG, &textStyle); + lv_label_set_style(l1, LV_LABEL_STYLE_MAIN, &textStyle); + lv_obj_set_pos(l1, textStyle.body.padding.left, titleHeight + titleStyle.body.padding.bottom + textStyle.body.padding.bottom + textStyle.body.padding.top); + lv_label_set_long_mode(l1, LV_LABEL_LONG_BREAK); lv_label_set_body_draw(l1, true); lv_obj_set_width(l1, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right) ); - lv_label_set_text(l1, "Marcel Pickett: Did you bring your ticket?"); + lv_label_set_text(l1, msg); - /*---*/ - lv_obj_t* container2 = lv_cont_create(page, NULL); + lv_obj_t* bottomlabel = lv_label_create(container1, NULL); + lv_label_set_style(bottomlabel, LV_LABEL_STYLE_MAIN, &bottomStyle); + lv_obj_set_width(bottomlabel, LV_HOR_RES - (bottomStyle.body.padding.left + bottomStyle.body.padding.right) ); + snprintf(pageText, 4, "%d/%d", notifNr, notifNb); + lv_label_set_text(bottomlabel, pageText); + auto bottomHeight = lv_obj_get_height(bottomlabel); + lv_obj_set_pos(bottomlabel, 0, LV_VER_RES - (bottomHeight*2)); +} + +Notifications::NotificationItem::NotificationItem(Pinetime::Applications::DisplayApp *app, const char *title1, const char* msg1, const char *title2, const char* msg2, uint8_t notifNr, uint8_t notifNb) : + Screen(app), notifNr{notifNr}, notifNb{notifNb} { + + lv_obj_t* container1 = lv_cont_create(lv_scr_act(), NULL); + static lv_style_t contStyle; + lv_style_copy(&contStyle, lv_cont_get_style(container1, LV_CONT_STYLE_MAIN)); + contStyle.body.padding.inner = 20; + lv_cont_set_style(container1, LV_CONT_STYLE_MAIN, &contStyle); + lv_obj_set_width(container1, LV_HOR_RES); + lv_obj_set_height(container1, LV_VER_RES); + lv_obj_set_pos(container1, 0, 0); + lv_cont_set_layout(container1, LV_LAYOUT_OFF); + lv_cont_set_fit2(container1, LV_FIT_FLOOD, LV_FIT_FLOOD); + + + + lv_obj_t* t1 = lv_label_create(container1, NULL); + + static lv_style_t titleStyle; + static lv_style_t textStyle; + static lv_style_t bottomStyle; + lv_style_copy(&titleStyle, lv_label_get_style(t1, LV_LABEL_STYLE_MAIN)); + lv_style_copy(&textStyle, lv_label_get_style(t1, LV_LABEL_STYLE_MAIN)); + lv_style_copy(&bottomStyle, lv_label_get_style(t1, LV_LABEL_STYLE_MAIN)); + titleStyle.body.padding.inner = 5; + textStyle.body.padding.inner = 5; + titleStyle.body.grad_color = LV_COLOR_GRAY; + titleStyle.body.main_color = LV_COLOR_GRAY; + textStyle.body.border.part = LV_BORDER_NONE; + + //bottomStyle.body.padding.inner = 5; + bottomStyle.body.main_color = LV_COLOR_GREEN; + bottomStyle.body.grad_color = LV_COLOR_GREEN; + bottomStyle.body.border.part = LV_BORDER_TOP; + bottomStyle.body.border.color = LV_COLOR_RED; + + + lv_label_set_style(t1, LV_LABEL_STYLE_MAIN, &titleStyle); + lv_label_set_long_mode(t1, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(t1, true); + lv_obj_set_width(t1, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right) ); + lv_label_set_text(t1, title1); + lv_obj_set_pos(t1, titleStyle.body.padding.left, titleStyle.body.padding.top); + + auto titleHeight = lv_obj_get_height(t1); + + lv_obj_t* l1 = lv_label_create(container1, NULL); + lv_label_set_style(l1, LV_LABEL_STYLE_MAIN, &textStyle); + lv_obj_set_pos(l1, textStyle.body.padding.left, titleHeight + titleStyle.body.padding.bottom + textStyle.body.padding.bottom + textStyle.body.padding.top); + + lv_label_set_long_mode(l1, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(l1, true); + lv_obj_set_width(l1, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right) ); + lv_label_set_text(l1, msg1); + + auto bottomPos = lv_obj_get_y(l1) + lv_obj_get_height(l1) + textStyle.body.padding.bottom; + + /* + lv_obj_t* bottomlabel = lv_label_create(container1, NULL); + lv_label_set_style(bottomlabel, LV_LABEL_STYLE_MAIN, &bottomStyle); + lv_obj_set_width(bottomlabel, LV_HOR_RES - (bottomStyle.body.padding.left + bottomStyle.body.padding.right) ); + snprintf(pageText, 4, "%d/%d", notifNr, notifNb); + lv_label_set_text(bottomlabel, pageText); + auto bottomHeight = lv_obj_get_height(bottomlabel); + lv_obj_set_pos(bottomlabel, 0, LV_VER_RES - (bottomHeight*2)); + */ + + //------------------------------------------------- +/* + lv_obj_t* container2 = lv_cont_create(lv_scr_act(), NULL); lv_cont_set_style(container2, LV_CONT_STYLE_MAIN, &contStyle); lv_obj_set_width(container2, LV_HOR_RES); - lv_obj_set_pos(container2, 0, lv_obj_get_y(container1) + lv_obj_get_height(container1)+5); - lv_cont_set_layout(container2, LV_LAYOUT_COL_M); - lv_cont_set_fit2(container2, LV_FIT_FLOOD, LV_FIT_TIGHT); - lv_tileview_add_element(page, container2); + lv_obj_set_height(container2, LV_VER_RES - bottomPos); + lv_obj_set_pos(container2, 0, bottomPos); + lv_cont_set_layout(container2, LV_LAYOUT_OFF); + lv_cont_set_fit2(container2, LV_FIT_FLOOD, LV_FIT_FLOOD); +*/ + lv_obj_t* t2 = lv_label_create(container1, NULL); - lv_obj_t* t2 = lv_label_create(container2, NULL); - lv_label_set_style(t2, LV_PAGE_STYLE_BG, &titleStyle); + + lv_label_set_style(t2, LV_LABEL_STYLE_MAIN, &titleStyle); lv_label_set_long_mode(t2, LV_LABEL_LONG_BREAK); lv_label_set_body_draw(t2, true); lv_obj_set_width(t2, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right) ); - lv_label_set_text(t2, "Alarm"); + lv_label_set_text(t2, title2); + lv_obj_set_pos(t2, titleStyle.body.padding.left, bottomPos + titleStyle.body.padding.top); + auto title2Height = lv_obj_get_height(t2); + + lv_obj_t* l2 = lv_label_create(container1, NULL); + lv_label_set_style(l2, LV_LABEL_STYLE_MAIN, &textStyle); + lv_obj_set_pos(l2, textStyle.body.padding.left, bottomPos + title2Height + titleStyle.body.padding.bottom + textStyle.body.padding.bottom + textStyle.body.padding.top); - lv_obj_t* l2 = lv_label_create(container2, NULL); - lv_label_set_style(l2, LV_PAGE_STYLE_BG, &textStyle); lv_label_set_long_mode(l2, LV_LABEL_LONG_BREAK); lv_label_set_body_draw(l2, true); lv_obj_set_width(l2, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right) ); - lv_label_set_text(l2, "Missed: 09:30"); - - /*****/ - lv_obj_t* container3 = lv_cont_create(page, NULL); - lv_cont_set_style(container3, LV_CONT_STYLE_MAIN, &contStyle); - lv_obj_set_width(container3, LV_HOR_RES); - lv_obj_set_pos(container3, 0, lv_obj_get_y(container2) + lv_obj_get_height(container2)+5); - lv_cont_set_layout(container3, LV_LAYOUT_COL_M); - lv_cont_set_fit2(container3, LV_FIT_FLOOD, LV_FIT_TIGHT); - lv_tileview_add_element(page, container3); - - lv_obj_t* t3 = lv_label_create(container3, NULL); - lv_label_set_style(t3, LV_PAGE_STYLE_BG, &titleStyle); - lv_label_set_long_mode(t3, LV_LABEL_LONG_BREAK); - lv_label_set_body_draw(t3, true); - lv_obj_set_width(t3, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right) ); - lv_label_set_text(t3, "Spotify"); - - - lv_obj_t* l3 = lv_label_create(container3, NULL); - lv_label_set_style(l3, LV_PAGE_STYLE_BG, &textStyle); - lv_label_set_long_mode(l3, LV_LABEL_LONG_BREAK); - lv_label_set_body_draw(l3, true); - lv_obj_set_width(l3, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right) ); - lv_label_set_text(l3, "Now playing: Bame game - Kanye West"); - - - - - - - - + lv_label_set_text(l2, msg2); } + +Notifications::NotificationItem::~NotificationItem() { + lv_obj_clean(lv_scr_act()); +} diff --git a/src/displayapp/screens/Notifications.h b/src/displayapp/screens/Notifications.h index b4d0beda..e6f20877 100644 --- a/src/displayapp/screens/Notifications.h +++ b/src/displayapp/screens/Notifications.h @@ -1,11 +1,11 @@ #pragma once -#include +#include +#include + #include "Screen.h" -#include -#include "Modal.h" -#include -#include +#include "ScreenList.h" + namespace Pinetime { namespace Applications { @@ -17,19 +17,27 @@ namespace Pinetime { bool Refresh() override; bool OnButtonPushed() override; - void OnObjectEvent(lv_obj_t* obj, lv_event_t event, uint32_t buttonId); bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; private: - class ListWidget { - public: - ListWidget(); - private: - lv_obj_t* page = nullptr; - }; - + ScreenList<3> screens; bool running = true; - ListWidget list; + std::unique_ptr CreateScreen1(); + std::unique_ptr CreateScreen2(); + std::unique_ptr CreateScreen3(); + + class NotificationItem : public Screen { + public: + NotificationItem(DisplayApp* app, const char* title, const char* msg, uint8_t notifNr, uint8_t notifNb); + NotificationItem(DisplayApp* app, const char* title1, const char* msg1, const char* title2, const char* msg2, uint8_t notifNr, uint8_t notifNb); + ~NotificationItem() override; + bool Refresh() override {return false;} + + private: + uint8_t notifNr = 0; + uint8_t notifNb = 0; + char pageText[4]; + }; }; } } diff --git a/src/displayapp/screens/Notifications_swscroll.cpp b/src/displayapp/screens/Notifications_swscroll.cpp new file mode 100644 index 00000000..a5eb74e9 --- /dev/null +++ b/src/displayapp/screens/Notifications_swscroll.cpp @@ -0,0 +1,145 @@ +#include "Notifications_swscroll.h" +#include "displayapp/DisplayApp.h" +#include + +using namespace Pinetime::Applications::Screens; + +Notifications2::Notifications2(DisplayApp* app) : Screen(app) { + + app->SetTouchMode(DisplayApp::TouchModes::Polling); +} + +Notifications2::~Notifications2() { + lv_obj_clean(lv_scr_act()); +} + +bool Notifications2::Refresh() { + return running; +} + +void Notifications2::OnObjectEvent(lv_obj_t *obj, lv_event_t event, uint32_t buttonId) { + +} + +bool Notifications2::OnTouchEvent(Pinetime::Applications::TouchEvents event) { return true; } + + +bool Notifications2::OnButtonPushed() { + app->StartApp(Apps::Clock); + running = false; + return true; +} + + +Notifications2::ListWidget::ListWidget() { + static lv_point_t valid_pos[] = {{0,0}, {0,1}}; + page = lv_tileview_create(lv_scr_act(), NULL); + lv_obj_set_size(page, LV_HOR_RES, LV_VER_RES); + lv_obj_align(page, NULL, LV_ALIGN_CENTER, 0, 0); + lv_tileview_set_valid_positions(page, valid_pos, 2); + + static lv_style_t pageStyle; + lv_style_copy(&pageStyle, lv_tileview_get_style(page, LV_TILEVIEW_STYLE_MAIN)); + + lv_tileview_set_style(page, LV_TILEVIEW_STYLE_MAIN, &pageStyle); + + + lv_obj_t* container1 = lv_cont_create(page, NULL); + static lv_style_t contStyle; + lv_style_copy(&contStyle, lv_cont_get_style(container1, LV_CONT_STYLE_MAIN)); + contStyle.body.padding.inner = 20; + lv_cont_set_style(container1, LV_CONT_STYLE_MAIN, &contStyle); + lv_obj_set_width(container1, LV_HOR_RES); + lv_obj_set_pos(container1, 0, 0); + lv_cont_set_layout(container1, LV_LAYOUT_COL_M); + lv_cont_set_fit2(container1, LV_FIT_FLOOD, LV_FIT_TIGHT); + + lv_tileview_add_element(page, container1); + + + lv_obj_t* t1 = lv_label_create(container1, NULL); + + static lv_style_t titleStyle; + static lv_style_t textStyle; + lv_style_copy(&titleStyle, lv_label_get_style(t1, LV_LABEL_STYLE_MAIN)); + lv_style_copy(&textStyle, lv_label_get_style(t1, LV_LABEL_STYLE_MAIN)); + + //titleStyle.body.main_color = LV_COLOR_RED; + //titleStyle.body.grad_color = LV_COLOR_RED; + titleStyle.body.padding.inner = 5; + + //textStyle.body.main_color = LV_COLOR_BLUE; + //textStyle.body.grad_color = LV_COLOR_BLUE; + textStyle.body.padding.inner = 5; + + lv_label_set_style(t1, LV_LABEL_STYLE_MAIN, &titleStyle); + lv_label_set_long_mode(t1, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(t1, true); + lv_obj_set_width(t1, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right) ); + lv_label_set_text(t1, "Message"); + + + lv_obj_t* l1 = lv_label_create(container1, NULL); + lv_label_set_style(l1, LV_PAGE_STYLE_BG, &textStyle); + lv_label_set_long_mode(l1, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(l1, true); + lv_obj_set_width(l1, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right) ); + lv_label_set_text(l1, "Marcel Pickett: Did you bring your ticket?"); + + /*---*/ + lv_obj_t* container2 = lv_cont_create(page, NULL); + lv_cont_set_style(container2, LV_CONT_STYLE_MAIN, &contStyle); + lv_obj_set_width(container2, LV_HOR_RES); + lv_obj_set_pos(container2, 0, lv_obj_get_y(container1) + lv_obj_get_height(container1)+5); + lv_cont_set_layout(container2, LV_LAYOUT_COL_M); + lv_cont_set_fit2(container2, LV_FIT_FLOOD, LV_FIT_TIGHT); + lv_tileview_add_element(page, container2); + + lv_obj_t* t2 = lv_label_create(container2, NULL); + lv_label_set_style(t2, LV_PAGE_STYLE_BG, &titleStyle); + lv_label_set_long_mode(t2, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(t2, true); + lv_obj_set_width(t2, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right) ); + lv_label_set_text(t2, "Alarm"); + + + lv_obj_t* l2 = lv_label_create(container2, NULL); + lv_label_set_style(l2, LV_PAGE_STYLE_BG, &textStyle); + lv_label_set_long_mode(l2, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(l2, true); + lv_obj_set_width(l2, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right) ); + lv_label_set_text(l2, "Missed: 09:30"); + + /*****/ + lv_obj_t* container3 = lv_cont_create(page, NULL); + lv_cont_set_style(container3, LV_CONT_STYLE_MAIN, &contStyle); + lv_obj_set_width(container3, LV_HOR_RES); + lv_obj_set_pos(container3, 0, lv_obj_get_y(container2) + lv_obj_get_height(container2)+5); + lv_cont_set_layout(container3, LV_LAYOUT_COL_M); + lv_cont_set_fit2(container3, LV_FIT_FLOOD, LV_FIT_TIGHT); + lv_tileview_add_element(page, container3); + + lv_obj_t* t3 = lv_label_create(container3, NULL); + lv_label_set_style(t3, LV_PAGE_STYLE_BG, &titleStyle); + lv_label_set_long_mode(t3, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(t3, true); + lv_obj_set_width(t3, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right) ); + lv_label_set_text(t3, "Spotify"); + + + lv_obj_t* l3 = lv_label_create(container3, NULL); + lv_label_set_style(l3, LV_PAGE_STYLE_BG, &textStyle); + lv_label_set_long_mode(l3, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(l3, true); + lv_obj_set_width(l3, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right) ); + lv_label_set_text(l3, "Now playing: Bame game - Kanye West"); + + + + + + + + + +} diff --git a/src/displayapp/screens/Notifications_swscroll.h b/src/displayapp/screens/Notifications_swscroll.h new file mode 100644 index 00000000..48960797 --- /dev/null +++ b/src/displayapp/screens/Notifications_swscroll.h @@ -0,0 +1,36 @@ +#pragma once + +#include +#include "Screen.h" +#include +#include "Modal.h" +#include +#include + +namespace Pinetime { + namespace Applications { + namespace Screens { + class Notifications2 : public Screen { + public: + explicit Notifications2(DisplayApp* app); + ~Notifications2() override; + + bool Refresh() override; + bool OnButtonPushed() override; + void OnObjectEvent(lv_obj_t* obj, lv_event_t event, uint32_t buttonId); + bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; + + private: + class ListWidget { + public: + ListWidget(); + private: + lv_obj_t* page = nullptr; + }; + + bool running = true; + ListWidget list; + }; + } + } +} From ef5670c7e09a1a63fc5df4a066472ed7fe7550ff Mon Sep 17 00:00:00 2001 From: JF Date: Tue, 20 Oct 2020 20:57:39 +0200 Subject: [PATCH 3/7] Integrate new notification UI with notifications coming from BLE --- src/CMakeLists.txt | 10 +- src/components/ble/NotificationManager.cpp | 70 +++++- src/components/ble/NotificationManager.h | 15 +- src/displayapp/Apps.h | 2 +- src/displayapp/DisplayApp.cpp | 16 +- src/displayapp/screens/ApplicationList.cpp | 6 +- src/displayapp/screens/Clock.cpp | 21 +- src/displayapp/screens/Clock.h | 12 +- src/displayapp/screens/NotificationIcon.cpp | 8 + src/displayapp/screens/NotificationIcon.h | 12 + src/displayapp/screens/Notifications.cpp | 235 +++++++----------- src/displayapp/screens/Notifications.h | 36 ++- .../screens/Notifications_swscroll.cpp | 145 ----------- .../screens/Notifications_swscroll.h | 36 --- 14 files changed, 261 insertions(+), 363 deletions(-) create mode 100644 src/displayapp/screens/NotificationIcon.cpp create mode 100644 src/displayapp/screens/NotificationIcon.h delete mode 100644 src/displayapp/screens/Notifications_swscroll.cpp delete mode 100644 src/displayapp/screens/Notifications_swscroll.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 36c69311..b18c6ce4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -289,6 +289,8 @@ set(LVGL_SRC libs/lvgl/src/lv_objx/lv_slider.c libs/lvgl/src/lv_objx/lv_ddlist.c libs/lvgl/src/lv_objx/lv_ddlist.h + libs/lvgl/src/lv_objx/lv_line.c + libs/lvgl/src/lv_objx/lv_line.h ) list(APPEND IMAGE_FILES @@ -334,6 +336,7 @@ list(APPEND SOURCE_FILES displayapp/screens/Modal.cpp displayapp/screens/BatteryIcon.cpp displayapp/screens/BleIcon.cpp + displayapp/screens/NotificationIcon.cpp displayapp/screens/Brightness.cpp displayapp/screens/SystemInfo.cpp displayapp/screens/Label.cpp @@ -342,7 +345,6 @@ list(APPEND SOURCE_FILES displayapp/screens/FirmwareValidation.cpp displayapp/screens/ApplicationList.cpp displayapp/screens/Notifications.cpp - displayapp/screens/Notifications_swscroll.cpp main.cpp drivers/St7789.cpp drivers/SpiNorFlash.cpp @@ -412,7 +414,8 @@ set(INCLUDE_FILES displayapp/screens/DropDownDemo.h displayapp/screens/Modal.h displayapp/screens/BatteryIcon.h - displayapp/screens/BleIcon.cpp + displayapp/screens/BleIcon.h + displayapp/screens/NotificationIcon.h displayapp/screens/Brightness.h displayapp/screens/SystemInfo.h displayapp/screens/ScreenList.h @@ -421,8 +424,7 @@ set(INCLUDE_FILES displayapp/screens/FirmwareValidation.h displayapp/screens/ApplicationList.h displayapp/Apps.h - displayapp/screens/Notifications.h - displayapp/screens/Notifications_swscroll.h.h + displayapp/screens/Notifications.h drivers/St7789.h drivers/SpiNorFlash.h drivers/SpiMaster.h diff --git a/src/components/ble/NotificationManager.cpp b/src/components/ble/NotificationManager.cpp index 0aea0697..4297cde9 100644 --- a/src/components/ble/NotificationManager.cpp +++ b/src/components/ble/NotificationManager.cpp @@ -1,4 +1,5 @@ #include +#include #include "NotificationManager.h" using namespace Pinetime::Controllers; @@ -11,20 +12,69 @@ void NotificationManager::Push(Pinetime::Controllers::NotificationManager::Categ std::memcpy(notif.message.data(), message, checkedSize); notif.message[checkedSize] = '\0'; notif.category = category; + notif.id = GetNextId(); + notif.valid = true; writeIndex = (writeIndex + 1 < TotalNbNotifications) ? writeIndex + 1 : 0; - if(!empty && writeIndex == readIndex) - readIndex = writeIndex + 1; + if(!empty) + readIndex = (readIndex + 1 < TotalNbNotifications) ? readIndex + 1 : 0; + else empty = false; + + newNotification = true; } -NotificationManager::Notification Pinetime::Controllers::NotificationManager::Pop() { -// TODO handle edge cases on read/write index +NotificationManager::Notification NotificationManager::GetLastNotification() { NotificationManager::Notification notification = notifications[readIndex]; - - if(readIndex != writeIndex) { - readIndex = (readIndex + 1 < TotalNbNotifications) ? readIndex + 1 : 0; - } - - // TODO Check move optimization on return return notification; } + +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) return {}; + + result.index = (lastNotification.id - result.id)+1; + return result; +} + +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{}; + + auto& lastNotification = notifications[readIndex]; + + NotificationManager::Notification result; + + if(currentIterator == notifications.begin()) + result = *(notifications.end()-1); + else + result = *(currentIterator-1); + + if(result.id >= id) return {}; + + result.index = (lastNotification.id - result.id)+1; + return result; +} + +bool NotificationManager::AreNewNotificationsAvailable() { + return newNotification; +} + +bool NotificationManager::ClearNewNotificationFlag() { + return newNotification.exchange(false); +} + diff --git a/src/components/ble/NotificationManager.h b/src/components/ble/NotificationManager.h index daa1571b..6bf689a8 100644 --- a/src/components/ble/NotificationManager.h +++ b/src/components/ble/NotificationManager.h @@ -1,6 +1,7 @@ #pragma once #include +#include namespace Pinetime { namespace Controllers { @@ -10,20 +11,32 @@ namespace Pinetime { static constexpr uint8_t MessageSize{18}; struct Notification { + using Id = uint8_t; + Id id; + bool valid = false; + uint8_t index; + uint8_t number = TotalNbNotifications; std::array message; Categories category = Categories::Unknown; }; + Notification::Id nextId {0}; void Push(Categories category, const char* message, uint8_t messageSize); - Notification Pop(); + Notification GetLastNotification(); + Notification GetNext(Notification::Id id); + Notification GetPrevious(Notification::Id id); + bool ClearNewNotificationFlag(); + bool AreNewNotificationsAvailable(); private: + Notification::Id GetNextId(); static constexpr uint8_t TotalNbNotifications = 5; std::array notifications; uint8_t readIndex = 0; uint8_t writeIndex = 0; bool empty = true; + std::atomic newNotification{false}; }; } } \ No newline at end of file diff --git a/src/displayapp/Apps.h b/src/displayapp/Apps.h index 8241b188..bfa799ba 100644 --- a/src/displayapp/Apps.h +++ b/src/displayapp/Apps.h @@ -2,6 +2,6 @@ namespace Pinetime { namespace Applications { - enum class Apps {None, Launcher, Clock, SysInfo, Meter, Gauge, Brightness, Music, FirmwareValidation, Paint, Notifications, Notifications2}; + enum class Apps {None, Launcher, Clock, SysInfo, Meter, Gauge, Brightness, Music, FirmwareValidation, Paint, Notifications}; } } \ No newline at end of file diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index ab4a5a7d..d4d41333 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -9,7 +9,6 @@ #include "components/datetime/DateTimeController.h" #include #include "displayapp/screens/Notifications.h" -#include "displayapp/screens/Notifications_swscroll.h" #include "displayapp/screens/Tile.h" #include "displayapp/screens/Meter.h" #include "displayapp/screens/Gauge.h" @@ -37,7 +36,7 @@ DisplayApp::DisplayApp(Drivers::St7789 &lcd, Components::LittleVgl &lvgl, Driver dateTimeController{dateTimeController}, watchdog{watchdog}, touchPanel{touchPanel}, - currentScreen{new Screens::Clock(this, dateTimeController, batteryController, bleController) }, + currentScreen{new Screens::Clock(this, dateTimeController, batteryController, bleController, notificationManager) }, systemTask{systemTask}, notificationManager{notificationManager} { msgQueue = xQueueCreate(queueSize, itemSize); @@ -116,8 +115,12 @@ void DisplayApp::Refresh() { // clockScreen.SetBatteryPercentRemaining(batteryController.PercentRemaining()); break; case Messages::NewNotification: { - auto notification = notificationManager.Pop(); - modal->Show(notification.message.data()); + if(onClockApp) { + currentScreen.reset(nullptr); + lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::Up); + onClockApp = false; + currentScreen.reset(new Screens::Notifications(this, notificationManager, Screens::Notifications::Modes::Preview)); + } } break; case Messages::TouchEvent: { @@ -193,7 +196,7 @@ void DisplayApp::RunningState() { case Apps::None: case Apps::Launcher: currentScreen.reset(new Screens::ApplicationList(this)); break; case Apps::Clock: - currentScreen.reset(new Screens::Clock(this, dateTimeController, batteryController, bleController)); + currentScreen.reset(new Screens::Clock(this, dateTimeController, batteryController, bleController, notificationManager)); onClockApp = true; break; // case Apps::Test: currentScreen.reset(new Screens::Message(this)); break; @@ -204,8 +207,7 @@ void DisplayApp::RunningState() { case Apps::Brightness : currentScreen.reset(new Screens::Brightness(this, brightnessController)); break; case Apps::Music : currentScreen.reset(new Screens::Music(this, systemTask.nimble().music())); break; case Apps::FirmwareValidation: currentScreen.reset(new Screens::FirmwareValidation(this, validator)); break; - case Apps::Notifications: currentScreen.reset(new Screens::Notifications(this)); break; - case Apps::Notifications2: currentScreen.reset(new Screens::Notifications2(this)); break; + case Apps::Notifications: currentScreen.reset(new Screens::Notifications(this, notificationManager, Screens::Notifications::Modes::Normal)); break; } nextApp = Apps::None; } diff --git a/src/displayapp/screens/ApplicationList.cpp b/src/displayapp/screens/ApplicationList.cpp index 8d986062..7eb97188 100644 --- a/src/displayapp/screens/ApplicationList.cpp +++ b/src/displayapp/screens/ApplicationList.cpp @@ -58,9 +58,9 @@ std::unique_ptr ApplicationList::CreateScreen2() { {{Symbols::tachometer, Apps::Gauge}, {Symbols::asterisk, Apps::Meter}, {Symbols::paintbrush, Apps::Paint}, - {Symbols::shoe, Apps::Notifications}, - {Symbols::shoe, Apps::Notifications2}, - {Symbols::none, Apps::None} + {Symbols::info, Apps::Notifications}, + {Symbols::none, Apps::None}, + {Symbols::none, Apps::None} } }; diff --git a/src/displayapp/screens/Clock.cpp b/src/displayapp/screens/Clock.cpp index 243d4c04..eabab21a 100644 --- a/src/displayapp/screens/Clock.cpp +++ b/src/displayapp/screens/Clock.cpp @@ -8,6 +8,9 @@ #include "BatteryIcon.h" #include "BleIcon.h" #include "Symbols.h" +#include "components/ble/NotificationManager.h" +#include "NotificationIcon.h" + using namespace Pinetime::Applications::Screens; extern lv_font_t jetbrains_mono_extrabold_compressed; extern lv_font_t jetbrains_mono_bold_20; @@ -21,8 +24,10 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) { Clock::Clock(DisplayApp* app, Controllers::DateTime& dateTimeController, Controllers::Battery& batteryController, - Controllers::Ble& bleController) : Screen(app), currentDateTime{{}}, - dateTimeController{dateTimeController}, batteryController{batteryController}, bleController{bleController} { + Controllers::Ble& bleController, + Controllers::NotificationManager& notificatioManager) : Screen(app), currentDateTime{{}}, + dateTimeController{dateTimeController}, batteryController{batteryController}, + bleController{bleController}, notificatioManager{notificatioManager} { displayedChar[0] = 0; displayedChar[1] = 0; displayedChar[2] = 0; @@ -41,9 +46,11 @@ Clock::Clock(DisplayApp* app, lv_label_set_text(bleIcon, Symbols::bluetooth); lv_obj_align(bleIcon, batteryPlug, LV_ALIGN_OUT_LEFT_MID, -5, 0); + notificationIcon = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(false)); + lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 10, 0); label_date = lv_label_create(lv_scr_act(), NULL); - lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 60); label_time = lv_label_create(lv_scr_act(), NULL); @@ -106,6 +113,14 @@ bool Clock::Refresh() { lv_obj_align(batteryPlug, batteryIcon, LV_ALIGN_OUT_LEFT_MID, -5, 0); lv_obj_align(bleIcon, batteryPlug, LV_ALIGN_OUT_LEFT_MID, -5, 0); + notificationState = notificatioManager.AreNewNotificationsAvailable(); + if(notificationState.IsUpdated()) { + if(notificationState.Get() == true) + lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(true)); + else + lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(false)); + } + currentDateTime = dateTimeController.CurrentDateTime(); if(currentDateTime.IsUpdated()) { diff --git a/src/displayapp/screens/Clock.h b/src/displayapp/screens/Clock.h index 5753f6a3..58149a79 100644 --- a/src/displayapp/screens/Clock.h +++ b/src/displayapp/screens/Clock.h @@ -7,6 +7,7 @@ #include #include #include +#include "components/ble/NotificationManager.h" #include "components/battery/BatteryController.h" #include "components/ble/BleController.h" @@ -38,7 +39,8 @@ namespace Pinetime { Clock(DisplayApp* app, Controllers::DateTime& dateTimeController, Controllers::Battery& batteryController, - Controllers::Ble& bleController); + Controllers::Ble& bleController, + Controllers::NotificationManager& notificatioManager); ~Clock() override; bool Refresh() override; @@ -63,23 +65,25 @@ namespace Pinetime { DirtyValue> currentDateTime; DirtyValue stepCount {0}; DirtyValue heartbeat {0}; - + DirtyValue notificationState {false}; lv_obj_t* label_time; lv_obj_t* label_date; lv_obj_t* backgroundLabel; - lv_obj_t * batteryIcon; - lv_obj_t * bleIcon; + lv_obj_t* batteryIcon; + lv_obj_t* bleIcon; lv_obj_t* batteryPlug; lv_obj_t* heartbeatIcon; lv_obj_t* heartbeatValue; lv_obj_t* heartbeatBpm; lv_obj_t* stepIcon; lv_obj_t* stepValue; + lv_obj_t* notificationIcon; Controllers::DateTime& dateTimeController; Controllers::Battery& batteryController; Controllers::Ble& bleController; + Controllers::NotificationManager& notificatioManager; bool running = true; diff --git a/src/displayapp/screens/NotificationIcon.cpp b/src/displayapp/screens/NotificationIcon.cpp new file mode 100644 index 00000000..64898c2c --- /dev/null +++ b/src/displayapp/screens/NotificationIcon.cpp @@ -0,0 +1,8 @@ +#include "NotificationIcon.h" +#include "Symbols.h" +using namespace Pinetime::Applications::Screens; + +const char* NotificationIcon::GetIcon(bool newNotificationAvailable) { + if(newNotificationAvailable) return Symbols::info; + else return ""; +} \ No newline at end of file diff --git a/src/displayapp/screens/NotificationIcon.h b/src/displayapp/screens/NotificationIcon.h new file mode 100644 index 00000000..dc34c3f0 --- /dev/null +++ b/src/displayapp/screens/NotificationIcon.h @@ -0,0 +1,12 @@ +#pragma once + +namespace Pinetime { + namespace Applications { + namespace Screens { + class NotificationIcon { + public: + static const char* GetIcon(bool newNotificationAvailable); + }; + } + } +} \ No newline at end of file diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp index 3cd26353..09365f2e 100644 --- a/src/displayapp/screens/Notifications.cpp +++ b/src/displayapp/screens/Notifications.cpp @@ -2,15 +2,35 @@ #include #include #include "Notifications.h" + using namespace Pinetime::Applications::Screens; -Notifications::Notifications(DisplayApp* app) : Screen(app), screens{app, { - [this]() -> std::unique_ptr { return CreateScreen1(); }, - [this]() -> std::unique_ptr { return CreateScreen2(); }, - [this]() -> std::unique_ptr { return CreateScreen3(); } -} -} { +Notifications::Notifications(DisplayApp *app, Pinetime::Controllers::NotificationManager ¬ificationManager, Modes mode) : + Screen(app), notificationManager{notificationManager}, mode{mode} { + notificationManager.ClearNewNotificationFlag(); + auto notification = notificationManager.GetLastNotification(); + if(notification.valid) { + currentId = notification.id; + currentItem.reset(new NotificationItem("Notification", notification.message.data(), notification.index, notification.number, mode)); + validDisplay = true; + } else { + currentItem.reset(new NotificationItem("Notification", "No notification to display", 0, 0, mode)); + } + if(mode == Modes::Preview) { + static lv_style_t style_line; + lv_style_copy(&style_line, &lv_style_plain); + style_line.line.color = LV_COLOR_WHITE; + style_line.line.width = 3; + style_line.line.rounded = 0; + + + timeoutLine = lv_line_create(lv_scr_act(), nullptr); + lv_line_set_style(timeoutLine, LV_LINE_STYLE_MAIN, &style_line); + lv_line_set_points(timeoutLine, timeoutLinePoints, 2); + timeoutTickCountStart = xTaskGetTickCount(); + timeoutTickCountEnd = timeoutTickCountStart + (5*1024); + } } Notifications::~Notifications() { @@ -18,12 +38,61 @@ Notifications::~Notifications() { } bool Notifications::Refresh() { - screens.Refresh(); + if (mode == Modes::Preview) { + auto tick = xTaskGetTickCount(); + int32_t pos = 240 - ((tick - timeoutTickCountStart) / ((timeoutTickCountEnd - timeoutTickCountStart) / 240)); + if (pos < 0) + running = false; + + timeoutLinePoints[1].x = pos; + lv_line_set_points(timeoutLine, timeoutLinePoints, 2); + + if (!running) { + // Start clock app when exiting this one + app->StartApp(Apps::Clock); + } + } + return running; } bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) { - return screens.OnTouchEvent(event); + switch (event) { + case Pinetime::Applications::TouchEvents::SwipeUp: { + Controllers::NotificationManager::Notification previousNotification; + if(validDisplay) + previousNotification = notificationManager.GetPrevious(currentId); + else + previousNotification = notificationManager.GetLastNotification(); + + if (!previousNotification.valid) return true; + + validDisplay = true; + currentId = previousNotification.id; + currentItem.reset(nullptr); + app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up); + currentItem.reset(new NotificationItem("Notification", previousNotification.message.data(), previousNotification.index, previousNotification.number, mode)); + } + return true; + case Pinetime::Applications::TouchEvents::SwipeDown: { + Controllers::NotificationManager::Notification nextNotification; + if(validDisplay) + nextNotification = notificationManager.GetNext(currentId); + else + nextNotification = notificationManager.GetLastNotification(); + + if (!nextNotification.valid) return true; + + validDisplay = true; + currentId = nextNotification.id; + currentItem.reset(nullptr); + app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down); + currentItem.reset(new NotificationItem("Notification", nextNotification.message.data(), nextNotification.index, nextNotification.number, mode)); + } + return true; + default: + return false; + } } @@ -32,22 +101,11 @@ bool Notifications::OnButtonPushed() { return true; } -std::unique_ptr Notifications::CreateScreen1() { - return std::unique_ptr(new Notifications::NotificationItem(app, "Message", "Marcel Pickett: Did you bring your ticket?", "Shot notif", "Short text", 1, 3)); -} -std::unique_ptr Notifications::CreateScreen2() { - return std::unique_ptr(new Notifications::NotificationItem(app, "Alarm", "Missed: 09:30", 2, 3)); -} +Notifications::NotificationItem::NotificationItem(const char *title, const char *msg, uint8_t notifNr, uint8_t notifNb, Modes mode) + : notifNr{notifNr}, notifNb{notifNb}, mode{mode} { -std::unique_ptr Notifications::CreateScreen3() { - return std::unique_ptr(new Notifications::NotificationItem(app, "Spotify", "Now playing: Bame game - Kanye West", 3, 3)); -} - -Notifications::NotificationItem::NotificationItem(Pinetime::Applications::DisplayApp *app, const char *title, const char* msg, uint8_t notifNr, uint8_t notifNb) : - Screen(app), notifNr{notifNr}, notifNb{notifNb} { - - lv_obj_t* container1 = lv_cont_create(lv_scr_act(), NULL); + container1 = lv_cont_create(lv_scr_act(), nullptr); static lv_style_t contStyle; lv_style_copy(&contStyle, lv_cont_get_style(container1, LV_CONT_STYLE_MAIN)); contStyle.body.padding.inner = 20; @@ -58,10 +116,7 @@ Notifications::NotificationItem::NotificationItem(Pinetime::Applications::Displa lv_cont_set_layout(container1, LV_LAYOUT_OFF); lv_cont_set_fit2(container1, LV_FIT_FLOOD, LV_FIT_FLOOD); - - - lv_obj_t* t1 = lv_label_create(container1, NULL); - + t1 = lv_label_create(container1, nullptr); static lv_style_t titleStyle; static lv_style_t textStyle; static lv_style_t bottomStyle; @@ -69,144 +124,46 @@ Notifications::NotificationItem::NotificationItem(Pinetime::Applications::Displa lv_style_copy(&textStyle, lv_label_get_style(t1, LV_LABEL_STYLE_MAIN)); lv_style_copy(&bottomStyle, lv_label_get_style(t1, LV_LABEL_STYLE_MAIN)); titleStyle.body.padding.inner = 5; - textStyle.body.padding.inner = 5; titleStyle.body.grad_color = LV_COLOR_GRAY; titleStyle.body.main_color = LV_COLOR_GRAY; + titleStyle.body.radius = 20; textStyle.body.border.part = LV_BORDER_NONE; + textStyle.body.padding.inner = 5; - //bottomStyle.body.padding.inner = 5; bottomStyle.body.main_color = LV_COLOR_GREEN; bottomStyle.body.grad_color = LV_COLOR_GREEN; bottomStyle.body.border.part = LV_BORDER_TOP; bottomStyle.body.border.color = LV_COLOR_RED; - lv_label_set_style(t1, LV_LABEL_STYLE_MAIN, &titleStyle); lv_label_set_long_mode(t1, LV_LABEL_LONG_BREAK); lv_label_set_body_draw(t1, true); - lv_obj_set_width(t1, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right) ); + lv_obj_set_width(t1, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right)); lv_label_set_text(t1, title); lv_obj_set_pos(t1, titleStyle.body.padding.left, titleStyle.body.padding.top); auto titleHeight = lv_obj_get_height(t1); - lv_obj_t* l1 = lv_label_create(container1, NULL); + l1 = lv_label_create(container1, nullptr); lv_label_set_style(l1, LV_LABEL_STYLE_MAIN, &textStyle); - lv_obj_set_pos(l1, textStyle.body.padding.left, titleHeight + titleStyle.body.padding.bottom + textStyle.body.padding.bottom + textStyle.body.padding.top); + lv_obj_set_pos(l1, textStyle.body.padding.left, + titleHeight + titleStyle.body.padding.bottom + textStyle.body.padding.bottom + + textStyle.body.padding.top); lv_label_set_long_mode(l1, LV_LABEL_LONG_BREAK); lv_label_set_body_draw(l1, true); - lv_obj_set_width(l1, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right) ); + lv_obj_set_width(l1, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right)); lv_label_set_text(l1, msg); - lv_obj_t* bottomlabel = lv_label_create(container1, NULL); - lv_label_set_style(bottomlabel, LV_LABEL_STYLE_MAIN, &bottomStyle); - lv_obj_set_width(bottomlabel, LV_HOR_RES - (bottomStyle.body.padding.left + bottomStyle.body.padding.right) ); - snprintf(pageText, 4, "%d/%d", notifNr, notifNb); - lv_label_set_text(bottomlabel, pageText); - auto bottomHeight = lv_obj_get_height(bottomlabel); - lv_obj_set_pos(bottomlabel, 0, LV_VER_RES - (bottomHeight*2)); + if(mode == Modes::Normal) { + lv_obj_t *bottomlabel = lv_label_create(container1, nullptr); + lv_label_set_style(bottomlabel, LV_LABEL_STYLE_MAIN, &bottomStyle); + lv_obj_align(bottomlabel, container1, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); + snprintf(pageText, 4, "%d/%d", notifNr, notifNb); + lv_label_set_text(bottomlabel, pageText); + } } -Notifications::NotificationItem::NotificationItem(Pinetime::Applications::DisplayApp *app, const char *title1, const char* msg1, const char *title2, const char* msg2, uint8_t notifNr, uint8_t notifNb) : - Screen(app), notifNr{notifNr}, notifNb{notifNb} { - - lv_obj_t* container1 = lv_cont_create(lv_scr_act(), NULL); - static lv_style_t contStyle; - lv_style_copy(&contStyle, lv_cont_get_style(container1, LV_CONT_STYLE_MAIN)); - contStyle.body.padding.inner = 20; - lv_cont_set_style(container1, LV_CONT_STYLE_MAIN, &contStyle); - lv_obj_set_width(container1, LV_HOR_RES); - lv_obj_set_height(container1, LV_VER_RES); - lv_obj_set_pos(container1, 0, 0); - lv_cont_set_layout(container1, LV_LAYOUT_OFF); - lv_cont_set_fit2(container1, LV_FIT_FLOOD, LV_FIT_FLOOD); - - - - lv_obj_t* t1 = lv_label_create(container1, NULL); - - static lv_style_t titleStyle; - static lv_style_t textStyle; - static lv_style_t bottomStyle; - lv_style_copy(&titleStyle, lv_label_get_style(t1, LV_LABEL_STYLE_MAIN)); - lv_style_copy(&textStyle, lv_label_get_style(t1, LV_LABEL_STYLE_MAIN)); - lv_style_copy(&bottomStyle, lv_label_get_style(t1, LV_LABEL_STYLE_MAIN)); - titleStyle.body.padding.inner = 5; - textStyle.body.padding.inner = 5; - titleStyle.body.grad_color = LV_COLOR_GRAY; - titleStyle.body.main_color = LV_COLOR_GRAY; - textStyle.body.border.part = LV_BORDER_NONE; - - //bottomStyle.body.padding.inner = 5; - bottomStyle.body.main_color = LV_COLOR_GREEN; - bottomStyle.body.grad_color = LV_COLOR_GREEN; - bottomStyle.body.border.part = LV_BORDER_TOP; - bottomStyle.body.border.color = LV_COLOR_RED; - - - lv_label_set_style(t1, LV_LABEL_STYLE_MAIN, &titleStyle); - lv_label_set_long_mode(t1, LV_LABEL_LONG_BREAK); - lv_label_set_body_draw(t1, true); - lv_obj_set_width(t1, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right) ); - lv_label_set_text(t1, title1); - lv_obj_set_pos(t1, titleStyle.body.padding.left, titleStyle.body.padding.top); - - auto titleHeight = lv_obj_get_height(t1); - - lv_obj_t* l1 = lv_label_create(container1, NULL); - lv_label_set_style(l1, LV_LABEL_STYLE_MAIN, &textStyle); - lv_obj_set_pos(l1, textStyle.body.padding.left, titleHeight + titleStyle.body.padding.bottom + textStyle.body.padding.bottom + textStyle.body.padding.top); - - lv_label_set_long_mode(l1, LV_LABEL_LONG_BREAK); - lv_label_set_body_draw(l1, true); - lv_obj_set_width(l1, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right) ); - lv_label_set_text(l1, msg1); - - auto bottomPos = lv_obj_get_y(l1) + lv_obj_get_height(l1) + textStyle.body.padding.bottom; - - /* - lv_obj_t* bottomlabel = lv_label_create(container1, NULL); - lv_label_set_style(bottomlabel, LV_LABEL_STYLE_MAIN, &bottomStyle); - lv_obj_set_width(bottomlabel, LV_HOR_RES - (bottomStyle.body.padding.left + bottomStyle.body.padding.right) ); - snprintf(pageText, 4, "%d/%d", notifNr, notifNb); - lv_label_set_text(bottomlabel, pageText); - auto bottomHeight = lv_obj_get_height(bottomlabel); - lv_obj_set_pos(bottomlabel, 0, LV_VER_RES - (bottomHeight*2)); - */ - - //------------------------------------------------- -/* - lv_obj_t* container2 = lv_cont_create(lv_scr_act(), NULL); - lv_cont_set_style(container2, LV_CONT_STYLE_MAIN, &contStyle); - lv_obj_set_width(container2, LV_HOR_RES); - lv_obj_set_height(container2, LV_VER_RES - bottomPos); - lv_obj_set_pos(container2, 0, bottomPos); - lv_cont_set_layout(container2, LV_LAYOUT_OFF); - lv_cont_set_fit2(container2, LV_FIT_FLOOD, LV_FIT_FLOOD); -*/ - lv_obj_t* t2 = lv_label_create(container1, NULL); - - - lv_label_set_style(t2, LV_LABEL_STYLE_MAIN, &titleStyle); - lv_label_set_long_mode(t2, LV_LABEL_LONG_BREAK); - lv_label_set_body_draw(t2, true); - lv_obj_set_width(t2, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right) ); - lv_label_set_text(t2, title2); - lv_obj_set_pos(t2, titleStyle.body.padding.left, bottomPos + titleStyle.body.padding.top); - - auto title2Height = lv_obj_get_height(t2); - - lv_obj_t* l2 = lv_label_create(container1, NULL); - lv_label_set_style(l2, LV_LABEL_STYLE_MAIN, &textStyle); - lv_obj_set_pos(l2, textStyle.body.padding.left, bottomPos + title2Height + titleStyle.body.padding.bottom + textStyle.body.padding.bottom + textStyle.body.padding.top); - - lv_label_set_long_mode(l2, LV_LABEL_LONG_BREAK); - lv_label_set_body_draw(l2, true); - lv_obj_set_width(l2, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right) ); - lv_label_set_text(l2, msg2); - -} Notifications::NotificationItem::~NotificationItem() { lv_obj_clean(lv_scr_act()); diff --git a/src/displayapp/screens/Notifications.h b/src/displayapp/screens/Notifications.h index e6f20877..0f797ea6 100644 --- a/src/displayapp/screens/Notifications.h +++ b/src/displayapp/screens/Notifications.h @@ -12,7 +12,8 @@ namespace Pinetime { namespace Screens { class Notifications : public Screen { public: - explicit Notifications(DisplayApp* app); + enum class Modes {Normal, Preview}; + explicit Notifications(DisplayApp* app, Pinetime::Controllers::NotificationManager& notificationManager, Modes mode); ~Notifications() override; bool Refresh() override; @@ -20,24 +21,39 @@ namespace Pinetime { bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; private: - ScreenList<3> screens; bool running = true; - std::unique_ptr CreateScreen1(); - std::unique_ptr CreateScreen2(); - std::unique_ptr CreateScreen3(); - class NotificationItem : public Screen { + class NotificationItem { public: - NotificationItem(DisplayApp* app, const char* title, const char* msg, uint8_t notifNr, uint8_t notifNb); - NotificationItem(DisplayApp* app, const char* title1, const char* msg1, const char* title2, const char* msg2, uint8_t notifNr, uint8_t notifNb); - ~NotificationItem() override; - bool Refresh() override {return false;} + NotificationItem(const char* title, const char* msg, uint8_t notifNr, uint8_t notifNb, Modes mode); + ~NotificationItem(); + bool Refresh() {return false;} private: uint8_t notifNr = 0; uint8_t notifNb = 0; char pageText[4]; + + lv_obj_t* container1; + lv_obj_t* t1; + lv_obj_t* l1; + Modes mode; }; + + struct NotificationData { + const char* title; + const char* text; + }; + Pinetime::Controllers::NotificationManager& notificationManager; + Modes mode = Modes::Normal; + std::unique_ptr currentItem; + Controllers::NotificationManager::Notification::Id currentId; + bool validDisplay = false; + + lv_point_t timeoutLinePoints[2] { {0, 237}, {239, 237} }; + lv_obj_t* timeoutLine; + uint32_t timeoutTickCountStart; + uint32_t timeoutTickCountEnd; }; } } diff --git a/src/displayapp/screens/Notifications_swscroll.cpp b/src/displayapp/screens/Notifications_swscroll.cpp deleted file mode 100644 index a5eb74e9..00000000 --- a/src/displayapp/screens/Notifications_swscroll.cpp +++ /dev/null @@ -1,145 +0,0 @@ -#include "Notifications_swscroll.h" -#include "displayapp/DisplayApp.h" -#include - -using namespace Pinetime::Applications::Screens; - -Notifications2::Notifications2(DisplayApp* app) : Screen(app) { - - app->SetTouchMode(DisplayApp::TouchModes::Polling); -} - -Notifications2::~Notifications2() { - lv_obj_clean(lv_scr_act()); -} - -bool Notifications2::Refresh() { - return running; -} - -void Notifications2::OnObjectEvent(lv_obj_t *obj, lv_event_t event, uint32_t buttonId) { - -} - -bool Notifications2::OnTouchEvent(Pinetime::Applications::TouchEvents event) { return true; } - - -bool Notifications2::OnButtonPushed() { - app->StartApp(Apps::Clock); - running = false; - return true; -} - - -Notifications2::ListWidget::ListWidget() { - static lv_point_t valid_pos[] = {{0,0}, {0,1}}; - page = lv_tileview_create(lv_scr_act(), NULL); - lv_obj_set_size(page, LV_HOR_RES, LV_VER_RES); - lv_obj_align(page, NULL, LV_ALIGN_CENTER, 0, 0); - lv_tileview_set_valid_positions(page, valid_pos, 2); - - static lv_style_t pageStyle; - lv_style_copy(&pageStyle, lv_tileview_get_style(page, LV_TILEVIEW_STYLE_MAIN)); - - lv_tileview_set_style(page, LV_TILEVIEW_STYLE_MAIN, &pageStyle); - - - lv_obj_t* container1 = lv_cont_create(page, NULL); - static lv_style_t contStyle; - lv_style_copy(&contStyle, lv_cont_get_style(container1, LV_CONT_STYLE_MAIN)); - contStyle.body.padding.inner = 20; - lv_cont_set_style(container1, LV_CONT_STYLE_MAIN, &contStyle); - lv_obj_set_width(container1, LV_HOR_RES); - lv_obj_set_pos(container1, 0, 0); - lv_cont_set_layout(container1, LV_LAYOUT_COL_M); - lv_cont_set_fit2(container1, LV_FIT_FLOOD, LV_FIT_TIGHT); - - lv_tileview_add_element(page, container1); - - - lv_obj_t* t1 = lv_label_create(container1, NULL); - - static lv_style_t titleStyle; - static lv_style_t textStyle; - lv_style_copy(&titleStyle, lv_label_get_style(t1, LV_LABEL_STYLE_MAIN)); - lv_style_copy(&textStyle, lv_label_get_style(t1, LV_LABEL_STYLE_MAIN)); - - //titleStyle.body.main_color = LV_COLOR_RED; - //titleStyle.body.grad_color = LV_COLOR_RED; - titleStyle.body.padding.inner = 5; - - //textStyle.body.main_color = LV_COLOR_BLUE; - //textStyle.body.grad_color = LV_COLOR_BLUE; - textStyle.body.padding.inner = 5; - - lv_label_set_style(t1, LV_LABEL_STYLE_MAIN, &titleStyle); - lv_label_set_long_mode(t1, LV_LABEL_LONG_BREAK); - lv_label_set_body_draw(t1, true); - lv_obj_set_width(t1, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right) ); - lv_label_set_text(t1, "Message"); - - - lv_obj_t* l1 = lv_label_create(container1, NULL); - lv_label_set_style(l1, LV_PAGE_STYLE_BG, &textStyle); - lv_label_set_long_mode(l1, LV_LABEL_LONG_BREAK); - lv_label_set_body_draw(l1, true); - lv_obj_set_width(l1, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right) ); - lv_label_set_text(l1, "Marcel Pickett: Did you bring your ticket?"); - - /*---*/ - lv_obj_t* container2 = lv_cont_create(page, NULL); - lv_cont_set_style(container2, LV_CONT_STYLE_MAIN, &contStyle); - lv_obj_set_width(container2, LV_HOR_RES); - lv_obj_set_pos(container2, 0, lv_obj_get_y(container1) + lv_obj_get_height(container1)+5); - lv_cont_set_layout(container2, LV_LAYOUT_COL_M); - lv_cont_set_fit2(container2, LV_FIT_FLOOD, LV_FIT_TIGHT); - lv_tileview_add_element(page, container2); - - lv_obj_t* t2 = lv_label_create(container2, NULL); - lv_label_set_style(t2, LV_PAGE_STYLE_BG, &titleStyle); - lv_label_set_long_mode(t2, LV_LABEL_LONG_BREAK); - lv_label_set_body_draw(t2, true); - lv_obj_set_width(t2, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right) ); - lv_label_set_text(t2, "Alarm"); - - - lv_obj_t* l2 = lv_label_create(container2, NULL); - lv_label_set_style(l2, LV_PAGE_STYLE_BG, &textStyle); - lv_label_set_long_mode(l2, LV_LABEL_LONG_BREAK); - lv_label_set_body_draw(l2, true); - lv_obj_set_width(l2, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right) ); - lv_label_set_text(l2, "Missed: 09:30"); - - /*****/ - lv_obj_t* container3 = lv_cont_create(page, NULL); - lv_cont_set_style(container3, LV_CONT_STYLE_MAIN, &contStyle); - lv_obj_set_width(container3, LV_HOR_RES); - lv_obj_set_pos(container3, 0, lv_obj_get_y(container2) + lv_obj_get_height(container2)+5); - lv_cont_set_layout(container3, LV_LAYOUT_COL_M); - lv_cont_set_fit2(container3, LV_FIT_FLOOD, LV_FIT_TIGHT); - lv_tileview_add_element(page, container3); - - lv_obj_t* t3 = lv_label_create(container3, NULL); - lv_label_set_style(t3, LV_PAGE_STYLE_BG, &titleStyle); - lv_label_set_long_mode(t3, LV_LABEL_LONG_BREAK); - lv_label_set_body_draw(t3, true); - lv_obj_set_width(t3, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right) ); - lv_label_set_text(t3, "Spotify"); - - - lv_obj_t* l3 = lv_label_create(container3, NULL); - lv_label_set_style(l3, LV_PAGE_STYLE_BG, &textStyle); - lv_label_set_long_mode(l3, LV_LABEL_LONG_BREAK); - lv_label_set_body_draw(l3, true); - lv_obj_set_width(l3, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right) ); - lv_label_set_text(l3, "Now playing: Bame game - Kanye West"); - - - - - - - - - -} diff --git a/src/displayapp/screens/Notifications_swscroll.h b/src/displayapp/screens/Notifications_swscroll.h deleted file mode 100644 index 48960797..00000000 --- a/src/displayapp/screens/Notifications_swscroll.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include -#include "Screen.h" -#include -#include "Modal.h" -#include -#include - -namespace Pinetime { - namespace Applications { - namespace Screens { - class Notifications2 : public Screen { - public: - explicit Notifications2(DisplayApp* app); - ~Notifications2() override; - - bool Refresh() override; - bool OnButtonPushed() override; - void OnObjectEvent(lv_obj_t* obj, lv_event_t event, uint32_t buttonId); - bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; - - private: - class ListWidget { - public: - ListWidget(); - private: - lv_obj_t* page = nullptr; - }; - - bool running = true; - ListWidget list; - }; - } - } -} From 440ae412b9ce9c868aa8b98e6da537bd0ec62de7 Mon Sep 17 00:00:00 2001 From: JF Date: Wed, 21 Oct 2020 17:31:56 +0200 Subject: [PATCH 4/7] Increase max size of notification message to 100 char. Fix bug in message handling that would ignore the last character of the notification. --- CMakeLists.txt | 2 +- .../ble/AlertNotificationClient.cpp | 25 ++++++--------- .../ble/AlertNotificationService.cpp | 32 +++++++------------ src/components/ble/AlertNotificationService.h | 4 +-- src/components/ble/NotificationManager.cpp | 5 ++- src/components/ble/NotificationManager.h | 3 +- 6 files changed, 30 insertions(+), 41 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5346ccfb..1e340f74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.10) -project(pinetime VERSION 0.8.2 LANGUAGES C CXX ASM) +project(pinetime VERSION 0.9.0 LANGUAGES C CXX ASM) set(NRF_TARGET "nrf52") diff --git a/src/components/ble/AlertNotificationClient.cpp b/src/components/ble/AlertNotificationClient.cpp index ddc72967..8fbbafb6 100644 --- a/src/components/ble/AlertNotificationClient.cpp +++ b/src/components/ble/AlertNotificationClient.cpp @@ -105,25 +105,18 @@ 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); + static constexpr size_t stringTerminatorSize{1}; // end of string '\0' + static 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); + size_t bufferSize = min(OS_MBUF_PKTLEN(event->notify_rx.om) + stringTerminatorSize, maxBufferSize); + char *message = (char *)(&event->notify_rx.om[headerSize]); + auto messageSize = min(maxMessageSize, (bufferSize-headerSize)); - char *s = (char *) &data[3]; - auto messageSize = min(maxMessageSize, (bufferSize-3)); + message[messageSize-1] = '\0'; - 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); + notificationManager.Push(Pinetime::Controllers::NotificationManager::Categories::SimpleAlert, message, messageSize); systemTask.PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification); } } diff --git a/src/components/ble/AlertNotificationService.cpp b/src/components/ble/AlertNotificationService.cpp index 9a9b535d..7e432b82 100644 --- a/src/components/ble/AlertNotificationService.cpp +++ b/src/components/ble/AlertNotificationService.cpp @@ -38,7 +38,7 @@ AlertNotificationService::AlertNotificationService ( System::SystemTask& systemT 0 } }, - serviceDefinition{ + serviceDefinition{ { /* Device Information Service */ .type = BLE_GATT_SVC_TYPE_PRIMARY, @@ -48,33 +48,25 @@ AlertNotificationService::AlertNotificationService ( System::SystemTask& systemT { 0 }, - }, m_systemTask{systemTask}, m_notificationManager{notificationManager} { + }, systemTask{systemTask}, notificationManager{notificationManager} { } int AlertNotificationService::OnAlert(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt) { - if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) { - // 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(ctxt->om), maxBufferSize); + static constexpr size_t stringTerminatorSize{1}; // end of string '\0' + static constexpr size_t headerSize{3}; + const auto maxMessageSize {NotificationManager::MaximumMessageSize()}; + const auto maxBufferSize{maxMessageSize + headerSize}; - uint8_t data[bufferSize]; - os_mbuf_copydata(ctxt->om, 0, bufferSize, data); + size_t bufferSize = min(OS_MBUF_PKTLEN(ctxt->om) + stringTerminatorSize, maxBufferSize); + char *message = (char *)(&ctxt->om->om_data[headerSize]); + auto messageSize = min(maxMessageSize, (bufferSize-headerSize)); - char *s = (char *) &data[3]; - auto messageSize = min(maxMessageSize, (bufferSize-3)); + message[messageSize-1] = '\0'; - for (uint i = 0; i < messageSize-1; i++) { - if (s[i] == 0x00) { - s[i] = 0x0A; - } - } - s[messageSize-1] = '\0'; - - m_notificationManager.Push(Pinetime::Controllers::NotificationManager::Categories::SimpleAlert, s, messageSize); - m_systemTask.PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification); + notificationManager.Push(Pinetime::Controllers::NotificationManager::Categories::SimpleAlert, message, messageSize); + systemTask.PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification); } return 0; } diff --git a/src/components/ble/AlertNotificationService.h b/src/components/ble/AlertNotificationService.h index 53cb44cc..1b8c4989 100644 --- a/src/components/ble/AlertNotificationService.h +++ b/src/components/ble/AlertNotificationService.h @@ -32,8 +32,8 @@ namespace Pinetime { struct ble_gatt_chr_def characteristicDefinition[2]; struct ble_gatt_svc_def serviceDefinition[2]; - Pinetime::System::SystemTask &m_systemTask; - NotificationManager &m_notificationManager; + Pinetime::System::SystemTask &systemTask; + NotificationManager ¬ificationManager; }; } } diff --git a/src/components/ble/NotificationManager.cpp b/src/components/ble/NotificationManager.cpp index 4297cde9..6ed3f835 100644 --- a/src/components/ble/NotificationManager.cpp +++ b/src/components/ble/NotificationManager.cpp @@ -4,10 +4,13 @@ using namespace Pinetime::Controllers; +constexpr uint8_t NotificationManager::MessageSize; + + void NotificationManager::Push(Pinetime::Controllers::NotificationManager::Categories category, const char *message, uint8_t currentMessageSize) { // TODO handle edge cases on read/write index - auto checkedSize = std::min(currentMessageSize, uint8_t{18}); + auto checkedSize = std::min(currentMessageSize, MessageSize); auto& notif = notifications[writeIndex]; std::memcpy(notif.message.data(), message, checkedSize); notif.message[checkedSize] = '\0'; diff --git a/src/components/ble/NotificationManager.h b/src/components/ble/NotificationManager.h index 6bf689a8..e4e2b4d4 100644 --- a/src/components/ble/NotificationManager.h +++ b/src/components/ble/NotificationManager.h @@ -8,7 +8,7 @@ namespace Pinetime { class NotificationManager { public: enum class Categories {Unknown, SimpleAlert, Email, News, IncomingCall, MissedCall, Sms, VoiceMail, Schedule, HighProriotyAlert, InstantMessage }; - static constexpr uint8_t MessageSize{18}; + static constexpr uint8_t MessageSize{100}; struct Notification { using Id = uint8_t; @@ -28,6 +28,7 @@ namespace Pinetime { bool ClearNewNotificationFlag(); bool AreNewNotificationsAvailable(); + static constexpr uint8_t MaximumMessageSize() { return MessageSize; }; private: Notification::Id GetNextId(); From cabf1168d429db84b0985e25881ead86d80dde3c Mon Sep 17 00:00:00 2001 From: JF Date: Wed, 21 Oct 2020 22:15:02 +0200 Subject: [PATCH 5/7] Notifications : Fix display of notification index/number. --- src/components/ble/NotificationManager.cpp | 5 +++++ src/components/ble/NotificationManager.h | 2 +- src/displayapp/screens/Notifications.cpp | 8 ++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/components/ble/NotificationManager.cpp b/src/components/ble/NotificationManager.cpp index 6ed3f835..11555bee 100644 --- a/src/components/ble/NotificationManager.cpp +++ b/src/components/ble/NotificationManager.cpp @@ -28,6 +28,7 @@ void NotificationManager::Push(Pinetime::Controllers::NotificationManager::Categ NotificationManager::Notification NotificationManager::GetLastNotification() { NotificationManager::Notification notification = notifications[readIndex]; + notification.index = 1; return notification; } @@ -81,3 +82,7 @@ bool NotificationManager::ClearNewNotificationFlag() { return newNotification.exchange(false); } +size_t NotificationManager::NbNotifications() const { + return std::count_if(notifications.begin(), notifications.end(), [](const Notification& n){ return n.valid;}); +} + diff --git a/src/components/ble/NotificationManager.h b/src/components/ble/NotificationManager.h index e4e2b4d4..64c6df6d 100644 --- a/src/components/ble/NotificationManager.h +++ b/src/components/ble/NotificationManager.h @@ -15,7 +15,6 @@ namespace Pinetime { Id id; bool valid = false; uint8_t index; - uint8_t number = TotalNbNotifications; std::array message; Categories category = Categories::Unknown; }; @@ -29,6 +28,7 @@ namespace Pinetime { bool AreNewNotificationsAvailable(); static constexpr uint8_t MaximumMessageSize() { return MessageSize; }; + size_t NbNotifications() const; private: Notification::Id GetNextId(); diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp index 09365f2e..38a28e12 100644 --- a/src/displayapp/screens/Notifications.cpp +++ b/src/displayapp/screens/Notifications.cpp @@ -11,10 +11,10 @@ Notifications::Notifications(DisplayApp *app, Pinetime::Controllers::Notificatio auto notification = notificationManager.GetLastNotification(); if(notification.valid) { currentId = notification.id; - currentItem.reset(new NotificationItem("Notification", notification.message.data(), notification.index, notification.number, mode)); + currentItem.reset(new NotificationItem("Notification", notification.message.data(), notification.index, notificationManager.NbNotifications(), mode)); validDisplay = true; } else { - currentItem.reset(new NotificationItem("Notification", "No notification to display", 0, 0, mode)); + currentItem.reset(new NotificationItem("Notification", "No notification to display", 0, notificationManager.NbNotifications(), Modes::Preview)); } if(mode == Modes::Preview) { @@ -71,7 +71,7 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) { currentId = previousNotification.id; currentItem.reset(nullptr); app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up); - currentItem.reset(new NotificationItem("Notification", previousNotification.message.data(), previousNotification.index, previousNotification.number, mode)); + currentItem.reset(new NotificationItem("Notification", previousNotification.message.data(), previousNotification.index, notificationManager.NbNotifications(), mode)); } return true; case Pinetime::Applications::TouchEvents::SwipeDown: { @@ -87,7 +87,7 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) { currentId = nextNotification.id; currentItem.reset(nullptr); app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down); - currentItem.reset(new NotificationItem("Notification", nextNotification.message.data(), nextNotification.index, nextNotification.number, mode)); + currentItem.reset(new NotificationItem("Notification", nextNotification.message.data(), nextNotification.index, notificationManager.NbNotifications(), mode)); } return true; default: From 07b6812f61cf5b7726fbf6015c2c60caa12c7f20 Mon Sep 17 00:00:00 2001 From: JF Date: Thu, 22 Oct 2020 10:43:42 +0200 Subject: [PATCH 6/7] Notifications : Fix copy when the messages is spread across multiple os_mbuf. --- src/components/ble/AlertNotificationClient.cpp | 15 +++++++++------ src/components/ble/AlertNotificationService.cpp | 15 +++++++++------ src/components/ble/ImmediateAlertService.cpp | 8 +++++++- src/components/ble/NotificationManager.cpp | 11 ++--------- src/components/ble/NotificationManager.h | 2 +- 5 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/components/ble/AlertNotificationClient.cpp b/src/components/ble/AlertNotificationClient.cpp index 8fbbafb6..40970e0b 100644 --- a/src/components/ble/AlertNotificationClient.cpp +++ b/src/components/ble/AlertNotificationClient.cpp @@ -105,18 +105,21 @@ int AlertNotificationClient::OnDescriptorDiscoveryEventCallback(uint16_t connect void AlertNotificationClient::OnNotification(ble_gap_event *event) { if(event->notify_rx.attr_handle == newAlertHandle) { - static constexpr size_t stringTerminatorSize{1}; // end of string '\0' - static constexpr size_t headerSize{3}; + constexpr size_t stringTerminatorSize = 1; // end of string '\0' + constexpr size_t headerSize = 3; const auto maxMessageSize {NotificationManager::MaximumMessageSize()}; const auto maxBufferSize{maxMessageSize + headerSize}; - size_t bufferSize = min(OS_MBUF_PKTLEN(event->notify_rx.om) + stringTerminatorSize, maxBufferSize); - char *message = (char *)(&event->notify_rx.om[headerSize]); + const auto dbgPacketLen = OS_MBUF_PKTLEN(event->notify_rx.om); + size_t bufferSize = min(dbgPacketLen + stringTerminatorSize, maxBufferSize); auto messageSize = min(maxMessageSize, (bufferSize-headerSize)); - message[messageSize-1] = '\0'; + 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)); - notificationManager.Push(Pinetime::Controllers::NotificationManager::Categories::SimpleAlert, message, messageSize); systemTask.PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification); } } diff --git a/src/components/ble/AlertNotificationService.cpp b/src/components/ble/AlertNotificationService.cpp index 7e432b82..32711b92 100644 --- a/src/components/ble/AlertNotificationService.cpp +++ b/src/components/ble/AlertNotificationService.cpp @@ -54,18 +54,21 @@ AlertNotificationService::AlertNotificationService ( System::SystemTask& systemT int AlertNotificationService::OnAlert(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt) { if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) { - static constexpr size_t stringTerminatorSize{1}; // end of string '\0' - static constexpr size_t headerSize{3}; + constexpr size_t stringTerminatorSize = 1; // end of string '\0' + constexpr size_t headerSize = 3; const auto maxMessageSize {NotificationManager::MaximumMessageSize()}; const auto maxBufferSize{maxMessageSize + headerSize}; - size_t bufferSize = min(OS_MBUF_PKTLEN(ctxt->om) + stringTerminatorSize, maxBufferSize); - char *message = (char *)(&ctxt->om->om_data[headerSize]); + const auto dbgPacketLen = OS_MBUF_PKTLEN(ctxt->om); + size_t bufferSize = min(dbgPacketLen + stringTerminatorSize, maxBufferSize); auto messageSize = min(maxMessageSize, (bufferSize-headerSize)); - message[messageSize-1] = '\0'; + NotificationManager::Notification notif; + os_mbuf_copydata(ctxt->om, headerSize, messageSize-1, notif.message.data()); + notif.message[messageSize-1] = '\0'; + notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert; + notificationManager.Push(std::move(notif)); - notificationManager.Push(Pinetime::Controllers::NotificationManager::Categories::SimpleAlert, message, messageSize); systemTask.PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification); } return 0; diff --git a/src/components/ble/ImmediateAlertService.cpp b/src/components/ble/ImmediateAlertService.cpp index 3b7f47bf..e2cee308 100644 --- a/src/components/ble/ImmediateAlertService.cpp +++ b/src/components/ble/ImmediateAlertService.cpp @@ -1,4 +1,5 @@ #include +#include #include "ImmediateAlertService.h" #include "AlertNotificationService.h" @@ -67,7 +68,12 @@ int ImmediateAlertService::OnAlertLevelChanged(uint16_t connectionHandle, uint16 if(context->op == BLE_GATT_ACCESS_OP_WRITE_CHR) { auto alertLevel = static_cast(context->om->om_data[0]); auto* alertString = ToString(alertLevel); - notificationManager.Push(Pinetime::Controllers::NotificationManager::Categories::SimpleAlert, alertString, strlen(alertString)); + + NotificationManager::Notification notif; + std::memcpy(notif.message.data(), alertString, strlen(alertString)); + notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert; + notificationManager.Push(std::move(notif)); + systemTask.PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification); } } diff --git a/src/components/ble/NotificationManager.cpp b/src/components/ble/NotificationManager.cpp index 11555bee..67711723 100644 --- a/src/components/ble/NotificationManager.cpp +++ b/src/components/ble/NotificationManager.cpp @@ -7,17 +7,10 @@ using namespace Pinetime::Controllers; constexpr uint8_t NotificationManager::MessageSize; -void NotificationManager::Push(Pinetime::Controllers::NotificationManager::Categories category, - const char *message, uint8_t currentMessageSize) { - // TODO handle edge cases on read/write index - auto checkedSize = std::min(currentMessageSize, MessageSize); - auto& notif = notifications[writeIndex]; - std::memcpy(notif.message.data(), message, checkedSize); - notif.message[checkedSize] = '\0'; - notif.category = category; +void NotificationManager::Push(NotificationManager::Notification &¬if) { 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; diff --git a/src/components/ble/NotificationManager.h b/src/components/ble/NotificationManager.h index 64c6df6d..49fe8306 100644 --- a/src/components/ble/NotificationManager.h +++ b/src/components/ble/NotificationManager.h @@ -20,7 +20,7 @@ namespace Pinetime { }; Notification::Id nextId {0}; - void Push(Categories category, const char* message, uint8_t messageSize); + void Push(Notification&& notif); Notification GetLastNotification(); Notification GetNext(Notification::Id id); Notification GetPrevious(Notification::Id id); From 5983e33b8d7702800dc91a3229b9a7cee75eb006 Mon Sep 17 00:00:00 2001 From: JF Date: Thu, 22 Oct 2020 15:39:20 +0200 Subject: [PATCH 7/7] Notifications : Replace the label "notificationNr/notificationNb" by a grey border on the bottom that is displayed when there are other notifications to available. --- src/displayapp/screens/Notifications.cpp | 28 ++++++++++++++---------- src/displayapp/screens/Notifications.h | 1 + 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp index 38a28e12..85848b2f 100644 --- a/src/displayapp/screens/Notifications.cpp +++ b/src/displayapp/screens/Notifications.cpp @@ -11,10 +11,10 @@ Notifications::Notifications(DisplayApp *app, Pinetime::Controllers::Notificatio auto notification = notificationManager.GetLastNotification(); if(notification.valid) { currentId = notification.id; - currentItem.reset(new NotificationItem("Notification", notification.message.data(), notification.index, notificationManager.NbNotifications(), mode)); + currentItem.reset(new NotificationItem("\nNotification", notification.message.data(), notification.index, notificationManager.NbNotifications(), mode)); validDisplay = true; } else { - currentItem.reset(new NotificationItem("Notification", "No notification to display", 0, notificationManager.NbNotifications(), Modes::Preview)); + currentItem.reset(new NotificationItem("\nNotification", "No notification to display", 0, notificationManager.NbNotifications(), Modes::Preview)); } if(mode == Modes::Preview) { @@ -71,7 +71,7 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) { currentId = previousNotification.id; currentItem.reset(nullptr); app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up); - currentItem.reset(new NotificationItem("Notification", previousNotification.message.data(), previousNotification.index, notificationManager.NbNotifications(), mode)); + currentItem.reset(new NotificationItem("\nNotification", previousNotification.message.data(), previousNotification.index, notificationManager.NbNotifications(), mode)); } return true; case Pinetime::Applications::TouchEvents::SwipeDown: { @@ -87,7 +87,7 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) { currentId = nextNotification.id; currentItem.reset(nullptr); app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down); - currentItem.reset(new NotificationItem("Notification", nextNotification.message.data(), nextNotification.index, notificationManager.NbNotifications(), mode)); + currentItem.reset(new NotificationItem("\nNotification", nextNotification.message.data(), nextNotification.index, notificationManager.NbNotifications(), mode)); } return true; default: @@ -104,7 +104,6 @@ bool Notifications::OnButtonPushed() { Notifications::NotificationItem::NotificationItem(const char *title, const char *msg, uint8_t notifNr, uint8_t notifNb, Modes mode) : notifNr{notifNr}, notifNb{notifNb}, mode{mode} { - container1 = lv_cont_create(lv_scr_act(), nullptr); static lv_style_t contStyle; lv_style_copy(&contStyle, lv_cont_get_style(container1, LV_CONT_STYLE_MAIN)); @@ -140,14 +139,15 @@ Notifications::NotificationItem::NotificationItem(const char *title, const char lv_label_set_body_draw(t1, true); lv_obj_set_width(t1, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right)); lv_label_set_text(t1, title); - lv_obj_set_pos(t1, titleStyle.body.padding.left, titleStyle.body.padding.top); + static constexpr int16_t offscreenOffset = -20 ; + lv_obj_set_pos(t1, titleStyle.body.padding.left, offscreenOffset); auto titleHeight = lv_obj_get_height(t1); l1 = lv_label_create(container1, nullptr); lv_label_set_style(l1, LV_LABEL_STYLE_MAIN, &textStyle); lv_obj_set_pos(l1, textStyle.body.padding.left, - titleHeight + titleStyle.body.padding.bottom + textStyle.body.padding.bottom + + titleHeight + offscreenOffset + textStyle.body.padding.bottom + textStyle.body.padding.top); lv_label_set_long_mode(l1, LV_LABEL_LONG_BREAK); @@ -156,11 +156,15 @@ Notifications::NotificationItem::NotificationItem(const char *title, const char lv_label_set_text(l1, msg); if(mode == Modes::Normal) { - lv_obj_t *bottomlabel = lv_label_create(container1, nullptr); - lv_label_set_style(bottomlabel, LV_LABEL_STYLE_MAIN, &bottomStyle); - lv_obj_align(bottomlabel, container1, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); - snprintf(pageText, 4, "%d/%d", notifNr, notifNb); - lv_label_set_text(bottomlabel, pageText); + if(notifNr < notifNb) { + bottomPlaceholder = lv_label_create(container1, nullptr); + lv_label_set_style(bottomPlaceholder, LV_LABEL_STYLE_MAIN, &titleStyle); + lv_label_set_long_mode(bottomPlaceholder, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(bottomPlaceholder, true); + lv_obj_set_width(bottomPlaceholder, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right)); + lv_label_set_text(bottomPlaceholder, " "); + lv_obj_set_pos(bottomPlaceholder, titleStyle.body.padding.left, LV_VER_RES - 5); + } } } diff --git a/src/displayapp/screens/Notifications.h b/src/displayapp/screens/Notifications.h index 0f797ea6..fb4e1ef2 100644 --- a/src/displayapp/screens/Notifications.h +++ b/src/displayapp/screens/Notifications.h @@ -37,6 +37,7 @@ namespace Pinetime { lv_obj_t* container1; lv_obj_t* t1; lv_obj_t* l1; + lv_obj_t* bottomPlaceholder; Modes mode; };