From bf5c655b4101b0f558ab9d8859064295e3b622a6 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Mon, 17 Oct 2022 20:12:56 +0100 Subject: [PATCH 01/41] Added new app --- src/CMakeLists.txt | 1 + src/displayapp/DisplayApp.cpp | 1 + src/displayapp/fonts/fonts.json | 2 +- src/displayapp/screens/ImageView.cpp | 15 +++++++++++++++ src/displayapp/screens/ImageView.h | 16 ++++++++++++++++ src/displayapp/screens/Symbols.h | 1 + 6 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/displayapp/screens/ImageView.cpp create mode 100644 src/displayapp/screens/ImageView.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e4a354df64..f0af58c266 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -366,6 +366,7 @@ list(APPEND SOURCE_FILES displayapp/DisplayApp.cpp displayapp/screens/Screen.cpp displayapp/screens/Tile.cpp + displayapp/screens/ImageView.cpp displayapp/screens/InfiniPaint.cpp displayapp/screens/Paddle.cpp displayapp/screens/StopWatch.cpp diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 84fa603622..d90a4f7a42 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -13,6 +13,7 @@ #include "displayapp/screens/ApplicationList.h" #include "displayapp/screens/FirmwareUpdate.h" #include "displayapp/screens/FirmwareValidation.h" +#include "displayapp/screens/ImageView.h" #include "displayapp/screens/InfiniPaint.h" #include "displayapp/screens/Paddle.h" #include "displayapp/screens/StopWatch.h" diff --git a/src/displayapp/fonts/fonts.json b/src/displayapp/fonts/fonts.json index 90be1febe6..3f50a6d734 100644 --- a/src/displayapp/fonts/fonts.json +++ b/src/displayapp/fonts/fonts.json @@ -7,7 +7,7 @@ }, { "file": "FontAwesome5-Solid+Brands+Regular.woff", - "range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf06e, 0xf015, 0xf00c, 0xf0f3, 0xf522, 0xf743, 0xf1ec, 0xf55a, 0xf3ed" + "range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf06e, 0xf015, 0xf00c, 0xf0f3, 0xf522, 0xf743, 0xf1ec, 0xf55a, 0xf3ed, 0xf302" } ], "bpp": 1, diff --git a/src/displayapp/screens/ImageView.cpp b/src/displayapp/screens/ImageView.cpp new file mode 100644 index 0000000000..2931c770cb --- /dev/null +++ b/src/displayapp/screens/ImageView.cpp @@ -0,0 +1,15 @@ +#include "displayapp/screens/ImageView.h" +#include "displayapp/DisplayApp.h" + +using namespace Pinetime::Applications::Screens; + +ImageView::ImageView(DisplayApp* app) : Screen(app) { + lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_static(title, "My test application"); + lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); + lv_obj_align(title, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); +} + +ImageView::~ImageView() { + lv_obj_clean(lv_scr_act()); +} diff --git a/src/displayapp/screens/ImageView.h b/src/displayapp/screens/ImageView.h new file mode 100644 index 0000000000..b209e8bec5 --- /dev/null +++ b/src/displayapp/screens/ImageView.h @@ -0,0 +1,16 @@ +#pragma once + +#include "displayapp/screens/Screen.h" +#include + +namespace Pinetime { + namespace Applications { + namespace Screens { + class ImageView : public Screen { + public: + ImageView(DisplayApp* app); + ~ImageView() override; + }; + } + } +} diff --git a/src/displayapp/screens/Symbols.h b/src/displayapp/screens/Symbols.h index fb93e80e87..ba294591c8 100644 --- a/src/displayapp/screens/Symbols.h +++ b/src/displayapp/screens/Symbols.h @@ -19,6 +19,7 @@ namespace Pinetime { static constexpr const char* check = "\xEF\x95\xA0"; static constexpr const char* music = "\xEF\x80\x81"; static constexpr const char* tachometer = "\xEF\x8F\xBD"; + static constexpr const char* imageview = "\xEF\x8C\x82"; static constexpr const char* paintbrush = "\xEF\x87\xBC"; static constexpr const char* paddle = "\xEF\x91\x9D"; static constexpr const char* map = "\xEF\x96\xa0"; From c712c7be59c462b06d69f5f95ec30c3c20c7ed76 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Mon, 17 Oct 2022 20:20:56 +0100 Subject: [PATCH 02/41] Pass filesystem --- src/displayapp/screens/ImageView.cpp | 5 ++++- src/displayapp/screens/ImageView.h | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/displayapp/screens/ImageView.cpp b/src/displayapp/screens/ImageView.cpp index 2931c770cb..d7f4b299b8 100644 --- a/src/displayapp/screens/ImageView.cpp +++ b/src/displayapp/screens/ImageView.cpp @@ -3,7 +3,10 @@ using namespace Pinetime::Applications::Screens; -ImageView::ImageView(DisplayApp* app) : Screen(app) { +ImageView::ImageView(DisplayApp* app, Pinetime::Controllers::FS& filesystem) + : Screen(app), + filesystem(filesystem) +{ lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_static(title, "My test application"); lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); diff --git a/src/displayapp/screens/ImageView.h b/src/displayapp/screens/ImageView.h index b209e8bec5..be97686710 100644 --- a/src/displayapp/screens/ImageView.h +++ b/src/displayapp/screens/ImageView.h @@ -1,6 +1,7 @@ #pragma once #include "displayapp/screens/Screen.h" +#include "displayapp/DisplayApp.h" #include namespace Pinetime { @@ -8,8 +9,10 @@ namespace Pinetime { namespace Screens { class ImageView : public Screen { public: - ImageView(DisplayApp* app); + ImageView(DisplayApp* app, Pinetime::Controllers::FS& filesystem); ~ImageView() override; + private: + Pinetime::Controllers::FS& filesystem; }; } } From e2bdfc4a80e98530871584b98275d2eefe1f49fc Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Mon, 17 Oct 2022 20:43:35 +0100 Subject: [PATCH 03/41] List directory --- src/displayapp/screens/ImageView.cpp | 29 ++++++++++++++++++++++++---- src/displayapp/screens/ImageView.h | 4 ++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/displayapp/screens/ImageView.cpp b/src/displayapp/screens/ImageView.cpp index d7f4b299b8..5d766824fb 100644 --- a/src/displayapp/screens/ImageView.cpp +++ b/src/displayapp/screens/ImageView.cpp @@ -1,3 +1,4 @@ +#include #include "displayapp/screens/ImageView.h" #include "displayapp/DisplayApp.h" @@ -7,12 +8,32 @@ ImageView::ImageView(DisplayApp* app, Pinetime::Controllers::FS& filesystem) : Screen(app), filesystem(filesystem) { - lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text_static(title, "My test application"); - lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); - lv_obj_align(title, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); + listdir(); + + if (nScreens == 0) { + lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_static(title, "no images found"); + lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); + lv_obj_align(title, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); + } } ImageView::~ImageView() { lv_obj_clean(lv_scr_act()); } + +void ImageView::listdir() { + lfs_dir_t dir = {0}; + lfs_info info = {0}; + nScreens = 0; + + int res = filesystem.DirOpen(directory, &dir); + if (res != 0) { + NRF_LOG_INFO("[ImageView] can't find directory"); + return; + } + while (filesystem.DirRead(&dir, &info)) { + nScreens++; + } + assert(filesystem.DirClose(&dir) == 0); +} diff --git a/src/displayapp/screens/ImageView.h b/src/displayapp/screens/ImageView.h index be97686710..891c017103 100644 --- a/src/displayapp/screens/ImageView.h +++ b/src/displayapp/screens/ImageView.h @@ -9,10 +9,14 @@ namespace Pinetime { namespace Screens { class ImageView : public Screen { public: + static constexpr const char* directory = "/gallery"; + ImageView(DisplayApp* app, Pinetime::Controllers::FS& filesystem); ~ImageView() override; private: Pinetime::Controllers::FS& filesystem; + void listdir(); + int nScreens; }; } } From bb5c5da6e737bd753ec92976191d8e3fe889fb2b Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Mon, 17 Oct 2022 20:47:29 +0100 Subject: [PATCH 04/41] only count files in DirRead --- src/displayapp/screens/ImageView.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/displayapp/screens/ImageView.cpp b/src/displayapp/screens/ImageView.cpp index 5d766824fb..3964e5a023 100644 --- a/src/displayapp/screens/ImageView.cpp +++ b/src/displayapp/screens/ImageView.cpp @@ -33,6 +33,8 @@ void ImageView::listdir() { return; } while (filesystem.DirRead(&dir, &info)) { + if(info.type == LFS_TYPE_DIR) + continue; nScreens++; } assert(filesystem.DirClose(&dir) == 0); From cf9825bfee790ae08f2b36a21447b574ab2e3362 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Mon, 17 Oct 2022 21:16:38 +0100 Subject: [PATCH 05/41] Renamed app --- src/CMakeLists.txt | 2 +- src/displayapp/DisplayApp.cpp | 2 +- src/displayapp/screens/{ImageView.cpp => Gallery.cpp} | 10 +++++----- src/displayapp/screens/{ImageView.h => Gallery.h} | 8 +++++--- src/displayapp/screens/Symbols.h | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) rename src/displayapp/screens/{ImageView.cpp => Gallery.cpp} (77%) rename src/displayapp/screens/{ImageView.h => Gallery.h} (69%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f0af58c266..56c5663003 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -366,7 +366,7 @@ list(APPEND SOURCE_FILES displayapp/DisplayApp.cpp displayapp/screens/Screen.cpp displayapp/screens/Tile.cpp - displayapp/screens/ImageView.cpp + displayapp/screens/Gallery.cpp displayapp/screens/InfiniPaint.cpp displayapp/screens/Paddle.cpp displayapp/screens/StopWatch.cpp diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index d90a4f7a42..b197ffdbe6 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -13,7 +13,7 @@ #include "displayapp/screens/ApplicationList.h" #include "displayapp/screens/FirmwareUpdate.h" #include "displayapp/screens/FirmwareValidation.h" -#include "displayapp/screens/ImageView.h" +#include "displayapp/screens/Gallery.h" #include "displayapp/screens/InfiniPaint.h" #include "displayapp/screens/Paddle.h" #include "displayapp/screens/StopWatch.h" diff --git a/src/displayapp/screens/ImageView.cpp b/src/displayapp/screens/Gallery.cpp similarity index 77% rename from src/displayapp/screens/ImageView.cpp rename to src/displayapp/screens/Gallery.cpp index 3964e5a023..321f26f0f9 100644 --- a/src/displayapp/screens/ImageView.cpp +++ b/src/displayapp/screens/Gallery.cpp @@ -1,10 +1,10 @@ #include -#include "displayapp/screens/ImageView.h" +#include "displayapp/screens/Gallery.h" #include "displayapp/DisplayApp.h" using namespace Pinetime::Applications::Screens; -ImageView::ImageView(DisplayApp* app, Pinetime::Controllers::FS& filesystem) +Gallery::Gallery(DisplayApp* app, Pinetime::Controllers::FS& filesystem) : Screen(app), filesystem(filesystem) { @@ -18,18 +18,18 @@ ImageView::ImageView(DisplayApp* app, Pinetime::Controllers::FS& filesystem) } } -ImageView::~ImageView() { +Gallery::~Gallery() { lv_obj_clean(lv_scr_act()); } -void ImageView::listdir() { +void Gallery::listdir() { lfs_dir_t dir = {0}; lfs_info info = {0}; nScreens = 0; int res = filesystem.DirOpen(directory, &dir); if (res != 0) { - NRF_LOG_INFO("[ImageView] can't find directory"); + NRF_LOG_INFO("[Gallery] can't find directory"); return; } while (filesystem.DirRead(&dir, &info)) { diff --git a/src/displayapp/screens/ImageView.h b/src/displayapp/screens/Gallery.h similarity index 69% rename from src/displayapp/screens/ImageView.h rename to src/displayapp/screens/Gallery.h index 891c017103..a952ddb7b4 100644 --- a/src/displayapp/screens/ImageView.h +++ b/src/displayapp/screens/Gallery.h @@ -7,15 +7,17 @@ namespace Pinetime { namespace Applications { namespace Screens { - class ImageView : public Screen { + class Gallery : public Screen { public: static constexpr const char* directory = "/gallery"; - ImageView(DisplayApp* app, Pinetime::Controllers::FS& filesystem); - ~ImageView() override; + Gallery(DisplayApp* app, Pinetime::Controllers::FS& filesystem); + ~Gallery() override; private: Pinetime::Controllers::FS& filesystem; + void listdir(); + void open(int n); int nScreens; }; } diff --git a/src/displayapp/screens/Symbols.h b/src/displayapp/screens/Symbols.h index ba294591c8..5eb309b8a9 100644 --- a/src/displayapp/screens/Symbols.h +++ b/src/displayapp/screens/Symbols.h @@ -19,7 +19,7 @@ namespace Pinetime { static constexpr const char* check = "\xEF\x95\xA0"; static constexpr const char* music = "\xEF\x80\x81"; static constexpr const char* tachometer = "\xEF\x8F\xBD"; - static constexpr const char* imageview = "\xEF\x8C\x82"; + static constexpr const char* gallery = "\xEF\x8C\x82"; static constexpr const char* paintbrush = "\xEF\x87\xBC"; static constexpr const char* paddle = "\xEF\x91\x9D"; static constexpr const char* map = "\xEF\x96\xa0"; From a619ff86347de276df74b90bffafe9cd43c4ec37 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Mon, 17 Oct 2022 21:19:43 +0100 Subject: [PATCH 06/41] Added ImageView --- src/CMakeLists.txt | 1 + src/displayapp/screens/ImageView.cpp | 15 +++++++++++++++ src/displayapp/screens/ImageView.h | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 src/displayapp/screens/ImageView.cpp create mode 100644 src/displayapp/screens/ImageView.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 56c5663003..65f22b5e23 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -366,6 +366,7 @@ list(APPEND SOURCE_FILES displayapp/DisplayApp.cpp displayapp/screens/Screen.cpp displayapp/screens/Tile.cpp + displayapp/screens/ImageView.cpp displayapp/screens/Gallery.cpp displayapp/screens/InfiniPaint.cpp displayapp/screens/Paddle.cpp diff --git a/src/displayapp/screens/ImageView.cpp b/src/displayapp/screens/ImageView.cpp new file mode 100644 index 0000000000..e61a0ea400 --- /dev/null +++ b/src/displayapp/screens/ImageView.cpp @@ -0,0 +1,15 @@ +#include +#include "displayapp/screens/ImageView.h" +#include "displayapp/DisplayApp.h" + +using namespace Pinetime::Applications::Screens; + +ImageView::ImageView(DisplayApp* app) + : Screen(app) +{ + +} + +ImageView::~ImageView() { + lv_obj_clean(lv_scr_act()); +} diff --git a/src/displayapp/screens/ImageView.h b/src/displayapp/screens/ImageView.h new file mode 100644 index 0000000000..7d4b9b5ec2 --- /dev/null +++ b/src/displayapp/screens/ImageView.h @@ -0,0 +1,18 @@ +#pragma once + +#include "displayapp/screens/Screen.h" +#include "displayapp/DisplayApp.h" +#include + +namespace Pinetime { + namespace Applications { + namespace Screens { + class ImageView : public Screen { + public: + ImageView(DisplayApp* app); + ~ImageView() override; + }; + } + } +} + From e9664075a8701e3284f5f6e9a8a45de53a0ebc52 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Mon, 17 Oct 2022 21:27:18 +0100 Subject: [PATCH 07/41] Pass path to ImageView --- src/displayapp/screens/ImageView.cpp | 7 +++++-- src/displayapp/screens/ImageView.h | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/displayapp/screens/ImageView.cpp b/src/displayapp/screens/ImageView.cpp index e61a0ea400..2b54ba04ec 100644 --- a/src/displayapp/screens/ImageView.cpp +++ b/src/displayapp/screens/ImageView.cpp @@ -4,10 +4,13 @@ using namespace Pinetime::Applications::Screens; -ImageView::ImageView(DisplayApp* app) +ImageView::ImageView(DisplayApp* app, const char *path) : Screen(app) { - + lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_static(title, path); + lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); + lv_obj_align(title, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); } ImageView::~ImageView() { diff --git a/src/displayapp/screens/ImageView.h b/src/displayapp/screens/ImageView.h index 7d4b9b5ec2..5d4a52cb01 100644 --- a/src/displayapp/screens/ImageView.h +++ b/src/displayapp/screens/ImageView.h @@ -9,7 +9,7 @@ namespace Pinetime { namespace Screens { class ImageView : public Screen { public: - ImageView(DisplayApp* app); + ImageView(DisplayApp* app, const char *path); ~ImageView() override; }; } From d7328f5bfac1e1606f7ad724e681c82a73b07b64 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Mon, 17 Oct 2022 21:38:40 +0100 Subject: [PATCH 08/41] Added open function --- src/displayapp/screens/Gallery.cpp | 28 ++++++++++++++++++++++++++++ src/displayapp/screens/Gallery.h | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/displayapp/screens/Gallery.cpp b/src/displayapp/screens/Gallery.cpp index 321f26f0f9..1e49370554 100644 --- a/src/displayapp/screens/Gallery.cpp +++ b/src/displayapp/screens/Gallery.cpp @@ -39,3 +39,31 @@ void Gallery::listdir() { } assert(filesystem.DirClose(&dir) == 0); } + +bool Gallery::open(int n, DisplayApp::FullRefreshDirections direction) { + if ( (n < 0) || (n >= nScreens) ) + return false; + + lfs_dir_t dir = {0}; + lfs_info info = {0}; + + int res = filesystem.DirOpen(directory, &dir); + if (res != 0) { + NRF_LOG_INFO("[Gallery] can't find directory"); + return false; + } + while (filesystem.DirRead(&dir, &info) && n > 0) { + if(info.type == LFS_TYPE_DIR) + continue; + n--; + } + assert(filesystem.DirClose(&dir) == 0); + + lfs_file f = {0}; + if (filesystem.FileOpen(&f, info.name, LFS_O_RDONLY) != LFS_ERR_OK) + return false; + + assert(filesystem.FileClose(&f) == 0); + + return true; +} diff --git a/src/displayapp/screens/Gallery.h b/src/displayapp/screens/Gallery.h index a952ddb7b4..d6dd30835e 100644 --- a/src/displayapp/screens/Gallery.h +++ b/src/displayapp/screens/Gallery.h @@ -17,7 +17,7 @@ namespace Pinetime { Pinetime::Controllers::FS& filesystem; void listdir(); - void open(int n); + bool open(int n, DisplayApp::FullRefreshDirections direction); int nScreens; }; } From 20548aa0803ca6fb8e3b1fb46d94a811d9b01037 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Mon, 17 Oct 2022 21:38:50 +0100 Subject: [PATCH 09/41] Keep track of open image --- src/displayapp/screens/Gallery.cpp | 6 ++++++ src/displayapp/screens/Gallery.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/displayapp/screens/Gallery.cpp b/src/displayapp/screens/Gallery.cpp index 1e49370554..c62098dde1 100644 --- a/src/displayapp/screens/Gallery.cpp +++ b/src/displayapp/screens/Gallery.cpp @@ -65,5 +65,11 @@ bool Gallery::open(int n, DisplayApp::FullRefreshDirections direction) { assert(filesystem.FileClose(&f) == 0); + if (current != nullptr) { + current.reset(nullptr); + app->SetFullRefresh(direction); + } + current = std::make_unique(app, info.name); + return true; } diff --git a/src/displayapp/screens/Gallery.h b/src/displayapp/screens/Gallery.h index d6dd30835e..3a837f3fa8 100644 --- a/src/displayapp/screens/Gallery.h +++ b/src/displayapp/screens/Gallery.h @@ -1,6 +1,7 @@ #pragma once #include "displayapp/screens/Screen.h" +#include "displayapp/screens/ImageView.h" #include "displayapp/DisplayApp.h" #include @@ -15,6 +16,7 @@ namespace Pinetime { ~Gallery() override; private: Pinetime::Controllers::FS& filesystem; + std::unique_ptr current; void listdir(); bool open(int n, DisplayApp::FullRefreshDirections direction); From ecde3c5358da9a32555f92376c06586c2d6174e4 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Mon, 17 Oct 2022 22:13:08 +0100 Subject: [PATCH 10/41] Fixed OBOE in open --- src/displayapp/screens/Gallery.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/displayapp/screens/Gallery.cpp b/src/displayapp/screens/Gallery.cpp index c62098dde1..8dda37758d 100644 --- a/src/displayapp/screens/Gallery.cpp +++ b/src/displayapp/screens/Gallery.cpp @@ -52,19 +52,15 @@ bool Gallery::open(int n, DisplayApp::FullRefreshDirections direction) { NRF_LOG_INFO("[Gallery] can't find directory"); return false; } - while (filesystem.DirRead(&dir, &info) && n > 0) { + int i = 0; + while (filesystem.DirRead(&dir, &info)) { if(info.type == LFS_TYPE_DIR) continue; - n--; + if (n == i) break; + i++; } assert(filesystem.DirClose(&dir) == 0); - lfs_file f = {0}; - if (filesystem.FileOpen(&f, info.name, LFS_O_RDONLY) != LFS_ERR_OK) - return false; - - assert(filesystem.FileClose(&f) == 0); - if (current != nullptr) { current.reset(nullptr); app->SetFullRefresh(direction); From d29dc3a22cb8b46d19f3189ba91ca1765ee873b5 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Mon, 17 Oct 2022 22:13:35 +0100 Subject: [PATCH 11/41] Open first image by default --- src/displayapp/screens/Gallery.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/displayapp/screens/Gallery.cpp b/src/displayapp/screens/Gallery.cpp index 8dda37758d..53261cf1c3 100644 --- a/src/displayapp/screens/Gallery.cpp +++ b/src/displayapp/screens/Gallery.cpp @@ -15,6 +15,8 @@ Gallery::Gallery(DisplayApp* app, Pinetime::Controllers::FS& filesystem) lv_label_set_text_static(title, "no images found"); lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); lv_obj_align(title, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); + } else { + open(0, DisplayApp::FullRefreshDirections::None); } } From c6d3adcd60cb690dcf8ddb4a5ee38e3ea1515be4 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Mon, 17 Oct 2022 22:26:55 +0100 Subject: [PATCH 12/41] Pass full path to ImageView --- src/displayapp/screens/Gallery.cpp | 7 ++++++- src/displayapp/screens/Gallery.h | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/displayapp/screens/Gallery.cpp b/src/displayapp/screens/Gallery.cpp index 53261cf1c3..c6dcdbf788 100644 --- a/src/displayapp/screens/Gallery.cpp +++ b/src/displayapp/screens/Gallery.cpp @@ -67,7 +67,12 @@ bool Gallery::open(int n, DisplayApp::FullRefreshDirections direction) { current.reset(nullptr); app->SetFullRefresh(direction); } - current = std::make_unique(app, info.name); + + char fullname[LFS_NAME_MAX] = "F:"; + strncat(fullname, directory, sizeof(fullname) - 2 - 1); + strncat(fullname, info.name, + sizeof(fullname) - strlen(directory) - 2 - 1); + current = std::make_unique(app, fullname); return true; } diff --git a/src/displayapp/screens/Gallery.h b/src/displayapp/screens/Gallery.h index 3a837f3fa8..fbbf68dec6 100644 --- a/src/displayapp/screens/Gallery.h +++ b/src/displayapp/screens/Gallery.h @@ -10,7 +10,7 @@ namespace Pinetime { namespace Screens { class Gallery : public Screen { public: - static constexpr const char* directory = "/gallery"; + static constexpr const char* directory = "/gallery/"; Gallery(DisplayApp* app, Pinetime::Controllers::FS& filesystem); ~Gallery() override; From 74b21e55c8d30846baaea4338cfff9d91273d811 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Mon, 17 Oct 2022 22:38:03 +0100 Subject: [PATCH 13/41] Show image --- src/displayapp/screens/ImageView.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/displayapp/screens/ImageView.cpp b/src/displayapp/screens/ImageView.cpp index 2b54ba04ec..77a26d026c 100644 --- a/src/displayapp/screens/ImageView.cpp +++ b/src/displayapp/screens/ImageView.cpp @@ -7,10 +7,9 @@ using namespace Pinetime::Applications::Screens; ImageView::ImageView(DisplayApp* app, const char *path) : Screen(app) { - lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text_static(title, path); - lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); - lv_obj_align(title, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); + lv_obj_t* image = lv_img_create(lv_scr_act(), nullptr); + lv_img_set_src(image, path); + lv_obj_align(image, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); } ImageView::~ImageView() { From 2d73865c10990008fa586aebdc977096d5a25e17 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Mon, 17 Oct 2022 22:52:44 +0100 Subject: [PATCH 14/41] Added swiping through images --- src/displayapp/screens/Gallery.cpp | 12 ++++++++++++ src/displayapp/screens/Gallery.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/src/displayapp/screens/Gallery.cpp b/src/displayapp/screens/Gallery.cpp index c6dcdbf788..e8354b9d7f 100644 --- a/src/displayapp/screens/Gallery.cpp +++ b/src/displayapp/screens/Gallery.cpp @@ -24,6 +24,16 @@ Gallery::~Gallery() { lv_obj_clean(lv_scr_act()); } +bool Gallery::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + switch (event) { + case Pinetime::Applications::TouchEvents::SwipeRight: + return open(index - 1, DisplayApp::FullRefreshDirections::Right); + case Pinetime::Applications::TouchEvents::SwipeLeft: + return open(index + 1, DisplayApp::FullRefreshDirections::Left); + } + return false; +} + void Gallery::listdir() { lfs_dir_t dir = {0}; lfs_info info = {0}; @@ -46,6 +56,8 @@ bool Gallery::open(int n, DisplayApp::FullRefreshDirections direction) { if ( (n < 0) || (n >= nScreens) ) return false; + index = n; + lfs_dir_t dir = {0}; lfs_info info = {0}; diff --git a/src/displayapp/screens/Gallery.h b/src/displayapp/screens/Gallery.h index fbbf68dec6..d0d64de9a0 100644 --- a/src/displayapp/screens/Gallery.h +++ b/src/displayapp/screens/Gallery.h @@ -14,6 +14,7 @@ namespace Pinetime { Gallery(DisplayApp* app, Pinetime::Controllers::FS& filesystem); ~Gallery() override; + bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; private: Pinetime::Controllers::FS& filesystem; std::unique_ptr current; @@ -21,6 +22,7 @@ namespace Pinetime { void listdir(); bool open(int n, DisplayApp::FullRefreshDirections direction); int nScreens; + int index; }; } } From 2515609c95814f03c323549912f6e6c4a4295b54 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Tue, 18 Oct 2022 07:24:13 +0100 Subject: [PATCH 15/41] Store a human readable name in ImageView --- src/displayapp/screens/ImageView.cpp | 15 +++++++++++++++ src/displayapp/screens/ImageView.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/displayapp/screens/ImageView.cpp b/src/displayapp/screens/ImageView.cpp index 77a26d026c..933662a30c 100644 --- a/src/displayapp/screens/ImageView.cpp +++ b/src/displayapp/screens/ImageView.cpp @@ -7,9 +7,24 @@ using namespace Pinetime::Applications::Screens; ImageView::ImageView(DisplayApp* app, const char *path) : Screen(app) { + label = nullptr; + lv_obj_t* image = lv_img_create(lv_scr_act(), nullptr); lv_img_set_src(image, path); lv_obj_align(image, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); + + const char *c = strrchr(path, '/') + 1; + if (c == nullptr) + c = path; + + strncpy(name, c, LFS_NAME_MAX-1); + char *pchar = strchr(name, '_'); + while (pchar != nullptr) { + *pchar = ' '; + pchar = strchr(pchar + 1, '_'); + } + + ShowInfo(); } ImageView::~ImageView() { diff --git a/src/displayapp/screens/ImageView.h b/src/displayapp/screens/ImageView.h index 5d4a52cb01..c047a51fd1 100644 --- a/src/displayapp/screens/ImageView.h +++ b/src/displayapp/screens/ImageView.h @@ -11,6 +11,8 @@ namespace Pinetime { public: ImageView(DisplayApp* app, const char *path); ~ImageView() override; + private: + char name[LFS_NAME_MAX]; }; } } From 73fe36629a585c6ef36306015db96f120978e363 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Tue, 18 Oct 2022 07:28:39 +0100 Subject: [PATCH 16/41] Show and hide label --- src/displayapp/screens/Gallery.cpp | 4 ++++ src/displayapp/screens/ImageView.cpp | 28 ++++++++++++++++++++++++++++ src/displayapp/screens/ImageView.h | 5 +++++ 3 files changed, 37 insertions(+) diff --git a/src/displayapp/screens/Gallery.cpp b/src/displayapp/screens/Gallery.cpp index e8354b9d7f..4d76f07ff6 100644 --- a/src/displayapp/screens/Gallery.cpp +++ b/src/displayapp/screens/Gallery.cpp @@ -30,6 +30,10 @@ bool Gallery::OnTouchEvent(Pinetime::Applications::TouchEvents event) { return open(index - 1, DisplayApp::FullRefreshDirections::Right); case Pinetime::Applications::TouchEvents::SwipeLeft: return open(index + 1, DisplayApp::FullRefreshDirections::Left); + case Pinetime::Applications::TouchEvents::LongTap: + case Pinetime::Applications::TouchEvents::DoubleTap: + current->ToggleInfo(); + return true; } return false; } diff --git a/src/displayapp/screens/ImageView.cpp b/src/displayapp/screens/ImageView.cpp index 933662a30c..f61dc595d6 100644 --- a/src/displayapp/screens/ImageView.cpp +++ b/src/displayapp/screens/ImageView.cpp @@ -27,6 +27,34 @@ ImageView::ImageView(DisplayApp* app, const char *path) ShowInfo(); } +void ImageView::ShowInfo() { + if(label != nullptr) { + return; + } + label = lv_btn_create(lv_scr_act(), nullptr); + label->user_data = this; + + lv_obj_set_height(label, 20); + lv_obj_set_width(label, LV_HOR_RES); + lv_obj_align(label, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); + + lv_obj_t *txtMessage = lv_label_create(label, nullptr); + lv_obj_set_style_local_bg_color(label, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_NAVY); + lv_label_set_text_static(txtMessage, name); +} + +void ImageView::HideInfo() { + lv_obj_del(label); + label = nullptr; +} + +void ImageView::ToggleInfo() { + if (label == nullptr) + ShowInfo(); + else + HideInfo(); +} + ImageView::~ImageView() { lv_obj_clean(lv_scr_act()); } diff --git a/src/displayapp/screens/ImageView.h b/src/displayapp/screens/ImageView.h index c047a51fd1..ff0ebd0333 100644 --- a/src/displayapp/screens/ImageView.h +++ b/src/displayapp/screens/ImageView.h @@ -11,8 +11,13 @@ namespace Pinetime { public: ImageView(DisplayApp* app, const char *path); ~ImageView() override; + + void ShowInfo(); + void HideInfo(); + void ToggleInfo(); private: char name[LFS_NAME_MAX]; + lv_obj_t *label; }; } } From 7cc90f84d5b049d19978ca978075260afb0204f0 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Tue, 18 Oct 2022 17:20:08 +0100 Subject: [PATCH 17/41] Pass i and n to ImageView --- src/displayapp/screens/Gallery.cpp | 2 +- src/displayapp/screens/ImageView.cpp | 6 ++++-- src/displayapp/screens/ImageView.h | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/displayapp/screens/Gallery.cpp b/src/displayapp/screens/Gallery.cpp index 4d76f07ff6..c0ed4e50aa 100644 --- a/src/displayapp/screens/Gallery.cpp +++ b/src/displayapp/screens/Gallery.cpp @@ -88,7 +88,7 @@ bool Gallery::open(int n, DisplayApp::FullRefreshDirections direction) { strncat(fullname, directory, sizeof(fullname) - 2 - 1); strncat(fullname, info.name, sizeof(fullname) - strlen(directory) - 2 - 1); - current = std::make_unique(app, fullname); + current = std::make_unique(n, nScreens, app, fullname); return true; } diff --git a/src/displayapp/screens/ImageView.cpp b/src/displayapp/screens/ImageView.cpp index f61dc595d6..ece5e31255 100644 --- a/src/displayapp/screens/ImageView.cpp +++ b/src/displayapp/screens/ImageView.cpp @@ -4,8 +4,10 @@ using namespace Pinetime::Applications::Screens; -ImageView::ImageView(DisplayApp* app, const char *path) - : Screen(app) +ImageView::ImageView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char *path) + : screenID(screenID), + nScreens(nScreens), + Screen(app) { label = nullptr; diff --git a/src/displayapp/screens/ImageView.h b/src/displayapp/screens/ImageView.h index ff0ebd0333..cc9c45dd72 100644 --- a/src/displayapp/screens/ImageView.h +++ b/src/displayapp/screens/ImageView.h @@ -9,7 +9,7 @@ namespace Pinetime { namespace Screens { class ImageView : public Screen { public: - ImageView(DisplayApp* app, const char *path); + ImageView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char *path); ~ImageView() override; void ShowInfo(); @@ -18,6 +18,8 @@ namespace Pinetime { private: char name[LFS_NAME_MAX]; lv_obj_t *label; + + uint8_t screenID, nScreens; }; } } From ea938da1749c01f989085decc5dd753ce42a04cd Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Tue, 18 Oct 2022 17:20:42 +0100 Subject: [PATCH 18/41] Added page indicator --- src/displayapp/screens/ImageView.cpp | 31 ++++++++++++++++++++++++++++ src/displayapp/screens/ImageView.h | 4 ++++ 2 files changed, 35 insertions(+) diff --git a/src/displayapp/screens/ImageView.cpp b/src/displayapp/screens/ImageView.cpp index ece5e31255..e68b219182 100644 --- a/src/displayapp/screens/ImageView.cpp +++ b/src/displayapp/screens/ImageView.cpp @@ -1,6 +1,7 @@ #include #include "displayapp/screens/ImageView.h" #include "displayapp/DisplayApp.h" +#include "displayapp/InfiniTimeTheme.h" using namespace Pinetime::Applications::Screens; @@ -10,6 +11,8 @@ ImageView::ImageView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const Screen(app) { label = nullptr; + pageIndicatorBase = nullptr; + pageIndicator = nullptr; lv_obj_t* image = lv_img_create(lv_scr_act(), nullptr); lv_img_set_src(image, path); @@ -26,6 +29,19 @@ ImageView::ImageView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const pchar = strchr(pchar + 1, '_'); } + pageIndicatorBasePoints[0].x = 0; + pageIndicatorBasePoints[0].y = 1; + pageIndicatorBasePoints[1].x = LV_HOR_RES - 1; + pageIndicatorBasePoints[1].y = 1; + + const int16_t indicatorSize = LV_HOR_RES / nScreens; + const int16_t indicatorPos = indicatorSize * screenID; + + pageIndicatorPoints[0].x = indicatorPos; + pageIndicatorPoints[0].y = 1; + pageIndicatorPoints[1].x = indicatorPos + indicatorSize; + pageIndicatorPoints[1].y = 1; + ShowInfo(); } @@ -43,11 +59,26 @@ void ImageView::ShowInfo() { lv_obj_t *txtMessage = lv_label_create(label, nullptr); lv_obj_set_style_local_bg_color(label, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_NAVY); lv_label_set_text_static(txtMessage, name); + + pageIndicatorBase = lv_line_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_line_width(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3); + lv_obj_set_style_local_line_color(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, Colors::bgDark); + lv_line_set_points(pageIndicatorBase, pageIndicatorBasePoints, 2); + + pageIndicator = lv_line_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_line_width(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3); + lv_obj_set_style_local_line_color(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray); + lv_line_set_points(pageIndicator, pageIndicatorPoints, 2); } void ImageView::HideInfo() { lv_obj_del(label); + lv_obj_del(pageIndicatorBase); + lv_obj_del(pageIndicator); + label = nullptr; + pageIndicatorBase = nullptr; + pageIndicator = nullptr; } void ImageView::ToggleInfo() { diff --git a/src/displayapp/screens/ImageView.h b/src/displayapp/screens/ImageView.h index cc9c45dd72..55d257dfba 100644 --- a/src/displayapp/screens/ImageView.h +++ b/src/displayapp/screens/ImageView.h @@ -19,6 +19,10 @@ namespace Pinetime { char name[LFS_NAME_MAX]; lv_obj_t *label; + lv_obj_t *pageIndicatorBase; + lv_obj_t *pageIndicator; + lv_point_t pageIndicatorBasePoints[2]; + lv_point_t pageIndicatorPoints[2]; uint8_t screenID, nScreens; }; } From 86700f5cd014442f7e46747df60f0b04cf469af0 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Tue, 18 Oct 2022 21:45:34 +0100 Subject: [PATCH 19/41] Renamed ImageView --- src/CMakeLists.txt | 2 +- src/displayapp/screens/{ImageView.cpp => FileView.cpp} | 2 +- src/displayapp/screens/{ImageView.h => FileView.h} | 0 src/displayapp/screens/Gallery.h | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename src/displayapp/screens/{ImageView.cpp => FileView.cpp} (98%) rename src/displayapp/screens/{ImageView.h => FileView.h} (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 65f22b5e23..89f552f9f9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -366,7 +366,7 @@ list(APPEND SOURCE_FILES displayapp/DisplayApp.cpp displayapp/screens/Screen.cpp displayapp/screens/Tile.cpp - displayapp/screens/ImageView.cpp + displayapp/screens/FileView.cpp displayapp/screens/Gallery.cpp displayapp/screens/InfiniPaint.cpp displayapp/screens/Paddle.cpp diff --git a/src/displayapp/screens/ImageView.cpp b/src/displayapp/screens/FileView.cpp similarity index 98% rename from src/displayapp/screens/ImageView.cpp rename to src/displayapp/screens/FileView.cpp index e68b219182..fb7bc3656f 100644 --- a/src/displayapp/screens/ImageView.cpp +++ b/src/displayapp/screens/FileView.cpp @@ -1,5 +1,5 @@ #include -#include "displayapp/screens/ImageView.h" +#include "displayapp/screens/FileView.h" #include "displayapp/DisplayApp.h" #include "displayapp/InfiniTimeTheme.h" diff --git a/src/displayapp/screens/ImageView.h b/src/displayapp/screens/FileView.h similarity index 100% rename from src/displayapp/screens/ImageView.h rename to src/displayapp/screens/FileView.h diff --git a/src/displayapp/screens/Gallery.h b/src/displayapp/screens/Gallery.h index d0d64de9a0..002dd2a793 100644 --- a/src/displayapp/screens/Gallery.h +++ b/src/displayapp/screens/Gallery.h @@ -1,7 +1,7 @@ #pragma once #include "displayapp/screens/Screen.h" -#include "displayapp/screens/ImageView.h" +#include "displayapp/screens/FileView.h" #include "displayapp/DisplayApp.h" #include From b91490c4f3e291d691765f2353c3c3803f71bed6 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Tue, 18 Oct 2022 21:48:25 +0100 Subject: [PATCH 20/41] New abstract class FileView --- src/displayapp/screens/FileView.cpp | 21 ++++++++++++--------- src/displayapp/screens/FileView.h | 11 ++++++++--- src/displayapp/screens/Gallery.h | 2 +- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/displayapp/screens/FileView.cpp b/src/displayapp/screens/FileView.cpp index fb7bc3656f..b8873075cd 100644 --- a/src/displayapp/screens/FileView.cpp +++ b/src/displayapp/screens/FileView.cpp @@ -5,7 +5,7 @@ using namespace Pinetime::Applications::Screens; -ImageView::ImageView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char *path) +FileView::FileView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char *path) : screenID(screenID), nScreens(nScreens), Screen(app) @@ -14,10 +14,6 @@ ImageView::ImageView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const pageIndicatorBase = nullptr; pageIndicator = nullptr; - lv_obj_t* image = lv_img_create(lv_scr_act(), nullptr); - lv_img_set_src(image, path); - lv_obj_align(image, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); - const char *c = strrchr(path, '/') + 1; if (c == nullptr) c = path; @@ -45,7 +41,7 @@ ImageView::ImageView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const ShowInfo(); } -void ImageView::ShowInfo() { +void FileView::ShowInfo() { if(label != nullptr) { return; } @@ -71,7 +67,7 @@ void ImageView::ShowInfo() { lv_line_set_points(pageIndicator, pageIndicatorPoints, 2); } -void ImageView::HideInfo() { +void FileView::HideInfo() { lv_obj_del(label); lv_obj_del(pageIndicatorBase); lv_obj_del(pageIndicator); @@ -81,13 +77,20 @@ void ImageView::HideInfo() { pageIndicator = nullptr; } -void ImageView::ToggleInfo() { +void FileView::ToggleInfo() { if (label == nullptr) ShowInfo(); else HideInfo(); } -ImageView::~ImageView() { +FileView::~FileView() { lv_obj_clean(lv_scr_act()); } + +ImageView::ImageView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char *path) + : FileView(screenID, nScreens, app, path) { + lv_obj_t* image = lv_img_create(lv_scr_act(), nullptr); + lv_img_set_src(image, path); + lv_obj_align(image, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); +} diff --git a/src/displayapp/screens/FileView.h b/src/displayapp/screens/FileView.h index 55d257dfba..533797d488 100644 --- a/src/displayapp/screens/FileView.h +++ b/src/displayapp/screens/FileView.h @@ -7,10 +7,10 @@ namespace Pinetime { namespace Applications { namespace Screens { - class ImageView : public Screen { + class FileView : public Screen { public: - ImageView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char *path); - ~ImageView() override; + FileView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char *path); + ~FileView() override; void ShowInfo(); void HideInfo(); @@ -25,6 +25,11 @@ namespace Pinetime { lv_point_t pageIndicatorPoints[2]; uint8_t screenID, nScreens; }; + + class ImageView : public FileView { + public: + ImageView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char *path); + }; } } } diff --git a/src/displayapp/screens/Gallery.h b/src/displayapp/screens/Gallery.h index 002dd2a793..9d6f55cf31 100644 --- a/src/displayapp/screens/Gallery.h +++ b/src/displayapp/screens/Gallery.h @@ -17,7 +17,7 @@ namespace Pinetime { bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; private: Pinetime::Controllers::FS& filesystem; - std::unique_ptr current; + std::unique_ptr current; void listdir(); bool open(int n, DisplayApp::FullRefreshDirections direction); From e45ddce6bed5d9ec0ae31b47e38545670b2bdde6 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Tue, 18 Oct 2022 21:52:42 +0100 Subject: [PATCH 21/41] Check file extension --- src/displayapp/screens/Gallery.cpp | 16 +++++++++++++++- src/displayapp/screens/Gallery.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/displayapp/screens/Gallery.cpp b/src/displayapp/screens/Gallery.cpp index c0ed4e50aa..4bffa2d7c5 100644 --- a/src/displayapp/screens/Gallery.cpp +++ b/src/displayapp/screens/Gallery.cpp @@ -88,7 +88,21 @@ bool Gallery::open(int n, DisplayApp::FullRefreshDirections direction) { strncat(fullname, directory, sizeof(fullname) - 2 - 1); strncat(fullname, info.name, sizeof(fullname) - strlen(directory) - 2 - 1); - current = std::make_unique(n, nScreens, app, fullname); + + if (string_ends_with(fullname, ".bin")) { + current = std::make_unique(n, nScreens, app, fullname); + } else { + return false; + } return true; } + +int Gallery::string_ends_with(const char * str, const char * suffix) { + int str_len = strlen(str); + int suffix_len = strlen(suffix); + + return + (str_len >= suffix_len) && + (0 == strcmp(str + (str_len-suffix_len), suffix)); +} diff --git a/src/displayapp/screens/Gallery.h b/src/displayapp/screens/Gallery.h index 9d6f55cf31..5520f54bd3 100644 --- a/src/displayapp/screens/Gallery.h +++ b/src/displayapp/screens/Gallery.h @@ -16,6 +16,8 @@ namespace Pinetime { ~Gallery() override; bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; private: + int string_ends_with(const char * str, const char * suffix); + Pinetime::Controllers::FS& filesystem; std::unique_ptr current; From cff6e8937bd6bcef178373dede839c36c858ddac Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Tue, 18 Oct 2022 22:22:50 +0100 Subject: [PATCH 22/41] Added class for text files --- src/displayapp/screens/FileView.cpp | 14 ++++++++++++++ src/displayapp/screens/FileView.h | 5 +++++ src/displayapp/screens/Gallery.cpp | 2 ++ 3 files changed, 21 insertions(+) diff --git a/src/displayapp/screens/FileView.cpp b/src/displayapp/screens/FileView.cpp index b8873075cd..d32fe35b2d 100644 --- a/src/displayapp/screens/FileView.cpp +++ b/src/displayapp/screens/FileView.cpp @@ -94,3 +94,17 @@ ImageView::ImageView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const lv_img_set_src(image, path); lv_obj_align(image, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); } + +TextView::TextView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char *path) + : FileView(screenID, nScreens, app, path) { + + lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK); + lv_obj_set_width(label, LV_HOR_RES); + lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); + + //lv_label_set_text(label, buf); + + lv_mem_free(buf); + +} diff --git a/src/displayapp/screens/FileView.h b/src/displayapp/screens/FileView.h index 533797d488..2aca36e576 100644 --- a/src/displayapp/screens/FileView.h +++ b/src/displayapp/screens/FileView.h @@ -30,6 +30,11 @@ namespace Pinetime { public: ImageView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char *path); }; + + class TextView : public FileView { + public: + TextView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char *path); + }; } } } diff --git a/src/displayapp/screens/Gallery.cpp b/src/displayapp/screens/Gallery.cpp index 4bffa2d7c5..98e0794235 100644 --- a/src/displayapp/screens/Gallery.cpp +++ b/src/displayapp/screens/Gallery.cpp @@ -91,6 +91,8 @@ bool Gallery::open(int n, DisplayApp::FullRefreshDirections direction) { if (string_ends_with(fullname, ".bin")) { current = std::make_unique(n, nScreens, app, fullname); + } else if (string_ends_with(fullname, ".txt")) { + current = std::make_unique(n, nScreens, app, fullname); } else { return false; } From 371b32f298f4d9f5b42faa92db2a9df7b29424ba Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Tue, 18 Oct 2022 22:24:47 +0100 Subject: [PATCH 23/41] Open and read text file --- src/displayapp/screens/FileView.cpp | 24 ++++++++++++++++++++++-- src/displayapp/screens/FileView.h | 2 +- src/displayapp/screens/Gallery.cpp | 2 +- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/displayapp/screens/FileView.cpp b/src/displayapp/screens/FileView.cpp index d32fe35b2d..ded67bc361 100644 --- a/src/displayapp/screens/FileView.cpp +++ b/src/displayapp/screens/FileView.cpp @@ -95,7 +95,7 @@ ImageView::ImageView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const lv_obj_align(image, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); } -TextView::TextView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char *path) +TextView::TextView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char *path, Pinetime::Controllers::FS& fs) : FileView(screenID, nScreens, app, path) { lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr); @@ -103,8 +103,28 @@ TextView::TextView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const ch lv_obj_set_width(label, LV_HOR_RES); lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); - //lv_label_set_text(label, buf); + lfs_info info = {0}; + if (fs.Stat(path+2, &info) != LFS_ERR_OK && info.type != LFS_TYPE_DIR) { + lv_label_set_text_static(label, "could not open file"); + return; + } + + char *buf = (char *)lv_mem_alloc(info.size); + if (buf == nullptr) { + lv_label_set_text_static(label, "could not open file"); + return; + } + + lfs_file_t fp; + if (fs.FileOpen(&fp, path+2, LFS_O_RDONLY) != LFS_ERR_OK) { + lv_label_set_text_static(label, "could not open file"); + lv_mem_free(buf); + return; + } + fs.FileRead(&fp, reinterpret_cast(buf), info.size); + lv_label_set_text(label, buf); lv_mem_free(buf); + fs.FileClose(&fp); } diff --git a/src/displayapp/screens/FileView.h b/src/displayapp/screens/FileView.h index 2aca36e576..e46b480ead 100644 --- a/src/displayapp/screens/FileView.h +++ b/src/displayapp/screens/FileView.h @@ -33,7 +33,7 @@ namespace Pinetime { class TextView : public FileView { public: - TextView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char *path); + TextView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char *path, Pinetime::Controllers::FS& fs); }; } } diff --git a/src/displayapp/screens/Gallery.cpp b/src/displayapp/screens/Gallery.cpp index 98e0794235..15591a1d07 100644 --- a/src/displayapp/screens/Gallery.cpp +++ b/src/displayapp/screens/Gallery.cpp @@ -92,7 +92,7 @@ bool Gallery::open(int n, DisplayApp::FullRefreshDirections direction) { if (string_ends_with(fullname, ".bin")) { current = std::make_unique(n, nScreens, app, fullname); } else if (string_ends_with(fullname, ".txt")) { - current = std::make_unique(n, nScreens, app, fullname); + current = std::make_unique(n, nScreens, app, fullname, filesystem); } else { return false; } From 843e0213be1a95a82a11bb883914ccc081fa7e40 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Wed, 19 Oct 2022 07:31:25 +0100 Subject: [PATCH 24/41] Fixed z index --- src/displayapp/screens/FileView.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/displayapp/screens/FileView.cpp b/src/displayapp/screens/FileView.cpp index ded67bc361..29bf869478 100644 --- a/src/displayapp/screens/FileView.cpp +++ b/src/displayapp/screens/FileView.cpp @@ -37,8 +37,6 @@ FileView::FileView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const ch pageIndicatorPoints[0].y = 1; pageIndicatorPoints[1].x = indicatorPos + indicatorSize; pageIndicatorPoints[1].y = 1; - - ShowInfo(); } void FileView::ShowInfo() { @@ -93,6 +91,8 @@ ImageView::ImageView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const lv_obj_t* image = lv_img_create(lv_scr_act(), nullptr); lv_img_set_src(image, path); lv_obj_align(image, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); + + ShowInfo(); } TextView::TextView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char *path, Pinetime::Controllers::FS& fs) @@ -127,4 +127,6 @@ TextView::TextView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const ch lv_mem_free(buf); fs.FileClose(&fp); + + ShowInfo(); } From 4082dd3fdfdf1334ce8d1baae74ffc4cca37f90a Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Thu, 20 Oct 2022 21:10:45 +0100 Subject: [PATCH 25/41] Ran clang-format --- src/displayapp/screens/FileView.cpp | 30 +++++++++++++---------------- src/displayapp/screens/FileView.h | 14 +++++++------- src/displayapp/screens/Gallery.cpp | 23 +++++++++------------- src/displayapp/screens/Gallery.h | 3 ++- 4 files changed, 31 insertions(+), 39 deletions(-) diff --git a/src/displayapp/screens/FileView.cpp b/src/displayapp/screens/FileView.cpp index 29bf869478..5026c50e27 100644 --- a/src/displayapp/screens/FileView.cpp +++ b/src/displayapp/screens/FileView.cpp @@ -5,21 +5,18 @@ using namespace Pinetime::Applications::Screens; -FileView::FileView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char *path) - : screenID(screenID), - nScreens(nScreens), - Screen(app) -{ +FileView::FileView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char* path) + : screenID(screenID), nScreens(nScreens), Screen(app) { label = nullptr; pageIndicatorBase = nullptr; pageIndicator = nullptr; - const char *c = strrchr(path, '/') + 1; + const char* c = strrchr(path, '/') + 1; if (c == nullptr) c = path; - strncpy(name, c, LFS_NAME_MAX-1); - char *pchar = strchr(name, '_'); + strncpy(name, c, LFS_NAME_MAX - 1); + char* pchar = strchr(name, '_'); while (pchar != nullptr) { *pchar = ' '; pchar = strchr(pchar + 1, '_'); @@ -40,7 +37,7 @@ FileView::FileView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const ch } void FileView::ShowInfo() { - if(label != nullptr) { + if (label != nullptr) { return; } label = lv_btn_create(lv_scr_act(), nullptr); @@ -50,7 +47,7 @@ void FileView::ShowInfo() { lv_obj_set_width(label, LV_HOR_RES); lv_obj_align(label, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); - lv_obj_t *txtMessage = lv_label_create(label, nullptr); + lv_obj_t* txtMessage = lv_label_create(label, nullptr); lv_obj_set_style_local_bg_color(label, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_NAVY); lv_label_set_text_static(txtMessage, name); @@ -86,8 +83,7 @@ FileView::~FileView() { lv_obj_clean(lv_scr_act()); } -ImageView::ImageView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char *path) - : FileView(screenID, nScreens, app, path) { +ImageView::ImageView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char* path) : FileView(screenID, nScreens, app, path) { lv_obj_t* image = lv_img_create(lv_scr_act(), nullptr); lv_img_set_src(image, path); lv_obj_align(image, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); @@ -95,8 +91,8 @@ ImageView::ImageView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const ShowInfo(); } -TextView::TextView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char *path, Pinetime::Controllers::FS& fs) - : FileView(screenID, nScreens, app, path) { +TextView::TextView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char* path, Pinetime::Controllers::FS& fs) + : FileView(screenID, nScreens, app, path) { lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr); lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK); @@ -104,19 +100,19 @@ TextView::TextView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const ch lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); lfs_info info = {0}; - if (fs.Stat(path+2, &info) != LFS_ERR_OK && info.type != LFS_TYPE_DIR) { + if (fs.Stat(path + 2, &info) != LFS_ERR_OK && info.type != LFS_TYPE_DIR) { lv_label_set_text_static(label, "could not open file"); return; } - char *buf = (char *)lv_mem_alloc(info.size); + char* buf = (char*) lv_mem_alloc(info.size); if (buf == nullptr) { lv_label_set_text_static(label, "could not open file"); return; } lfs_file_t fp; - if (fs.FileOpen(&fp, path+2, LFS_O_RDONLY) != LFS_ERR_OK) { + if (fs.FileOpen(&fp, path + 2, LFS_O_RDONLY) != LFS_ERR_OK) { lv_label_set_text_static(label, "could not open file"); lv_mem_free(buf); return; diff --git a/src/displayapp/screens/FileView.h b/src/displayapp/screens/FileView.h index e46b480ead..f5e7f580aa 100644 --- a/src/displayapp/screens/FileView.h +++ b/src/displayapp/screens/FileView.h @@ -9,18 +9,19 @@ namespace Pinetime { namespace Screens { class FileView : public Screen { public: - FileView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char *path); + FileView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char* path); ~FileView() override; void ShowInfo(); void HideInfo(); void ToggleInfo(); + private: char name[LFS_NAME_MAX]; - lv_obj_t *label; + lv_obj_t* label; - lv_obj_t *pageIndicatorBase; - lv_obj_t *pageIndicator; + lv_obj_t* pageIndicatorBase; + lv_obj_t* pageIndicator; lv_point_t pageIndicatorBasePoints[2]; lv_point_t pageIndicatorPoints[2]; uint8_t screenID, nScreens; @@ -28,14 +29,13 @@ namespace Pinetime { class ImageView : public FileView { public: - ImageView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char *path); + ImageView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char* path); }; class TextView : public FileView { public: - TextView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char *path, Pinetime::Controllers::FS& fs); + TextView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char* path, Pinetime::Controllers::FS& fs); }; } } } - diff --git a/src/displayapp/screens/Gallery.cpp b/src/displayapp/screens/Gallery.cpp index 15591a1d07..50840a9885 100644 --- a/src/displayapp/screens/Gallery.cpp +++ b/src/displayapp/screens/Gallery.cpp @@ -4,10 +4,7 @@ using namespace Pinetime::Applications::Screens; -Gallery::Gallery(DisplayApp* app, Pinetime::Controllers::FS& filesystem) - : Screen(app), - filesystem(filesystem) -{ +Gallery::Gallery(DisplayApp* app, Pinetime::Controllers::FS& filesystem) : Screen(app), filesystem(filesystem) { listdir(); if (nScreens == 0) { @@ -49,7 +46,7 @@ void Gallery::listdir() { return; } while (filesystem.DirRead(&dir, &info)) { - if(info.type == LFS_TYPE_DIR) + if (info.type == LFS_TYPE_DIR) continue; nScreens++; } @@ -57,7 +54,7 @@ void Gallery::listdir() { } bool Gallery::open(int n, DisplayApp::FullRefreshDirections direction) { - if ( (n < 0) || (n >= nScreens) ) + if ((n < 0) || (n >= nScreens)) return false; index = n; @@ -72,9 +69,10 @@ bool Gallery::open(int n, DisplayApp::FullRefreshDirections direction) { } int i = 0; while (filesystem.DirRead(&dir, &info)) { - if(info.type == LFS_TYPE_DIR) + if (info.type == LFS_TYPE_DIR) continue; - if (n == i) break; + if (n == i) + break; i++; } assert(filesystem.DirClose(&dir) == 0); @@ -86,8 +84,7 @@ bool Gallery::open(int n, DisplayApp::FullRefreshDirections direction) { char fullname[LFS_NAME_MAX] = "F:"; strncat(fullname, directory, sizeof(fullname) - 2 - 1); - strncat(fullname, info.name, - sizeof(fullname) - strlen(directory) - 2 - 1); + strncat(fullname, info.name, sizeof(fullname) - strlen(directory) - 2 - 1); if (string_ends_with(fullname, ".bin")) { current = std::make_unique(n, nScreens, app, fullname); @@ -100,11 +97,9 @@ bool Gallery::open(int n, DisplayApp::FullRefreshDirections direction) { return true; } -int Gallery::string_ends_with(const char * str, const char * suffix) { +int Gallery::string_ends_with(const char* str, const char* suffix) { int str_len = strlen(str); int suffix_len = strlen(suffix); - return - (str_len >= suffix_len) && - (0 == strcmp(str + (str_len-suffix_len), suffix)); + return (str_len >= suffix_len) && (0 == strcmp(str + (str_len - suffix_len), suffix)); } diff --git a/src/displayapp/screens/Gallery.h b/src/displayapp/screens/Gallery.h index 5520f54bd3..63368626f1 100644 --- a/src/displayapp/screens/Gallery.h +++ b/src/displayapp/screens/Gallery.h @@ -15,8 +15,9 @@ namespace Pinetime { Gallery(DisplayApp* app, Pinetime::Controllers::FS& filesystem); ~Gallery() override; bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; + private: - int string_ends_with(const char * str, const char * suffix); + int string_ends_with(const char* str, const char* suffix); Pinetime::Controllers::FS& filesystem; std::unique_ptr current; From 1935affc7f5a3f71c8b397036a93492d0d5797bb Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Fri, 28 Oct 2022 21:42:25 +0100 Subject: [PATCH 26/41] Switched to CamelCase --- src/displayapp/screens/Gallery.cpp | 18 +++++++++--------- src/displayapp/screens/Gallery.h | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/displayapp/screens/Gallery.cpp b/src/displayapp/screens/Gallery.cpp index 50840a9885..e2015c118d 100644 --- a/src/displayapp/screens/Gallery.cpp +++ b/src/displayapp/screens/Gallery.cpp @@ -5,7 +5,7 @@ using namespace Pinetime::Applications::Screens; Gallery::Gallery(DisplayApp* app, Pinetime::Controllers::FS& filesystem) : Screen(app), filesystem(filesystem) { - listdir(); + ListDir(); if (nScreens == 0) { lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); @@ -13,7 +13,7 @@ Gallery::Gallery(DisplayApp* app, Pinetime::Controllers::FS& filesystem) : Scree lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); lv_obj_align(title, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); } else { - open(0, DisplayApp::FullRefreshDirections::None); + Open(0, DisplayApp::FullRefreshDirections::None); } } @@ -24,9 +24,9 @@ Gallery::~Gallery() { bool Gallery::OnTouchEvent(Pinetime::Applications::TouchEvents event) { switch (event) { case Pinetime::Applications::TouchEvents::SwipeRight: - return open(index - 1, DisplayApp::FullRefreshDirections::Right); + return Open(index - 1, DisplayApp::FullRefreshDirections::Right); case Pinetime::Applications::TouchEvents::SwipeLeft: - return open(index + 1, DisplayApp::FullRefreshDirections::Left); + return Open(index + 1, DisplayApp::FullRefreshDirections::Left); case Pinetime::Applications::TouchEvents::LongTap: case Pinetime::Applications::TouchEvents::DoubleTap: current->ToggleInfo(); @@ -35,7 +35,7 @@ bool Gallery::OnTouchEvent(Pinetime::Applications::TouchEvents event) { return false; } -void Gallery::listdir() { +void Gallery::ListDir() { lfs_dir_t dir = {0}; lfs_info info = {0}; nScreens = 0; @@ -53,7 +53,7 @@ void Gallery::listdir() { assert(filesystem.DirClose(&dir) == 0); } -bool Gallery::open(int n, DisplayApp::FullRefreshDirections direction) { +bool Gallery::Open(int n, DisplayApp::FullRefreshDirections direction) { if ((n < 0) || (n >= nScreens)) return false; @@ -86,9 +86,9 @@ bool Gallery::open(int n, DisplayApp::FullRefreshDirections direction) { strncat(fullname, directory, sizeof(fullname) - 2 - 1); strncat(fullname, info.name, sizeof(fullname) - strlen(directory) - 2 - 1); - if (string_ends_with(fullname, ".bin")) { + if (StringEndsWith(fullname, ".bin")) { current = std::make_unique(n, nScreens, app, fullname); - } else if (string_ends_with(fullname, ".txt")) { + } else if (StringEndsWith(fullname, ".txt")) { current = std::make_unique(n, nScreens, app, fullname, filesystem); } else { return false; @@ -97,7 +97,7 @@ bool Gallery::open(int n, DisplayApp::FullRefreshDirections direction) { return true; } -int Gallery::string_ends_with(const char* str, const char* suffix) { +int Gallery::StringEndsWith(const char* str, const char* suffix) { int str_len = strlen(str); int suffix_len = strlen(suffix); diff --git a/src/displayapp/screens/Gallery.h b/src/displayapp/screens/Gallery.h index 63368626f1..888b0736cd 100644 --- a/src/displayapp/screens/Gallery.h +++ b/src/displayapp/screens/Gallery.h @@ -17,13 +17,13 @@ namespace Pinetime { bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; private: - int string_ends_with(const char* str, const char* suffix); + int StringEndsWith(const char* str, const char* suffix); Pinetime::Controllers::FS& filesystem; std::unique_ptr current; - void listdir(); - bool open(int n, DisplayApp::FullRefreshDirections direction); + void ListDir(); + bool Open(int n, DisplayApp::FullRefreshDirections direction); int nScreens; int index; }; From 519d76184bdf5149789ce3a5df8159ca3644f269 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Sat, 5 Nov 2022 16:28:45 +0000 Subject: [PATCH 27/41] 1. Added PageIndicator::CreateHorizontal --- src/displayapp/widgets/PageIndicator.cpp | 25 ++++++++++++++++++++++++ src/displayapp/widgets/PageIndicator.h | 1 + 2 files changed, 26 insertions(+) diff --git a/src/displayapp/widgets/PageIndicator.cpp b/src/displayapp/widgets/PageIndicator.cpp index cee979f22c..92365849d5 100644 --- a/src/displayapp/widgets/PageIndicator.cpp +++ b/src/displayapp/widgets/PageIndicator.cpp @@ -34,3 +34,28 @@ void PageIndicator::SetPageIndicatorPosition(uint8_t position) { lv_line_set_points(pageIndicator, pageIndicatorPoints, 2); } + +void PageIndicator::CreateHorizontal() { + pageIndicatorBasePoints[0].x = 0; + pageIndicatorBasePoints[0].y = 1; + pageIndicatorBasePoints[1].x = LV_HOR_RES - 1; + pageIndicatorBasePoints[1].y = 1; + + pageIndicatorBase = lv_line_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_line_width(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3); + lv_obj_set_style_local_line_color(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, Colors::bgDark); + lv_line_set_points(pageIndicatorBase, pageIndicatorBasePoints, 2); + + const int16_t indicatorSize = LV_HOR_RES / nScreens; + const int16_t indicatorPos = indicatorSize * nCurrentScreen; + + pageIndicatorPoints[0].x = indicatorPos; + pageIndicatorPoints[0].y = 1; + pageIndicatorPoints[1].x = indicatorPos + indicatorSize; + pageIndicatorPoints[1].y = 1; + + pageIndicator = lv_line_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_line_width(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3); + lv_obj_set_style_local_line_color(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray); + lv_line_set_points(pageIndicator, pageIndicatorPoints, 2); +} diff --git a/src/displayapp/widgets/PageIndicator.h b/src/displayapp/widgets/PageIndicator.h index b9aaffe408..01720fef9a 100644 --- a/src/displayapp/widgets/PageIndicator.h +++ b/src/displayapp/widgets/PageIndicator.h @@ -9,6 +9,7 @@ namespace Pinetime { PageIndicator(uint8_t nCurrentScreen, uint8_t nScreens); void Create(); void SetPageIndicatorPosition(uint8_t position); + void CreateHorizontal(); private: uint8_t nCurrentScreen; From b4b96f652f9de02127895ecdee61d9dfa100a6c4 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Sat, 5 Nov 2022 16:34:39 +0000 Subject: [PATCH 28/41] 2. Used page indicator --- src/displayapp/screens/FileView.cpp | 34 ++++------------------------- src/displayapp/screens/FileView.h | 6 ++--- 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/src/displayapp/screens/FileView.cpp b/src/displayapp/screens/FileView.cpp index 5026c50e27..ac5d67229c 100644 --- a/src/displayapp/screens/FileView.cpp +++ b/src/displayapp/screens/FileView.cpp @@ -6,10 +6,10 @@ using namespace Pinetime::Applications::Screens; FileView::FileView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char* path) - : screenID(screenID), nScreens(nScreens), Screen(app) { + : screenID(screenID), nScreens(nScreens), Screen(app), pageIndicator(screenID, nScreens) { label = nullptr; - pageIndicatorBase = nullptr; - pageIndicator = nullptr; + + pageIndicator.CreateHorizontal(); const char* c = strrchr(path, '/') + 1; if (c == nullptr) @@ -21,19 +21,6 @@ FileView::FileView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const ch *pchar = ' '; pchar = strchr(pchar + 1, '_'); } - - pageIndicatorBasePoints[0].x = 0; - pageIndicatorBasePoints[0].y = 1; - pageIndicatorBasePoints[1].x = LV_HOR_RES - 1; - pageIndicatorBasePoints[1].y = 1; - - const int16_t indicatorSize = LV_HOR_RES / nScreens; - const int16_t indicatorPos = indicatorSize * screenID; - - pageIndicatorPoints[0].x = indicatorPos; - pageIndicatorPoints[0].y = 1; - pageIndicatorPoints[1].x = indicatorPos + indicatorSize; - pageIndicatorPoints[1].y = 1; } void FileView::ShowInfo() { @@ -50,26 +37,13 @@ void FileView::ShowInfo() { lv_obj_t* txtMessage = lv_label_create(label, nullptr); lv_obj_set_style_local_bg_color(label, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_NAVY); lv_label_set_text_static(txtMessage, name); - - pageIndicatorBase = lv_line_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_line_width(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3); - lv_obj_set_style_local_line_color(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, Colors::bgDark); - lv_line_set_points(pageIndicatorBase, pageIndicatorBasePoints, 2); - - pageIndicator = lv_line_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_line_width(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3); - lv_obj_set_style_local_line_color(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray); - lv_line_set_points(pageIndicator, pageIndicatorPoints, 2); } void FileView::HideInfo() { lv_obj_del(label); - lv_obj_del(pageIndicatorBase); - lv_obj_del(pageIndicator); + // TODO: delete page indicator label = nullptr; - pageIndicatorBase = nullptr; - pageIndicator = nullptr; } void FileView::ToggleInfo() { diff --git a/src/displayapp/screens/FileView.h b/src/displayapp/screens/FileView.h index f5e7f580aa..34e5796c2f 100644 --- a/src/displayapp/screens/FileView.h +++ b/src/displayapp/screens/FileView.h @@ -2,6 +2,7 @@ #include "displayapp/screens/Screen.h" #include "displayapp/DisplayApp.h" +#include "displayapp/widgets/PageIndicator.h" #include namespace Pinetime { @@ -20,10 +21,7 @@ namespace Pinetime { char name[LFS_NAME_MAX]; lv_obj_t* label; - lv_obj_t* pageIndicatorBase; - lv_obj_t* pageIndicator; - lv_point_t pageIndicatorBasePoints[2]; - lv_point_t pageIndicatorPoints[2]; + Widgets::PageIndicator pageIndicator; uint8_t screenID, nScreens; }; From 38bbe605994885e170b45e6b7c4da238a7e238f5 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Sat, 5 Nov 2022 16:40:56 +0000 Subject: [PATCH 29/41] 3. Added PageIndicator::Hide --- src/displayapp/widgets/PageIndicator.cpp | 8 ++++++++ src/displayapp/widgets/PageIndicator.h | 1 + 2 files changed, 9 insertions(+) diff --git a/src/displayapp/widgets/PageIndicator.cpp b/src/displayapp/widgets/PageIndicator.cpp index 92365849d5..cee94c96d5 100644 --- a/src/displayapp/widgets/PageIndicator.cpp +++ b/src/displayapp/widgets/PageIndicator.cpp @@ -59,3 +59,11 @@ void PageIndicator::CreateHorizontal() { lv_obj_set_style_local_line_color(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray); lv_line_set_points(pageIndicator, pageIndicatorPoints, 2); } + +void PageIndicator::Hide() { + lv_obj_del(pageIndicatorBase); + lv_obj_del(pageIndicator); + + pageIndicatorBase = nullptr; + pageIndicator = nullptr; +} diff --git a/src/displayapp/widgets/PageIndicator.h b/src/displayapp/widgets/PageIndicator.h index 01720fef9a..29a00174bc 100644 --- a/src/displayapp/widgets/PageIndicator.h +++ b/src/displayapp/widgets/PageIndicator.h @@ -10,6 +10,7 @@ namespace Pinetime { void Create(); void SetPageIndicatorPosition(uint8_t position); void CreateHorizontal(); + void Hide(); private: uint8_t nCurrentScreen; From 6b4b11e597cd1d4cc693790c424a4fc1d439f562 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Sat, 5 Nov 2022 16:41:56 +0000 Subject: [PATCH 30/41] 4. Re-implemented FileView::HideInfo --- src/displayapp/screens/FileView.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/displayapp/screens/FileView.cpp b/src/displayapp/screens/FileView.cpp index ac5d67229c..ec1e9d8e4e 100644 --- a/src/displayapp/screens/FileView.cpp +++ b/src/displayapp/screens/FileView.cpp @@ -9,8 +9,6 @@ FileView::FileView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const ch : screenID(screenID), nScreens(nScreens), Screen(app), pageIndicator(screenID, nScreens) { label = nullptr; - pageIndicator.CreateHorizontal(); - const char* c = strrchr(path, '/') + 1; if (c == nullptr) c = path; @@ -37,11 +35,13 @@ void FileView::ShowInfo() { lv_obj_t* txtMessage = lv_label_create(label, nullptr); lv_obj_set_style_local_bg_color(label, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_NAVY); lv_label_set_text_static(txtMessage, name); + + pageIndicator.CreateHorizontal(); } void FileView::HideInfo() { lv_obj_del(label); - // TODO: delete page indicator + pageIndicator.Hide(); label = nullptr; } From 46f820c7c2427af11906edb046c58fcdfecea705 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Sat, 31 Dec 2022 18:29:25 +0100 Subject: [PATCH 31/41] Avoid temp. double allocation of text buffer --- src/displayapp/screens/FileView.cpp | 11 ++++++++--- src/displayapp/screens/FileView.h | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/displayapp/screens/FileView.cpp b/src/displayapp/screens/FileView.cpp index ec1e9d8e4e..1729d05cc7 100644 --- a/src/displayapp/screens/FileView.cpp +++ b/src/displayapp/screens/FileView.cpp @@ -79,7 +79,7 @@ TextView::TextView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const ch return; } - char* buf = (char*) lv_mem_alloc(info.size); + buf = (char*) lv_mem_alloc(info.size); if (buf == nullptr) { lv_label_set_text_static(label, "could not open file"); return; @@ -93,10 +93,15 @@ TextView::TextView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const ch } fs.FileRead(&fp, reinterpret_cast(buf), info.size); - lv_label_set_text(label, buf); - lv_mem_free(buf); + lv_label_set_text_static(label, buf); fs.FileClose(&fp); ShowInfo(); } + +TextView::~TextView() { + if (buf != nullptr) + lv_mem_free(buf); + lv_obj_clean(lv_scr_act()); +} diff --git a/src/displayapp/screens/FileView.h b/src/displayapp/screens/FileView.h index 34e5796c2f..e0051c13e9 100644 --- a/src/displayapp/screens/FileView.h +++ b/src/displayapp/screens/FileView.h @@ -33,6 +33,10 @@ namespace Pinetime { class TextView : public FileView { public: TextView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char* path, Pinetime::Controllers::FS& fs); + ~TextView() override; + + private: + char *buf; }; } } From 3be86cf5b63710f62beda0027e1c44ad7afbe13d Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Sat, 31 Dec 2022 18:35:38 +0100 Subject: [PATCH 32/41] Check file properly --- src/displayapp/screens/FileView.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/displayapp/screens/FileView.cpp b/src/displayapp/screens/FileView.cpp index 1729d05cc7..fa7dc89deb 100644 --- a/src/displayapp/screens/FileView.cpp +++ b/src/displayapp/screens/FileView.cpp @@ -74,14 +74,18 @@ TextView::TextView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const ch lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); lfs_info info = {0}; - if (fs.Stat(path + 2, &info) != LFS_ERR_OK && info.type != LFS_TYPE_DIR) { - lv_label_set_text_static(label, "could not open file"); + if (fs.Stat(path + 2, &info) != LFS_ERR_OK) { + lv_label_set_text_static(label, "could not stat file"); + return; + } + if (info.type != LFS_TYPE_REG) { + lv_label_set_text_static(label, "not a file"); return; } buf = (char*) lv_mem_alloc(info.size); if (buf == nullptr) { - lv_label_set_text_static(label, "could not open file"); + lv_label_set_text_static(label, "could not allocate buffer"); return; } From 9d32c3264e06c59d5bf62891a7337e3e840ca411 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Sat, 31 Dec 2022 22:39:15 +0100 Subject: [PATCH 33/41] New concept: index file instead of DirRead --- src/displayapp/screens/Gallery.cpp | 55 +++++++++++++----------------- src/displayapp/screens/Gallery.h | 4 +-- 2 files changed, 25 insertions(+), 34 deletions(-) diff --git a/src/displayapp/screens/Gallery.cpp b/src/displayapp/screens/Gallery.cpp index e2015c118d..519c495a28 100644 --- a/src/displayapp/screens/Gallery.cpp +++ b/src/displayapp/screens/Gallery.cpp @@ -5,7 +5,7 @@ using namespace Pinetime::Applications::Screens; Gallery::Gallery(DisplayApp* app, Pinetime::Controllers::FS& filesystem) : Screen(app), filesystem(filesystem) { - ListDir(); + nScreens = CountFiles(); if (nScreens == 0) { lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); @@ -35,22 +35,13 @@ bool Gallery::OnTouchEvent(Pinetime::Applications::TouchEvents event) { return false; } -void Gallery::ListDir() { - lfs_dir_t dir = {0}; +uint8_t Gallery::CountFiles() { lfs_info info = {0}; - nScreens = 0; - - int res = filesystem.DirOpen(directory, &dir); - if (res != 0) { - NRF_LOG_INFO("[Gallery] can't find directory"); - return; - } - while (filesystem.DirRead(&dir, &info)) { - if (info.type == LFS_TYPE_DIR) - continue; - nScreens++; + if (filesystem.Stat(index_file, &info) != LFS_ERR_OK) { + NRF_LOG_INFO("[Gallery] can't stat index"); + return 0; } - assert(filesystem.DirClose(&dir) == 0); + return info.size / LFS_NAME_MAX; } bool Gallery::Open(int n, DisplayApp::FullRefreshDirections direction) { @@ -59,33 +50,33 @@ bool Gallery::Open(int n, DisplayApp::FullRefreshDirections direction) { index = n; - lfs_dir_t dir = {0}; - lfs_info info = {0}; + char fullname[LFS_NAME_MAX+2] = "F:"; - int res = filesystem.DirOpen(directory, &dir); - if (res != 0) { - NRF_LOG_INFO("[Gallery] can't find directory"); + lfs_file_t fp; + int res = filesystem.FileOpen(&fp, index_file, LFS_O_RDONLY); + if (res != LFS_ERR_OK) { + NRF_LOG_INFO("[Gallery] can't open index"); return false; } - int i = 0; - while (filesystem.DirRead(&dir, &info)) { - if (info.type == LFS_TYPE_DIR) - continue; - if (n == i) - break; - i++; + res = filesystem.FileSeek(&fp, n * LFS_NAME_MAX); + if (res != n * LFS_NAME_MAX) { + filesystem.FileClose(&fp); + NRF_LOG_INFO("[Gallery] can't seek index"); + return false; } - assert(filesystem.DirClose(&dir) == 0); + res = filesystem.FileRead(&fp, reinterpret_cast(fullname)+2, LFS_NAME_MAX); + if (res != LFS_NAME_MAX) { + NRF_LOG_INFO("[Gallery] can't read index"); + filesystem.FileClose(&fp); + return false; + } + filesystem.FileClose(&fp); if (current != nullptr) { current.reset(nullptr); app->SetFullRefresh(direction); } - char fullname[LFS_NAME_MAX] = "F:"; - strncat(fullname, directory, sizeof(fullname) - 2 - 1); - strncat(fullname, info.name, sizeof(fullname) - strlen(directory) - 2 - 1); - if (StringEndsWith(fullname, ".bin")) { current = std::make_unique(n, nScreens, app, fullname); } else if (StringEndsWith(fullname, ".txt")) { diff --git a/src/displayapp/screens/Gallery.h b/src/displayapp/screens/Gallery.h index 888b0736cd..903ccb34e9 100644 --- a/src/displayapp/screens/Gallery.h +++ b/src/displayapp/screens/Gallery.h @@ -10,7 +10,7 @@ namespace Pinetime { namespace Screens { class Gallery : public Screen { public: - static constexpr const char* directory = "/gallery/"; + static constexpr const char* index_file = "/gallery/index"; Gallery(DisplayApp* app, Pinetime::Controllers::FS& filesystem); ~Gallery() override; @@ -22,7 +22,7 @@ namespace Pinetime { Pinetime::Controllers::FS& filesystem; std::unique_ptr current; - void ListDir(); + uint8_t CountFiles(); bool Open(int n, DisplayApp::FullRefreshDirections direction); int nScreens; int index; From b29a044f7cc5519266fb8179a2418bd66336636c Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Fri, 3 Mar 2023 19:48:12 +0000 Subject: [PATCH 34/41] Top-align textview --- src/displayapp/screens/FileView.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/displayapp/screens/FileView.cpp b/src/displayapp/screens/FileView.cpp index fa7dc89deb..59d674c3ef 100644 --- a/src/displayapp/screens/FileView.cpp +++ b/src/displayapp/screens/FileView.cpp @@ -71,7 +71,6 @@ TextView::TextView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const ch lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr); lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK); lv_obj_set_width(label, LV_HOR_RES); - lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); lfs_info info = {0}; if (fs.Stat(path + 2, &info) != LFS_ERR_OK) { From c01bea956b9638fd7121d1b3a69cbfd470739d33 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Sun, 12 Mar 2023 12:57:30 +0000 Subject: [PATCH 35/41] Revert "New concept: index file instead of DirRead" This reverts commit 8644937b11150c37cd9269759ebcfcc3a83ebb67. --- src/displayapp/screens/Gallery.cpp | 55 +++++++++++++++++------------- src/displayapp/screens/Gallery.h | 4 +-- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/src/displayapp/screens/Gallery.cpp b/src/displayapp/screens/Gallery.cpp index 519c495a28..e2015c118d 100644 --- a/src/displayapp/screens/Gallery.cpp +++ b/src/displayapp/screens/Gallery.cpp @@ -5,7 +5,7 @@ using namespace Pinetime::Applications::Screens; Gallery::Gallery(DisplayApp* app, Pinetime::Controllers::FS& filesystem) : Screen(app), filesystem(filesystem) { - nScreens = CountFiles(); + ListDir(); if (nScreens == 0) { lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); @@ -35,13 +35,22 @@ bool Gallery::OnTouchEvent(Pinetime::Applications::TouchEvents event) { return false; } -uint8_t Gallery::CountFiles() { +void Gallery::ListDir() { + lfs_dir_t dir = {0}; lfs_info info = {0}; - if (filesystem.Stat(index_file, &info) != LFS_ERR_OK) { - NRF_LOG_INFO("[Gallery] can't stat index"); - return 0; + nScreens = 0; + + int res = filesystem.DirOpen(directory, &dir); + if (res != 0) { + NRF_LOG_INFO("[Gallery] can't find directory"); + return; + } + while (filesystem.DirRead(&dir, &info)) { + if (info.type == LFS_TYPE_DIR) + continue; + nScreens++; } - return info.size / LFS_NAME_MAX; + assert(filesystem.DirClose(&dir) == 0); } bool Gallery::Open(int n, DisplayApp::FullRefreshDirections direction) { @@ -50,33 +59,33 @@ bool Gallery::Open(int n, DisplayApp::FullRefreshDirections direction) { index = n; - char fullname[LFS_NAME_MAX+2] = "F:"; + lfs_dir_t dir = {0}; + lfs_info info = {0}; - lfs_file_t fp; - int res = filesystem.FileOpen(&fp, index_file, LFS_O_RDONLY); - if (res != LFS_ERR_OK) { - NRF_LOG_INFO("[Gallery] can't open index"); + int res = filesystem.DirOpen(directory, &dir); + if (res != 0) { + NRF_LOG_INFO("[Gallery] can't find directory"); return false; } - res = filesystem.FileSeek(&fp, n * LFS_NAME_MAX); - if (res != n * LFS_NAME_MAX) { - filesystem.FileClose(&fp); - NRF_LOG_INFO("[Gallery] can't seek index"); - return false; + int i = 0; + while (filesystem.DirRead(&dir, &info)) { + if (info.type == LFS_TYPE_DIR) + continue; + if (n == i) + break; + i++; } - res = filesystem.FileRead(&fp, reinterpret_cast(fullname)+2, LFS_NAME_MAX); - if (res != LFS_NAME_MAX) { - NRF_LOG_INFO("[Gallery] can't read index"); - filesystem.FileClose(&fp); - return false; - } - filesystem.FileClose(&fp); + assert(filesystem.DirClose(&dir) == 0); if (current != nullptr) { current.reset(nullptr); app->SetFullRefresh(direction); } + char fullname[LFS_NAME_MAX] = "F:"; + strncat(fullname, directory, sizeof(fullname) - 2 - 1); + strncat(fullname, info.name, sizeof(fullname) - strlen(directory) - 2 - 1); + if (StringEndsWith(fullname, ".bin")) { current = std::make_unique(n, nScreens, app, fullname); } else if (StringEndsWith(fullname, ".txt")) { diff --git a/src/displayapp/screens/Gallery.h b/src/displayapp/screens/Gallery.h index 903ccb34e9..888b0736cd 100644 --- a/src/displayapp/screens/Gallery.h +++ b/src/displayapp/screens/Gallery.h @@ -10,7 +10,7 @@ namespace Pinetime { namespace Screens { class Gallery : public Screen { public: - static constexpr const char* index_file = "/gallery/index"; + static constexpr const char* directory = "/gallery/"; Gallery(DisplayApp* app, Pinetime::Controllers::FS& filesystem); ~Gallery() override; @@ -22,7 +22,7 @@ namespace Pinetime { Pinetime::Controllers::FS& filesystem; std::unique_ptr current; - uint8_t CountFiles(); + void ListDir(); bool Open(int n, DisplayApp::FullRefreshDirections direction); int nScreens; int index; From 480eb14bc382ff3cc4b137f9250126ca32867215 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Sun, 12 Mar 2023 13:11:32 +0000 Subject: [PATCH 36/41] Removed assert Thanks to @IchbinkeinReh for pointing this out --- src/displayapp/screens/Gallery.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/displayapp/screens/Gallery.cpp b/src/displayapp/screens/Gallery.cpp index e2015c118d..fb84bf0f77 100644 --- a/src/displayapp/screens/Gallery.cpp +++ b/src/displayapp/screens/Gallery.cpp @@ -50,7 +50,11 @@ void Gallery::ListDir() { continue; nScreens++; } - assert(filesystem.DirClose(&dir) == 0); + res = filesystem.DirClose(&dir); + if (res != 0) { + NRF_LOG_INFO("[Gallery] DirClose failed"); + return; + } } bool Gallery::Open(int n, DisplayApp::FullRefreshDirections direction) { @@ -75,7 +79,11 @@ bool Gallery::Open(int n, DisplayApp::FullRefreshDirections direction) { break; i++; } - assert(filesystem.DirClose(&dir) == 0); + res = filesystem.DirClose(&dir); + if (res != 0) { + NRF_LOG_INFO("[Gallery] DirClose failed"); + return; + } if (current != nullptr) { current.reset(nullptr); From 12b62faa62b19f868711f58614032f5139171ad7 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Sun, 12 Mar 2023 13:41:20 +0000 Subject: [PATCH 37/41] Disabled sliding animation This is really slow on the watch --- src/displayapp/screens/Gallery.cpp | 11 +++++------ src/displayapp/screens/Gallery.h | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/displayapp/screens/Gallery.cpp b/src/displayapp/screens/Gallery.cpp index fb84bf0f77..78e122357f 100644 --- a/src/displayapp/screens/Gallery.cpp +++ b/src/displayapp/screens/Gallery.cpp @@ -13,7 +13,7 @@ Gallery::Gallery(DisplayApp* app, Pinetime::Controllers::FS& filesystem) : Scree lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); lv_obj_align(title, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); } else { - Open(0, DisplayApp::FullRefreshDirections::None); + Open(0); } } @@ -24,9 +24,9 @@ Gallery::~Gallery() { bool Gallery::OnTouchEvent(Pinetime::Applications::TouchEvents event) { switch (event) { case Pinetime::Applications::TouchEvents::SwipeRight: - return Open(index - 1, DisplayApp::FullRefreshDirections::Right); + return Open(index - 1); case Pinetime::Applications::TouchEvents::SwipeLeft: - return Open(index + 1, DisplayApp::FullRefreshDirections::Left); + return Open(index + 1); case Pinetime::Applications::TouchEvents::LongTap: case Pinetime::Applications::TouchEvents::DoubleTap: current->ToggleInfo(); @@ -57,7 +57,7 @@ void Gallery::ListDir() { } } -bool Gallery::Open(int n, DisplayApp::FullRefreshDirections direction) { +bool Gallery::Open(int n) { if ((n < 0) || (n >= nScreens)) return false; @@ -82,12 +82,11 @@ bool Gallery::Open(int n, DisplayApp::FullRefreshDirections direction) { res = filesystem.DirClose(&dir); if (res != 0) { NRF_LOG_INFO("[Gallery] DirClose failed"); - return; + return false; } if (current != nullptr) { current.reset(nullptr); - app->SetFullRefresh(direction); } char fullname[LFS_NAME_MAX] = "F:"; diff --git a/src/displayapp/screens/Gallery.h b/src/displayapp/screens/Gallery.h index 888b0736cd..d11a269c5f 100644 --- a/src/displayapp/screens/Gallery.h +++ b/src/displayapp/screens/Gallery.h @@ -23,7 +23,7 @@ namespace Pinetime { std::unique_ptr current; void ListDir(); - bool Open(int n, DisplayApp::FullRefreshDirections direction); + bool Open(int n); int nScreens; int index; }; From fb0e2062a3f3d9ccd5f960ac6b6c33d6d72ad4a7 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Sun, 12 Mar 2023 13:41:55 +0000 Subject: [PATCH 38/41] Stop passing app around Following 7c7a860 --- src/displayapp/screens/FileView.cpp | 10 +++++----- src/displayapp/screens/FileView.h | 6 +++--- src/displayapp/screens/Gallery.cpp | 6 +++--- src/displayapp/screens/Gallery.h | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/displayapp/screens/FileView.cpp b/src/displayapp/screens/FileView.cpp index 59d674c3ef..e9167b2d0d 100644 --- a/src/displayapp/screens/FileView.cpp +++ b/src/displayapp/screens/FileView.cpp @@ -5,8 +5,8 @@ using namespace Pinetime::Applications::Screens; -FileView::FileView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char* path) - : screenID(screenID), nScreens(nScreens), Screen(app), pageIndicator(screenID, nScreens) { +FileView::FileView(uint8_t screenID, uint8_t nScreens, const char* path) + : screenID(screenID), nScreens(nScreens), Screen(), pageIndicator(screenID, nScreens) { label = nullptr; const char* c = strrchr(path, '/') + 1; @@ -57,7 +57,7 @@ FileView::~FileView() { lv_obj_clean(lv_scr_act()); } -ImageView::ImageView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char* path) : FileView(screenID, nScreens, app, path) { +ImageView::ImageView(uint8_t screenID, uint8_t nScreens, const char* path) : FileView(screenID, nScreens, path) { lv_obj_t* image = lv_img_create(lv_scr_act(), nullptr); lv_img_set_src(image, path); lv_obj_align(image, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); @@ -65,8 +65,8 @@ ImageView::ImageView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const ShowInfo(); } -TextView::TextView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char* path, Pinetime::Controllers::FS& fs) - : FileView(screenID, nScreens, app, path) { +TextView::TextView(uint8_t screenID, uint8_t nScreens, const char* path, Pinetime::Controllers::FS& fs) + : FileView(screenID, nScreens, path) { lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr); lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK); diff --git a/src/displayapp/screens/FileView.h b/src/displayapp/screens/FileView.h index e0051c13e9..5aa61b4f53 100644 --- a/src/displayapp/screens/FileView.h +++ b/src/displayapp/screens/FileView.h @@ -10,7 +10,7 @@ namespace Pinetime { namespace Screens { class FileView : public Screen { public: - FileView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char* path); + FileView(uint8_t screenID, uint8_t nScreens, const char* path); ~FileView() override; void ShowInfo(); @@ -27,12 +27,12 @@ namespace Pinetime { class ImageView : public FileView { public: - ImageView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char* path); + ImageView(uint8_t screenID, uint8_t nScreens, const char* path); }; class TextView : public FileView { public: - TextView(uint8_t screenID, uint8_t nScreens, DisplayApp* app, const char* path, Pinetime::Controllers::FS& fs); + TextView(uint8_t screenID, uint8_t nScreens, const char* path, Pinetime::Controllers::FS& fs); ~TextView() override; private: diff --git a/src/displayapp/screens/Gallery.cpp b/src/displayapp/screens/Gallery.cpp index 78e122357f..8ce84eb56b 100644 --- a/src/displayapp/screens/Gallery.cpp +++ b/src/displayapp/screens/Gallery.cpp @@ -4,7 +4,7 @@ using namespace Pinetime::Applications::Screens; -Gallery::Gallery(DisplayApp* app, Pinetime::Controllers::FS& filesystem) : Screen(app), filesystem(filesystem) { +Gallery::Gallery(Pinetime::Controllers::FS& filesystem) : Screen(), filesystem(filesystem) { ListDir(); if (nScreens == 0) { @@ -94,9 +94,9 @@ bool Gallery::Open(int n) { strncat(fullname, info.name, sizeof(fullname) - strlen(directory) - 2 - 1); if (StringEndsWith(fullname, ".bin")) { - current = std::make_unique(n, nScreens, app, fullname); + current = std::make_unique(n, nScreens, fullname); } else if (StringEndsWith(fullname, ".txt")) { - current = std::make_unique(n, nScreens, app, fullname, filesystem); + current = std::make_unique(n, nScreens, fullname, filesystem); } else { return false; } diff --git a/src/displayapp/screens/Gallery.h b/src/displayapp/screens/Gallery.h index d11a269c5f..7632c6c2c2 100644 --- a/src/displayapp/screens/Gallery.h +++ b/src/displayapp/screens/Gallery.h @@ -12,7 +12,7 @@ namespace Pinetime { public: static constexpr const char* directory = "/gallery/"; - Gallery(DisplayApp* app, Pinetime::Controllers::FS& filesystem); + Gallery(Pinetime::Controllers::FS& filesystem); ~Gallery() override; bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; From a6ba3f9fcbbcaa9c62ca65e87d9e415cfdeb7967 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Sun, 12 Mar 2023 17:04:47 +0000 Subject: [PATCH 39/41] Fixed Werrors --- src/displayapp/screens/FileView.cpp | 2 +- src/displayapp/screens/Gallery.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/displayapp/screens/FileView.cpp b/src/displayapp/screens/FileView.cpp index e9167b2d0d..c6fbebcff4 100644 --- a/src/displayapp/screens/FileView.cpp +++ b/src/displayapp/screens/FileView.cpp @@ -6,7 +6,7 @@ using namespace Pinetime::Applications::Screens; FileView::FileView(uint8_t screenID, uint8_t nScreens, const char* path) - : screenID(screenID), nScreens(nScreens), Screen(), pageIndicator(screenID, nScreens) { + : Screen(), pageIndicator(screenID, nScreens), screenID(screenID), nScreens(nScreens) { label = nullptr; const char* c = strrchr(path, '/') + 1; diff --git a/src/displayapp/screens/Gallery.cpp b/src/displayapp/screens/Gallery.cpp index 8ce84eb56b..fe032640c7 100644 --- a/src/displayapp/screens/Gallery.cpp +++ b/src/displayapp/screens/Gallery.cpp @@ -31,6 +31,11 @@ bool Gallery::OnTouchEvent(Pinetime::Applications::TouchEvents event) { case Pinetime::Applications::TouchEvents::DoubleTap: current->ToggleInfo(); return true; + case Pinetime::Applications::TouchEvents::None: + case Pinetime::Applications::TouchEvents::Tap: + case Pinetime::Applications::TouchEvents::SwipeUp: + case Pinetime::Applications::TouchEvents::SwipeDown: + return false; } return false; } From 370ecdefc2d96d4e628901d6150c6dedf4146ad6 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Sat, 27 May 2023 21:50:37 +0100 Subject: [PATCH 40/41] Fixed format --- src/displayapp/screens/FileView.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/displayapp/screens/FileView.h b/src/displayapp/screens/FileView.h index 5aa61b4f53..51374605fb 100644 --- a/src/displayapp/screens/FileView.h +++ b/src/displayapp/screens/FileView.h @@ -36,7 +36,7 @@ namespace Pinetime { ~TextView() override; private: - char *buf; + char* buf; }; } } From 33411149ce5afec0e6dc235c3ab494dee1403eeb Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Thu, 25 Dec 2025 13:32:56 +0100 Subject: [PATCH 41/41] Defined app trait --- src/displayapp/apps/Apps.h.in | 1 + src/displayapp/screens/Gallery.h | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/displayapp/apps/Apps.h.in b/src/displayapp/apps/Apps.h.in index d440b598d1..ab38d84dda 100644 --- a/src/displayapp/apps/Apps.h.in +++ b/src/displayapp/apps/Apps.h.in @@ -30,6 +30,7 @@ namespace Pinetime { Steps, Dice, Weather, + Gallery, PassKey, QuickSettings, Settings, diff --git a/src/displayapp/screens/Gallery.h b/src/displayapp/screens/Gallery.h index 7632c6c2c2..44d94e0158 100644 --- a/src/displayapp/screens/Gallery.h +++ b/src/displayapp/screens/Gallery.h @@ -4,6 +4,7 @@ #include "displayapp/screens/FileView.h" #include "displayapp/DisplayApp.h" #include +#include "Symbols.h" namespace Pinetime { namespace Applications { @@ -28,5 +29,19 @@ namespace Pinetime { int index; }; } + + template <> + struct AppTraits { + static constexpr Apps app = Apps::Gallery; + static constexpr const char* icon = Screens::Symbols::gallery; + + static Screens::Screen* Create(AppControllers& controllers) { + return new Screens::Gallery(controllers.filesystem); + }; + + static bool IsAvailable(Pinetime::Controllers::FS& filesystem) { + return true; + }; + }; } }