diff --git a/lib/3rd_party_adapters/LVGL/GuiEngine.cpp b/lib/3rd_party_adapters/LVGL/GuiEngine.cpp index da246d2b7..b036f652e 100644 --- a/lib/3rd_party_adapters/LVGL/GuiEngine.cpp +++ b/lib/3rd_party_adapters/LVGL/GuiEngine.cpp @@ -200,6 +200,7 @@ void GuiEngine::registerKeyPad(IKeypad *keypad) */ void GuiEngine::refresh() { + CurrentScreen->draw(); lv_timer_handler(); LV_LOG_TRACE("Adafruit display() start"); this->display.display(); diff --git a/lib/3rd_party_adapters/LVGL/Screen.cpp b/lib/3rd_party_adapters/LVGL/Screen.cpp index ef2abd534..b980d71e7 100644 --- a/lib/3rd_party_adapters/LVGL/Screen.cpp +++ b/lib/3rd_party_adapters/LVGL/Screen.cpp @@ -1,6 +1,7 @@ #include "Screen.hpp" #include #include +#include std::shared_ptr CurrentScreen; static std::stack> screenHistory; @@ -135,6 +136,27 @@ ScreenMenu::ScreenMenu(MenuItemList itemList) { } +static lv_style_t style_small_padding; + +static void drawTaskList(lv_obj_t &screen) +{ + lv_obj_t *table = lv_table_create(&screen); + + uint16_t row = 0; + for (auto task_item : device::tasks) + { + lv_table_set_cell_value(table, row, 0, task_item.second.getLabel().c_str()); + const auto time_label = std::to_string(task_item.second.getRecordedDuration().count()) + "s"; + lv_table_set_cell_value(table, row, 1, time_label.c_str()); + row++; + } + + lv_table_set_col_width(table, 0, 86); + lv_table_set_col_width(table, 1, 42); + + lv_obj_add_style(table, &style_small_padding, 0); +} + /** * @brief Translates the list of item types into actual lvgl draw directives. */ @@ -144,15 +166,19 @@ void ScreenMenu::draw() lv_obj_clean(lv_scr_act()); /* adjust the style so everything has a 1 px padding in all directions */ - static lv_style_t style_small_padding; - lv_style_init(&style_small_padding); + static bool initialized = false; + if (!initialized) + { + lv_style_init(&style_small_padding); + initialized = true; + } lv_style_set_pad_left(&style_small_padding, 1); lv_style_set_pad_top(&style_small_padding, 1); lv_style_set_pad_bottom(&style_small_padding, 1); lv_style_set_pad_right(&style_small_padding, 1); /* create the lvgl screen object and configure it's properties */ - lv_obj_t *screen = lv_obj_create(NULL); + static lv_obj_t *screen = lv_obj_create(NULL); lv_obj_add_style(screen, &style_small_padding, 0); lv_obj_set_flex_flow(screen, LV_FLEX_FLOW_COLUMN); lv_obj_set_style_pad_row(screen, 2, 0); @@ -252,6 +278,8 @@ void ScreenMenu::draw() } break; } + case MenuItemType::TASK: + drawTaskList(*screen); } } diff --git a/lib/3rd_party_adapters/LVGL/lv_conf.h b/lib/3rd_party_adapters/LVGL/lv_conf.h index 513ef357a..404d81ec9 100644 --- a/lib/3rd_party_adapters/LVGL/lv_conf.h +++ b/lib/3rd_party_adapters/LVGL/lv_conf.h @@ -509,7 +509,7 @@ #define LV_TEXTAREA_DEF_PWD_SHOW_TIME 1500 /*ms*/ #endif -#define LV_USE_TABLE 0 +#define LV_USE_TABLE 1 /*================== * EXTRA COMPONENTS diff --git a/lib/application_business_rules/user_interaction/Menu.cpp b/lib/application_business_rules/user_interaction/Menu.cpp index 454b7aae7..2afd9f93a 100644 --- a/lib/application_business_rules/user_interaction/Menu.cpp +++ b/lib/application_business_rules/user_interaction/Menu.cpp @@ -15,45 +15,11 @@ Menu::Menu(IGuiEngine &guiEngineToUse, IKeypad &keypad) /* initialize some lists for several menus */ static auto mainMenu = MenuItemList(); - static auto subMenu1 = MenuItemList(); - static auto subMenu2 = MenuItemList(); - static auto subMenu3 = MenuItemList(); /* define menu items for the main menu */ - static auto ListButton1 = MenuItemSubmenu{"ListButton1 Text", &subMenu1}; - static auto ListValue = MenuItemValue("ListValue", NULL, 2, 0.9, 1001.4); - static auto ListButton2 = MenuItemSubmenu{"ListButton2 Text", &subMenu2}; - static auto ListButton3 = MenuItemSubmenu{"ListButton3 Text", &subMenu3}; - static auto ListSwitch1 = MenuItemSwitch{"ListSwitch1 Text", NULL}; - static auto ListSwitch2 = MenuItemSwitch{"ListSwitch2 Text", NULL}; + static auto ListValue = MenuItemTask(); /* add menu items to main menu list */ - mainMenu.push_back(&ListButton1); mainMenu.push_back(&ListValue); - mainMenu.push_back(&ListButton2); - mainMenu.push_back(&ListSwitch1); - mainMenu.push_back(&ListSwitch2); - mainMenu.push_back(&ListButton3); - - /* define menu items for sub menu 1 */ - static auto Sub1Button1 = MenuItemSubmenu{"Sub1 Button1", &subMenu1}; - static auto Sub1Button2 = MenuItemSubmenu{"Sub1 Button2", &subMenu2}; - /* add menu items sub menu 1 list */ - subMenu1.push_back(&Sub1Button1); - subMenu1.push_back(&Sub1Button2); - - /* define menu items for sub menu 2 */ - static auto Sub2Button1 = MenuItemSubmenu{"Sub2 Button1", &subMenu1}; - static auto Sub2Button2 = MenuItemSubmenu{"Sub2 Button2", &subMenu2}; - /* add menu items sub menu 2 list */ - subMenu2.push_back(&Sub2Button1); - subMenu2.push_back(&Sub2Button2); - - /* define menu items for sub menu 3 */ - static auto Sub3Button1 = MenuItemSubmenu{"Sub3 Button1", &subMenu1}; - static auto Sub3Button2 = MenuItemSubmenu{"Sub3 Button2", &subMenu2}; - /* add menu items sub menu 3 list */ - subMenu3.push_back(&Sub3Button1); - subMenu3.push_back(&Sub3Button2); /* draw the main menu with GuiEngine */ guiEngine.drawMenu(&mainMenu); diff --git a/lib/application_business_rules/user_interaction/MenuItem.cpp b/lib/application_business_rules/user_interaction/MenuItem.cpp index c8434b211..bf3505e41 100644 --- a/lib/application_business_rules/user_interaction/MenuItem.cpp +++ b/lib/application_business_rules/user_interaction/MenuItem.cpp @@ -116,3 +116,17 @@ double MenuItemValue::getMax() const { return this->_max; } + +MenuItemTask::MenuItemTask() +{ +} + +MenuItemType MenuItemTask::getType() const +{ + return MenuItemType::TASK; +} + +std::string MenuItemTask::getText() const +{ + return {}; +} diff --git a/lib/application_business_rules/user_interaction/MenuItem.hpp b/lib/application_business_rules/user_interaction/MenuItem.hpp index c8e5ecf50..34a860bd7 100644 --- a/lib/application_business_rules/user_interaction/MenuItem.hpp +++ b/lib/application_business_rules/user_interaction/MenuItem.hpp @@ -1,6 +1,7 @@ #pragma once #include #include +#include #include /** @@ -12,6 +13,7 @@ enum class MenuItemType SUBMENU, SWITCH, VALUE, + TASK, }; /** @@ -109,3 +111,11 @@ struct MenuItemValue final : public IMenuItem double _min; double _max; }; + +class MenuItemTask : public IMenuItem +{ + public: + MenuItemTask(); + MenuItemType getType() const override; + std::string getText() const override; +}; diff --git a/src/main.cpp b/src/main.cpp index 8f0f98480..7ab096f8e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,13 +34,6 @@ void loop() serial_port::readAndHandleInput(); - for (auto task : device::tasks) - { - serial_port::cout << task.second.getLabel() << " : " << std::boolalpha << task.second.isRunning() - << std::noboolalpha << " with " << task.second.getRecordedDuration().count() << " s" << std::endl; - } - serial_port::cout << "_\r" << std::endl; - std::this_thread::yield(); using namespace std::chrono_literals; std::this_thread::sleep_for(100ms);