Skip to content

show basic task information on dispay #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/3rd_party_adapters/LVGL/GuiEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
34 changes: 31 additions & 3 deletions lib/3rd_party_adapters/LVGL/Screen.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Screen.hpp"
#include <math.h>
#include <stack>
#include <string>

std::shared_ptr<IScreen> CurrentScreen;
static std::stack<std::shared_ptr<IScreen>> screenHistory;
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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);
Expand Down Expand Up @@ -252,6 +278,8 @@ void ScreenMenu::draw()
}
break;
}
case MenuItemType::TASK:
drawTaskList(*screen);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/3rd_party_adapters/LVGL/lv_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 1 addition & 35 deletions lib/application_business_rules/user_interaction/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions lib/application_business_rules/user_interaction/MenuItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
}
10 changes: 10 additions & 0 deletions lib/application_business_rules/user_interaction/MenuItem.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <cstdint>
#include <string>
#include <tasks/Task.hpp>
#include <vector>

/**
Expand All @@ -12,6 +13,7 @@ enum class MenuItemType
SUBMENU,
SWITCH,
VALUE,
TASK,
};

/**
Expand Down Expand Up @@ -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;
};
7 changes: 0 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading