From 862dd7a5b92728ac362f7e9fea8e348b6902f665 Mon Sep 17 00:00:00 2001 From: Florian Kraupa Date: Thu, 27 May 2021 15:23:46 +0200 Subject: [PATCH 1/5] refactored the List used for settings into a more generic List that can be used by other apps and a specific SettingsList --- src/CMakeLists.txt | 1 + src/displayapp/screens/List.cpp | 109 +++++++----------- src/displayapp/screens/List.h | 40 +++---- src/displayapp/screens/ScreenList.h | 4 +- src/displayapp/screens/settings/Settings.cpp | 26 ++--- .../screens/settings/SettingsList.cpp | 47 ++++++++ .../screens/settings/SettingsList.h | 38 ++++++ 7 files changed, 159 insertions(+), 106 deletions(-) create mode 100644 src/displayapp/screens/settings/SettingsList.cpp create mode 100644 src/displayapp/screens/settings/SettingsList.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7ccd4ce77f..8234501af0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -404,6 +404,7 @@ list(APPEND SOURCE_FILES displayapp/screens/HeartRate.cpp displayapp/screens/Motion.cpp displayapp/screens/FlashLight.cpp + displayapp/screens/settings/SettingsList.cpp displayapp/screens/List.cpp displayapp/screens/BatteryInfo.cpp displayapp/screens/Steps.cpp diff --git a/src/displayapp/screens/List.cpp b/src/displayapp/screens/List.cpp index b4f4d2cfff..95fcd37db2 100644 --- a/src/displayapp/screens/List.cpp +++ b/src/displayapp/screens/List.cpp @@ -1,6 +1,6 @@ + + #include "List.h" -#include "../DisplayApp.h" -#include "Symbols.h" using namespace Pinetime::Applications::Screens; @@ -9,88 +9,56 @@ namespace { List* screen = static_cast(obj->user_data); screen->OnButtonEvent(obj, event); } - + } -List::List(uint8_t screenID, - uint8_t numScreens, - DisplayApp* app, - Controllers::Settings& settingsController, - std::array& applications) - : Screen(app), settingsController {settingsController} { - +List::List(Pinetime::Applications::DisplayApp* app, uint8_t screenID, uint8_t numScreens, std::array& +items) + : Screen(app) { // Set the background to Black lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_make(0, 0, 0)); - - settingsController.SetSettingsMenu(screenID); - + //draw scroll bar if List has more than one Page if (numScreens > 1) { pageIndicatorBasePoints[0].x = 240 - 1; pageIndicatorBasePoints[0].y = 6; pageIndicatorBasePoints[1].x = 240 - 1; pageIndicatorBasePoints[1].y = 240 - 6; - + pageIndicatorBase = lv_line_create(lv_scr_act(), NULL); 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, lv_color_hex(0x111111)); lv_obj_set_style_local_line_rounded(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, true); lv_line_set_points(pageIndicatorBase, pageIndicatorBasePoints, 2); - + uint16_t indicatorSize = 228 / numScreens; uint16_t indicatorPos = indicatorSize * screenID; - + pageIndicatorPoints[0].x = 240 - 1; pageIndicatorPoints[0].y = 6 + indicatorPos; pageIndicatorPoints[1].x = 240 - 1; pageIndicatorPoints[1].y = 6 + indicatorPos + indicatorSize; - + pageIndicator = lv_line_create(lv_scr_act(), NULL); 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, LV_COLOR_GRAY); lv_obj_set_style_local_line_rounded(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, true); lv_line_set_points(pageIndicator, pageIndicatorPoints, 2); } - - lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr); - + + //container for the buttons that will be created by createButtonNr + container1 = lv_cont_create(lv_scr_act(), nullptr); + // lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); - + lv_obj_set_pos(container1, 0, 0); lv_obj_set_width(container1, LV_HOR_RES - 15); lv_obj_set_height(container1, LV_VER_RES); lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); - - lv_obj_t* labelBt; - lv_obj_t* labelBtIco; - - for (int i = 0; i < MAXLISTITEMS; i++) { - apps[i] = applications[i].application; - if (applications[i].application != Apps::None) { - - itemApps[i] = lv_btn_create(container1, nullptr); - lv_obj_set_style_local_bg_opa(itemApps[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_20); - lv_obj_set_style_local_radius(itemApps[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 20); - lv_obj_set_style_local_bg_color(itemApps[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_AQUA); - - lv_obj_set_width(itemApps[i], LV_HOR_RES - 25); - lv_obj_set_height(itemApps[i], 52); - lv_obj_set_event_cb(itemApps[i], ButtonEventHandler); - lv_btn_set_layout(itemApps[i], LV_LAYOUT_ROW_MID); - itemApps[i]->user_data = this; - - labelBtIco = lv_label_create(itemApps[i], nullptr); - lv_obj_set_style_local_text_color(labelBtIco, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW); - lv_label_set_text_static(labelBtIco, applications[i].icon); - - labelBt = lv_label_create(itemApps[i], nullptr); - lv_label_set_text_fmt(labelBt, " %s", applications[i].name); - } - } - + lv_obj_t* backgroundLabel = lv_label_create(lv_scr_act(), nullptr); lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP); lv_obj_set_size(backgroundLabel, LV_HOR_RES, LV_VER_RES); @@ -98,23 +66,28 @@ List::List(uint8_t screenID, lv_label_set_text_static(backgroundLabel, ""); } -List::~List() { - lv_obj_clean(lv_scr_act()); -} - -bool List::Refresh() { - - return running; -} - -void List::OnButtonEvent(lv_obj_t* object, lv_event_t event) { - if (event == LV_EVENT_RELEASED) { - for (int i = 0; i < MAXLISTITEMS; i++) { - if (apps[i] != Apps::None && object == itemApps[i]) { - app->StartApp(apps[i], DisplayApp::FullRefreshDirections::Up); - running = false; - return; - } - } - } +//Derived Classes shall call this in their constructor to create the buttons +void List::createButtonNr(int i, std::array& +items) { + + lv_obj_t* labelBt; + lv_obj_t* labelBtIco; + + buttons[i] = lv_btn_create(container1, nullptr); + lv_obj_set_style_local_bg_opa(buttons[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_20); + lv_obj_set_style_local_radius(buttons[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 20); + lv_obj_set_style_local_bg_color(buttons[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_AQUA); + + lv_obj_set_width(buttons[i], LV_HOR_RES - 25); + lv_obj_set_height(buttons[i], 52); + lv_obj_set_event_cb(buttons[i], ButtonEventHandler); + lv_btn_set_layout(buttons[i], LV_LAYOUT_ROW_MID); + buttons[i]->user_data = this; + + labelBtIco = lv_label_create(buttons[i], nullptr); + lv_obj_set_style_local_text_color(labelBtIco, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW); + lv_label_set_text_static(labelBtIco, items[i].icon); + + labelBt = lv_label_create(buttons[i], nullptr); + lv_label_set_text_fmt(labelBt, " %s", items[i].name); } diff --git a/src/displayapp/screens/List.h b/src/displayapp/screens/List.h index a45fd1d3c9..d08d85dd5a 100644 --- a/src/displayapp/screens/List.h +++ b/src/displayapp/screens/List.h @@ -1,11 +1,8 @@ #pragma once #include -#include -#include +#include #include "Screen.h" -#include "../Apps.h" -#include "components/settings/Settings.h" #define MAXLISTITEMS 4 @@ -14,29 +11,26 @@ namespace Pinetime { namespace Screens { class List : public Screen { public: - struct Applications { + struct Item { const char* icon; const char* name; - Pinetime::Applications::Apps application; + void* data; }; - - explicit List(uint8_t screenID, - uint8_t numScreens, - DisplayApp* app, - Controllers::Settings& settingsController, - std::array& applications); - ~List() override; - - bool Refresh() override; - - void OnButtonEvent(lv_obj_t* object, lv_event_t event); - + + virtual void OnButtonEvent(lv_obj_t* object, lv_event_t event) = 0; + + protected: + explicit List(Pinetime::Applications::DisplayApp* app, uint8_t screenID, uint8_t numScreens, std::array& + items); + + lv_obj_t* buttons[MAXLISTITEMS]; + lv_obj_t* container1; + + void createButtonNr(int i, std::array& + items); + private: - Controllers::Settings& settingsController; - Pinetime::Applications::Apps apps[MAXLISTITEMS]; - - lv_obj_t* itemApps[MAXLISTITEMS]; - + lv_point_t pageIndicatorBasePoints[2]; lv_point_t pageIndicatorPoints[2]; lv_obj_t* pageIndicatorBase; diff --git a/src/displayapp/screens/ScreenList.h b/src/displayapp/screens/ScreenList.h index 73ea461010..a2db1ca09c 100644 --- a/src/displayapp/screens/ScreenList.h +++ b/src/displayapp/screens/ScreenList.h @@ -3,8 +3,8 @@ #include #include #include -#include "Screen.h" -#include "../DisplayApp.h" +#include "displayapp/screens/Screen.h" +#include "displayapp/DisplayApp.h" namespace Pinetime { namespace Applications { diff --git a/src/displayapp/screens/settings/Settings.cpp b/src/displayapp/screens/settings/Settings.cpp index 2c72c832ca..80cd7a11bc 100644 --- a/src/displayapp/screens/settings/Settings.cpp +++ b/src/displayapp/screens/settings/Settings.cpp @@ -1,7 +1,7 @@ #include "Settings.h" #include #include -#include "displayapp/screens/List.h" +#include "SettingsList.h" #include "displayapp/Apps.h" #include "displayapp/DisplayApp.h" #include "displayapp/screens/Symbols.h" @@ -39,24 +39,24 @@ bool Settings::OnTouchEvent(Pinetime::Applications::TouchEvents event) { std::unique_ptr Settings::CreateScreen1() { - std::array applications {{ - {Symbols::sun, "Display", Apps::SettingDisplay}, - {Symbols::clock, "Wake Up", Apps::SettingWakeUp}, - {Symbols::clock, "Time format", Apps::SettingTimeFormat}, - {Symbols::clock, "Watch face", Apps::SettingWatchFace}, + std::array applications {{ + {Symbols::sun, "Display", static_cast(new Apps(Apps::SettingDisplay))}, + {Symbols::clock, "Wake Up", static_cast(new Apps(Apps::SettingWakeUp))}, + {Symbols::clock, "Time format", static_cast(new Apps(Apps::SettingTimeFormat))}, + {Symbols::clock, "Watch face",static_cast(new Apps(Apps::SettingWatchFace))}, }}; - return std::unique_ptr(new Screens::List(0, 2, app, settingsController, applications)); + return std::unique_ptr(new Screens::SettingsList(0, 2, app, settingsController, applications)); } std::unique_ptr Settings::CreateScreen2() { - std::array applications {{ - {Symbols::shoe, "Steps", Apps::SettingSteps}, - {Symbols::batteryHalf, "Battery", Apps::BatteryInfo}, - {Symbols::check, "Firmware", Apps::FirmwareValidation}, - {Symbols::list, "About", Apps::SysInfo}, + std::array applications {{ + {Symbols::shoe, "Steps", static_cast(new Apps(Apps::SettingSteps))}, + {Symbols::batteryHalf, "Battery", static_cast(new Apps(Apps::BatteryInfo))}, + {Symbols::check, "Firmware", static_cast(new Apps(Apps::FirmwareValidation))}, + {Symbols::list, "About", static_cast(new Apps(Apps::SysInfo))}, }}; - return std::unique_ptr(new Screens::List(1, 2, app, settingsController, applications)); + return std::unique_ptr(new Screens::SettingsList(1, 2, app, settingsController, applications)); } diff --git a/src/displayapp/screens/settings/SettingsList.cpp b/src/displayapp/screens/settings/SettingsList.cpp new file mode 100644 index 0000000000..dfd91b44ce --- /dev/null +++ b/src/displayapp/screens/settings/SettingsList.cpp @@ -0,0 +1,47 @@ +#include "SettingsList.h" +#include "displayapp/DisplayApp.h" +#include "displayapp/screens/Symbols.h" + +using namespace Pinetime::Applications::Screens; + + +SettingsList::SettingsList(uint8_t screenID, + uint8_t numScreens, + DisplayApp* app, + Controllers::Settings& settingsController, + std::array& applications) + : List(app, screenID, numScreens, applications), settingsController{settingsController} { + + settingsController.SetSettingsMenu(screenID); + + + for (int i = 0; i < MAXLISTITEMS; i++) { + apps[i] = *static_cast(applications[i].data); + //only create buttons for applications that exist + if (apps[i] != Apps::None) { + createButtonNr(i, applications); + } + } + +} + +SettingsList::~SettingsList() { + lv_obj_clean(lv_scr_act()); +} + +bool SettingsList::Refresh() { + + return running; +} + +void SettingsList::OnButtonEvent(lv_obj_t* object, lv_event_t event) { + if (event == LV_EVENT_RELEASED) { + for (int i = 0; i < MAXLISTITEMS; i++) { + if (apps[i] != Apps::None && object == buttons[i]) { + app->StartApp(apps[i], DisplayApp::FullRefreshDirections::Up); + running = false; + return; + } + } + } +} diff --git a/src/displayapp/screens/settings/SettingsList.h b/src/displayapp/screens/settings/SettingsList.h new file mode 100644 index 0000000000..a216b457d6 --- /dev/null +++ b/src/displayapp/screens/settings/SettingsList.h @@ -0,0 +1,38 @@ +#pragma once + +#include +#include +#include +#include "displayapp/screens/List.h" +#include "displayapp/Apps.h" +#include "components/settings/Settings.h" + + +namespace Pinetime { + namespace Applications { + namespace Screens { + class SettingsList : public List { + public: + + + explicit SettingsList(uint8_t screenID, + uint8_t numScreens, + DisplayApp* app, + Controllers::Settings& settingsController, + std::array& applications); + + ~SettingsList() override; + + bool Refresh() override; + + void OnButtonEvent(lv_obj_t* object, lv_event_t event); + + private: + Controllers::Settings& settingsController; + Pinetime::Applications::Apps apps[MAXLISTITEMS]; + + + }; + } + } +} From c5f1f101fa1c950eb816d413ab9c56bd03f46487 Mon Sep 17 00:00:00 2001 From: Florian Kraupa Date: Thu, 27 May 2021 17:35:26 +0200 Subject: [PATCH 2/5] added timer setting by swipes and prepared presets. persistence of set timer values is a nice side effect --- src/components/timer/TimerController.cpp | 18 +++- src/components/timer/TimerController.h | 22 ++++- src/displayapp/DisplayApp.cpp | 2 +- src/displayapp/screens/{ => Timer}/Timer.cpp | 94 ++++++++++++++------ src/displayapp/screens/{ => Timer}/Timer.h | 11 +-- 5 files changed, 111 insertions(+), 36 deletions(-) rename src/displayapp/screens/{ => Timer}/Timer.cpp (62%) rename src/displayapp/screens/{ => Timer}/Timer.h (82%) diff --git a/src/components/timer/TimerController.cpp b/src/components/timer/TimerController.cpp index 3b25901c7e..31c0b5da4b 100644 --- a/src/components/timer/TimerController.cpp +++ b/src/components/timer/TimerController.cpp @@ -61,4 +61,20 @@ void TimerController::StopTimer() { bool TimerController::IsRunning() { return timerRunning; -} \ No newline at end of file +} + +void TimerController::selectPreset(int8_t i) { + initialValue = presets[i]; +} + +void TimerController::setPreset(int8_t i) { + presets[i] = initialValue; +} + +TimerController::TimerValue* TimerController::getInitialValue(){ + return &initialValue; +} + +const TimerController::TimerValue& TimerController::getPreset(uint8_t i) const { + return presets[i]; +} diff --git a/src/components/timer/TimerController.h b/src/components/timer/TimerController.h index 5a0b293ee5..d20739d2d8 100644 --- a/src/components/timer/TimerController.h +++ b/src/components/timer/TimerController.h @@ -12,6 +12,11 @@ namespace Pinetime { class TimerController { public: + struct TimerValue { + uint8_t minutes; + uint8_t seconds; + }; + TimerController(Pinetime::System::SystemTask& systemTask); void Init(); @@ -23,8 +28,23 @@ namespace Pinetime { uint32_t GetTimeRemaining(); bool IsRunning(); - + + void selectPreset(int8_t i); + void setPreset(int8_t i); + + TimerValue* getInitialValue(); + const TimerValue& getPreset(uint8_t i) const; + private: + + TimerValue presets[3] = { + {15, 00}, + {30, 00}, + {00, 30} + }; + + TimerValue initialValue = {00, 00}; + System::SystemTask& systemTask; static void timerEnd(void* p_context); diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 419b9f6fd2..f9c0aff3a2 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include "components/battery/BatteryController.h" #include "components/ble/BleController.h" #include "components/datetime/DateTimeController.h" diff --git a/src/displayapp/screens/Timer.cpp b/src/displayapp/screens/Timer/Timer.cpp similarity index 62% rename from src/displayapp/screens/Timer.cpp rename to src/displayapp/screens/Timer/Timer.cpp index 260a17ef00..5e06d0ef0e 100644 --- a/src/displayapp/screens/Timer.cpp +++ b/src/displayapp/screens/Timer/Timer.cpp @@ -1,7 +1,7 @@ #include "Timer.h" -#include "Screen.h" -#include "Symbols.h" +#include "displayapp/screens/Screen.h" +#include "displayapp/screens/Symbols.h" #include "lvgl/lvgl.h" @@ -56,14 +56,14 @@ void Timer::createButtons() { Timer::Timer(DisplayApp* app, Controllers::TimerController& timerController) : Screen(app), running{true}, - timerController{timerController} { + timerController{timerController}, valueToSet{timerController.getInitialValue()} { + time = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76); lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); - uint32_t seconds = timerController.GetTimeRemaining() / 1000; - lv_label_set_text_fmt(time, "%02d:%02d", seconds / 60, seconds % 60); + lv_obj_align(time, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, -20); @@ -74,8 +74,11 @@ Timer::Timer(DisplayApp* app, Controllers::TimerController& timerController) lv_obj_set_height(btnPlayPause, 40); txtPlayPause = lv_label_create(btnPlayPause, nullptr); if (timerController.IsRunning()) { + uint32_t seconds = timerController.GetTimeRemaining() / 1000; + lv_label_set_text_fmt(time, "%02d:%02d", seconds / 60, seconds % 60); lv_label_set_text(txtPlayPause, Symbols::pause); } else { + lv_label_set_text_fmt(time, "%02d:%02d", valueToSet->minutes, valueToSet->seconds); lv_label_set_text(txtPlayPause, Symbols::play); createButtons(); } @@ -101,14 +104,14 @@ void Timer::OnButtonEvent(lv_obj_t* obj, lv_event_t event) { if (timerController.IsRunning()) { lv_label_set_text(txtPlayPause, Symbols::play); uint32_t seconds = timerController.GetTimeRemaining() / 1000; - minutesToSet = seconds / 60; - secondsToSet = seconds % 60; + valueToSet->minutes = seconds / 60; + valueToSet->seconds = seconds % 60; timerController.StopTimer(); createButtons(); - } else if (secondsToSet + minutesToSet > 0) { + } else if (valueToSet->seconds + valueToSet->minutes > 0) { lv_label_set_text(txtPlayPause, Symbols::pause); - timerController.StartTimer((secondsToSet + minutesToSet * 60) * 1000); + timerController.StartTimer((valueToSet->seconds + valueToSet->minutes * 60) * 1000); lv_obj_del(btnSecondsDown); btnSecondsDown = nullptr; @@ -123,36 +126,36 @@ void Timer::OnButtonEvent(lv_obj_t* obj, lv_event_t event) { } else { if (!timerController.IsRunning()) { if (obj == btnMinutesUp) { - if (minutesToSet >= 59) { - minutesToSet = 0; + if (valueToSet->minutes >= 59) { + valueToSet->minutes = 0; } else { - minutesToSet++; + valueToSet->minutes++; } - lv_label_set_text_fmt(time, "%02d:%02d", minutesToSet, secondsToSet); + lv_label_set_text_fmt(time, "%02d:%02d", valueToSet->minutes, valueToSet->seconds); } else if (obj == btnMinutesDown) { - if (minutesToSet == 0) { - minutesToSet = 59; + if (valueToSet->minutes == 0) { + valueToSet->minutes = 59; } else { - minutesToSet--; + valueToSet->minutes--; } - lv_label_set_text_fmt(time, "%02d:%02d", minutesToSet, secondsToSet); + lv_label_set_text_fmt(time, "%02d:%02d", valueToSet->minutes, valueToSet->seconds); } else if (obj == btnSecondsUp) { - if (secondsToSet >= 59) { - secondsToSet = 0; + if (valueToSet->seconds >= 59) { + valueToSet->seconds = 0; } else { - secondsToSet++; + valueToSet->seconds++; } - lv_label_set_text_fmt(time, "%02d:%02d", minutesToSet, secondsToSet); + lv_label_set_text_fmt(time, "%02d:%02d", valueToSet->minutes, valueToSet->seconds); } else if (obj == btnSecondsDown) { - if (secondsToSet == 0) { - secondsToSet = 59; + if (valueToSet->seconds == 0) { + valueToSet->seconds = 59; } else { - secondsToSet--; + valueToSet->seconds--; } - lv_label_set_text_fmt(time, "%02d:%02d", minutesToSet, secondsToSet); + lv_label_set_text_fmt(time, "%02d:%02d", valueToSet->minutes, valueToSet->seconds); } } @@ -163,11 +166,46 @@ void Timer::OnButtonEvent(lv_obj_t* obj, lv_event_t event) { } +bool Timer::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + //dont react to swipes while running + if (timerController.IsRunning()) { + return false; + } + if (event == TouchEvents::SwipeUp) { + if (valueToSet->seconds < 50) { + valueToSet->seconds += 10; + } else if (valueToSet->minutes < 59) { + valueToSet->minutes++; + valueToSet->seconds = valueToSet->seconds - 60 + 10; + } else { + valueToSet->minutes = 0; + valueToSet->seconds = valueToSet->seconds - 60 + 10; + } + lv_label_set_text_fmt(time, "%02d:%02d", valueToSet->minutes, valueToSet->seconds); + return true; + } + if (event == TouchEvents::SwipeDown) { + if (valueToSet->seconds >= 10) { + valueToSet->seconds -= 10; + } else if (valueToSet->minutes > 0){ + valueToSet->seconds = 60 + valueToSet->seconds - 10; + valueToSet->minutes--; + } else { + valueToSet->minutes = 59; + valueToSet->seconds = 60 + valueToSet->seconds - 10; + } + lv_label_set_text_fmt(time, "%02d:%02d", valueToSet->minutes, valueToSet->seconds); + return true; + } + return false; +} void Timer::setDone() { lv_label_set_text(time, "00:00"); lv_label_set_text(txtPlayPause, Symbols::play); - secondsToSet = 0; - minutesToSet = 0; + valueToSet->seconds = 0; + valueToSet->minutes = 0; createButtons(); -} \ No newline at end of file +} + + diff --git a/src/displayapp/screens/Timer.h b/src/displayapp/screens/Timer/Timer.h similarity index 82% rename from src/displayapp/screens/Timer.h rename to src/displayapp/screens/Timer/Timer.h index 0d66f2d46e..b2789723cd 100644 --- a/src/displayapp/screens/Timer.h +++ b/src/displayapp/screens/Timer/Timer.h @@ -1,9 +1,9 @@ #pragma once -#include "Screen.h" +#include "displayapp/screens/Screen.h" #include "components/datetime/DateTimeController.h" #include "systemtask/SystemTask.h" -#include "../LittleVgl.h" +#include "displayapp/LittleVgl.h" #include "components/timer/TimerController.h" @@ -27,11 +27,12 @@ namespace Pinetime::Applications::Screens { void OnButtonEvent(lv_obj_t* obj, lv_event_t event); + bool OnTouchEvent(TouchEvents event); + private: - + + Controllers::TimerController::TimerValue* valueToSet; bool running; - uint8_t secondsToSet = 0; - uint8_t minutesToSet = 0; Controllers::TimerController& timerController; void createButtons(); From 516504e24d1514af5648b29339e742e3c478dd8c Mon Sep 17 00:00:00 2001 From: Florian Kraupa Date: Thu, 27 May 2021 18:58:06 +0200 Subject: [PATCH 3/5] Timer Presets --- src/CMakeLists.txt | 6 +- src/displayapp/Apps.h | 1 + src/displayapp/DisplayApp.cpp | 4 + src/displayapp/screens/List.cpp | 10 +- src/displayapp/screens/List.h | 6 +- src/displayapp/screens/Timer/Timer.cpp | 4 + src/displayapp/screens/Timer/TimerList.cpp | 91 +++++++++++++++++++ src/displayapp/screens/Timer/TimerList.h | 39 ++++++++ .../screens/settings/SettingsList.cpp | 4 +- 9 files changed, 151 insertions(+), 14 deletions(-) create mode 100644 src/displayapp/screens/Timer/TimerList.cpp create mode 100644 src/displayapp/screens/Timer/TimerList.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8234501af0..69e2d94efc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -408,7 +408,8 @@ list(APPEND SOURCE_FILES displayapp/screens/List.cpp displayapp/screens/BatteryInfo.cpp displayapp/screens/Steps.cpp - displayapp/screens/Timer.cpp + displayapp/screens/Timer/Timer.cpp + displayapp/screens/Timer/TimerList.cpp ## Settings displayapp/screens/settings/QuickSettings.cpp @@ -594,7 +595,8 @@ set(INCLUDE_FILES displayapp/screens/Notifications.h displayapp/screens/HeartRate.h displayapp/screens/Motion.h - displayapp/screens/Timer.h + displayapp/screens/Timer/Timer.h + displayapp/screens/Timer/TimerList.h drivers/St7789.h drivers/SpiNorFlash.h drivers/SpiMaster.h diff --git a/src/displayapp/Apps.h b/src/displayapp/Apps.h index 2df517f89d..0f72b2c8f1 100644 --- a/src/displayapp/Apps.h +++ b/src/displayapp/Apps.h @@ -12,6 +12,7 @@ namespace Pinetime { NotificationsPreview, Notifications, Timer, + TimerTemplates, FlashLight, BatteryInfo, Music, diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index f9c0aff3a2..8edb730ca4 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "components/battery/BatteryController.h" #include "components/ble/BleController.h" #include "components/datetime/DateTimeController.h" @@ -278,6 +279,9 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) case Apps::Timer: currentScreen = std::make_unique(this, timerController); break; + case Apps::TimerTemplates: + currentScreen = std::make_unique( 0, 1, this,timerController); + break; // Settings case Apps::QuickSettings: diff --git a/src/displayapp/screens/List.cpp b/src/displayapp/screens/List.cpp index 95fcd37db2..290065ae7b 100644 --- a/src/displayapp/screens/List.cpp +++ b/src/displayapp/screens/List.cpp @@ -12,8 +12,7 @@ namespace { } -List::List(Pinetime::Applications::DisplayApp* app, uint8_t screenID, uint8_t numScreens, std::array& -items) +List::List(Pinetime::Applications::DisplayApp* app, uint8_t screenID, uint8_t numScreens) : Screen(app) { // Set the background to Black lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_make(0, 0, 0)); @@ -67,8 +66,7 @@ items) } //Derived Classes shall call this in their constructor to create the buttons -void List::createButtonNr(int i, std::array& -items) { +void List::createButtonNr(int i, Item& item) { lv_obj_t* labelBt; lv_obj_t* labelBtIco; @@ -86,8 +84,8 @@ items) { labelBtIco = lv_label_create(buttons[i], nullptr); lv_obj_set_style_local_text_color(labelBtIco, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW); - lv_label_set_text_static(labelBtIco, items[i].icon); + lv_label_set_text_static(labelBtIco, item.icon); labelBt = lv_label_create(buttons[i], nullptr); - lv_label_set_text_fmt(labelBt, " %s", items[i].name); + lv_label_set_text_fmt(labelBt, " %s", item.name); } diff --git a/src/displayapp/screens/List.h b/src/displayapp/screens/List.h index d08d85dd5a..664856d5dd 100644 --- a/src/displayapp/screens/List.h +++ b/src/displayapp/screens/List.h @@ -20,14 +20,12 @@ namespace Pinetime { virtual void OnButtonEvent(lv_obj_t* object, lv_event_t event) = 0; protected: - explicit List(Pinetime::Applications::DisplayApp* app, uint8_t screenID, uint8_t numScreens, std::array& - items); + explicit List(Pinetime::Applications::DisplayApp* app, uint8_t screenID, uint8_t numScreens); lv_obj_t* buttons[MAXLISTITEMS]; lv_obj_t* container1; - void createButtonNr(int i, std::array& - items); + void createButtonNr(int i, Item& item); private: diff --git a/src/displayapp/screens/Timer/Timer.cpp b/src/displayapp/screens/Timer/Timer.cpp index 5e06d0ef0e..3ec45b1d83 100644 --- a/src/displayapp/screens/Timer/Timer.cpp +++ b/src/displayapp/screens/Timer/Timer.cpp @@ -197,6 +197,10 @@ bool Timer::OnTouchEvent(Pinetime::Applications::TouchEvents event) { lv_label_set_text_fmt(time, "%02d:%02d", valueToSet->minutes, valueToSet->seconds); return true; } + if (event == TouchEvents::SwipeRight) { + running = false; + app->StartApp(Apps::TimerTemplates, DisplayApp::FullRefreshDirections::RightAnim); + } return false; } diff --git a/src/displayapp/screens/Timer/TimerList.cpp b/src/displayapp/screens/Timer/TimerList.cpp new file mode 100644 index 0000000000..a7dd9127d4 --- /dev/null +++ b/src/displayapp/screens/Timer/TimerList.cpp @@ -0,0 +1,91 @@ +#include "TimerList.h" + +using namespace Pinetime::Applications::Screens; + +TimerList::TimerList(uint8_t screenID, + uint8_t numScreens, + DisplayApp* app, + Controllers::TimerController& timerController) + : List(app, screenID, numScreens), timerController{timerController} { + + + char names[3][6]; + for (int i = 0; i < 3; i++) { + sprintf(names[i], "%02d:%02d", timerController.getPreset(i).minutes, timerController.getPreset(i).seconds); + } + std::array timerItems {{ + {"", "Set", nullptr}, + {"", names[0], nullptr}, + {"", names[1], nullptr}, + {"", names[2], nullptr}, + }}; + + for (int i = 0; i < MAXLISTITEMS; i++) { + timers[i] = *static_cast(timerItems[i].data); + createButtonNr(i, timerItems[i]); + } + lv_btn_set_checkable(buttons[0], true); + +} + +TimerList::~TimerList() { + lv_obj_clean(lv_scr_act()); +} + +bool TimerList::Refresh() { + + return running; +} + +void TimerList::OnButtonEvent(lv_obj_t* object, lv_event_t event) { + if (event == LV_EVENT_RELEASED) { + switch (currentMode) { + case Normal: + if (object == buttons[0]) { + + currentMode = Set; + return; + } + for (int i = 1; i < MAXLISTITEMS; i++) { + if (object == buttons[i]) { + //first button is "Set" + timerController.selectPreset(i -1); + app->StartApp(Apps::Timer, DisplayApp::FullRefreshDirections::LeftAnim); + running = false; + return; + } + } + break; + case Set: + if (object == buttons[0]) { + Item newItem = {"", "Set", nullptr}; + createButtonNr(0, newItem); + currentMode = Normal; + return; + } + for (int i = 1; i < MAXLISTITEMS; i++) { + if (object == buttons[i]) { + //first button is "Set" + timerController.setPreset(i - 1); + char newTxt[6]; + sprintf(newTxt, "%02d:%02d", timerController.getPreset(i).minutes, timerController.getPreset(i).seconds); + Item newItem = {"", newTxt, nullptr}; + createButtonNr(i, newItem); + app->StartApp(Apps::Timer, DisplayApp::FullRefreshDirections::LeftAnim); + running = false; + return; + } + } + } + + } +} + +bool TimerList::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + + if (event == TouchEvents::SwipeLeft) { + running = false; + app->StartApp(Apps::Timer, DisplayApp::FullRefreshDirections::LeftAnim); + } + return false; +} diff --git a/src/displayapp/screens/Timer/TimerList.h b/src/displayapp/screens/Timer/TimerList.h new file mode 100644 index 0000000000..9627495801 --- /dev/null +++ b/src/displayapp/screens/Timer/TimerList.h @@ -0,0 +1,39 @@ +#pragma once + +#include +#include +#include +#include "displayapp/screens/List.h" +#include "Timer.h" + + +namespace Pinetime { + namespace Applications { + namespace Screens { + class TimerList : public List { + enum Mode {Normal, Set}; + public: + + explicit TimerList(uint8_t screenID, + uint8_t numScreens, + DisplayApp* app, + Controllers::TimerController& timerController); + + ~TimerList() override; + + bool Refresh() override; + + void OnButtonEvent(lv_obj_t* object, lv_event_t event); + bool OnTouchEvent(Pinetime::Applications::TouchEvents event); + + private: + Mode currentMode = Normal; + Controllers::TimerController& timerController; + //leave space the set button + uint32_t timers[MAXLISTITEMS - 1]; + + + }; + } + } +} diff --git a/src/displayapp/screens/settings/SettingsList.cpp b/src/displayapp/screens/settings/SettingsList.cpp index dfd91b44ce..f9de9104ed 100644 --- a/src/displayapp/screens/settings/SettingsList.cpp +++ b/src/displayapp/screens/settings/SettingsList.cpp @@ -10,7 +10,7 @@ SettingsList::SettingsList(uint8_t screenID, DisplayApp* app, Controllers::Settings& settingsController, std::array& applications) - : List(app, screenID, numScreens, applications), settingsController{settingsController} { + : List(app, screenID, numScreens), settingsController{settingsController} { settingsController.SetSettingsMenu(screenID); @@ -19,7 +19,7 @@ SettingsList::SettingsList(uint8_t screenID, apps[i] = *static_cast(applications[i].data); //only create buttons for applications that exist if (apps[i] != Apps::None) { - createButtonNr(i, applications); + createButtonNr(i, applications[i]); } } From ab3295d4c823dae5e673fce0eb972903c4b8b90a Mon Sep 17 00:00:00 2001 From: Florian Kraupa Date: Thu, 27 May 2021 20:09:14 +0200 Subject: [PATCH 4/5] some style changes and removing unused stuff --- src/displayapp/screens/List.cpp | 2 -- src/displayapp/screens/Timer/Timer.cpp | 2 -- src/displayapp/screens/Timer/TimerList.cpp | 1 - src/displayapp/screens/Timer/TimerList.h | 2 -- src/displayapp/screens/settings/SettingsList.cpp | 1 - 5 files changed, 8 deletions(-) diff --git a/src/displayapp/screens/List.cpp b/src/displayapp/screens/List.cpp index 290065ae7b..170158ce64 100644 --- a/src/displayapp/screens/List.cpp +++ b/src/displayapp/screens/List.cpp @@ -1,5 +1,3 @@ - - #include "List.h" using namespace Pinetime::Applications::Screens; diff --git a/src/displayapp/screens/Timer/Timer.cpp b/src/displayapp/screens/Timer/Timer.cpp index 3ec45b1d83..3eb66005d4 100644 --- a/src/displayapp/screens/Timer/Timer.cpp +++ b/src/displayapp/screens/Timer/Timer.cpp @@ -211,5 +211,3 @@ void Timer::setDone() { valueToSet->minutes = 0; createButtons(); } - - diff --git a/src/displayapp/screens/Timer/TimerList.cpp b/src/displayapp/screens/Timer/TimerList.cpp index a7dd9127d4..a6ec462cd6 100644 --- a/src/displayapp/screens/Timer/TimerList.cpp +++ b/src/displayapp/screens/Timer/TimerList.cpp @@ -21,7 +21,6 @@ TimerList::TimerList(uint8_t screenID, }}; for (int i = 0; i < MAXLISTITEMS; i++) { - timers[i] = *static_cast(timerItems[i].data); createButtonNr(i, timerItems[i]); } lv_btn_set_checkable(buttons[0], true); diff --git a/src/displayapp/screens/Timer/TimerList.h b/src/displayapp/screens/Timer/TimerList.h index 9627495801..80c68cf44b 100644 --- a/src/displayapp/screens/Timer/TimerList.h +++ b/src/displayapp/screens/Timer/TimerList.h @@ -29,8 +29,6 @@ namespace Pinetime { private: Mode currentMode = Normal; Controllers::TimerController& timerController; - //leave space the set button - uint32_t timers[MAXLISTITEMS - 1]; }; diff --git a/src/displayapp/screens/settings/SettingsList.cpp b/src/displayapp/screens/settings/SettingsList.cpp index f9de9104ed..664a2bb504 100644 --- a/src/displayapp/screens/settings/SettingsList.cpp +++ b/src/displayapp/screens/settings/SettingsList.cpp @@ -1,6 +1,5 @@ #include "SettingsList.h" #include "displayapp/DisplayApp.h" -#include "displayapp/screens/Symbols.h" using namespace Pinetime::Applications::Screens; From 02990e9fff398a4948a477a489c3a90798db2e59 Mon Sep 17 00:00:00 2001 From: Florian Date: Tue, 8 Jun 2021 00:13:42 +0200 Subject: [PATCH 5/5] fix return to timer from timer list --- src/displayapp/screens/Timer/TimerList.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/displayapp/screens/Timer/TimerList.cpp b/src/displayapp/screens/Timer/TimerList.cpp index a6ec462cd6..fee8f0d188 100644 --- a/src/displayapp/screens/Timer/TimerList.cpp +++ b/src/displayapp/screens/Timer/TimerList.cpp @@ -50,7 +50,6 @@ void TimerList::OnButtonEvent(lv_obj_t* object, lv_event_t event) { //first button is "Set" timerController.selectPreset(i -1); app->StartApp(Apps::Timer, DisplayApp::FullRefreshDirections::LeftAnim); - running = false; return; } } @@ -71,7 +70,6 @@ void TimerList::OnButtonEvent(lv_obj_t* object, lv_event_t event) { Item newItem = {"", newTxt, nullptr}; createButtonNr(i, newItem); app->StartApp(Apps::Timer, DisplayApp::FullRefreshDirections::LeftAnim); - running = false; return; } } @@ -83,7 +81,6 @@ void TimerList::OnButtonEvent(lv_obj_t* object, lv_event_t event) { bool TimerList::OnTouchEvent(Pinetime::Applications::TouchEvents event) { if (event == TouchEvents::SwipeLeft) { - running = false; app->StartApp(Apps::Timer, DisplayApp::FullRefreshDirections::LeftAnim); } return false;