Skip to content

Commit fa64662

Browse files
committed
add possibility to refresh screen items and implement it for ScreenMenu
1 parent 8910deb commit fa64662

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

lib/3rd_party_adapters/LVGL/GuiEngine.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ void GuiEngine::registerKeyPad(IKeypad *keypad)
200200
*/
201201
void GuiEngine::refresh()
202202
{
203+
CurrentScreen->refresh();
203204
lv_timer_handler();
204205
LV_LOG_TRACE("Adafruit display() start");
205206
this->display.display();

lib/3rd_party_adapters/LVGL/Screen.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,24 @@ static void ScreenMenu_value_cb(lv_event_t *e)
159159
IScreen_leave();
160160
}
161161
}
162+
else if ((code == LV_EVENT_REFRESH) && (item != nullptr))
163+
{
164+
/* the second child label holds the actual value as text */
165+
auto lab = lv_obj_get_child(obj, 1);
166+
167+
double *ptr = item->getPtrDouble();
168+
if (ptr == nullptr)
169+
{
170+
/* if pointer to double variable is not valid, disable the switch and don't add callbacks */
171+
lv_obj_add_state(obj, LV_STATE_DISABLED);
172+
lv_label_set_text(lab, "NULL");
173+
}
174+
else
175+
{
176+
/* if pointer to double variable is valid, show it's value and assign callbacks */
177+
lv_label_set_text_fmt(lab, "%.*f", item->getDecimals(), *item->getPtrDouble());
178+
}
179+
}
162180
}
163181

164182
/**
@@ -275,6 +293,7 @@ void ScreenMenu::draw()
275293
lv_label_set_text_fmt(lab, "%.*f", valItem->getDecimals(), *valItem->getPtrDouble());
276294
lv_obj_add_event_cb(btn, ScreenMenu_value_cb, LV_EVENT_SHORT_CLICKED, (void *)item); /* assign the value callback for event short clicked */
277295
lv_obj_add_event_cb(btn, ScreenMenu_value_cb, LV_EVENT_KEY, nullptr); /* assign the value callback for event key press */
296+
lv_obj_add_event_cb(btn, ScreenMenu_value_cb, LV_EVENT_REFRESH, (void *)item);
278297
}
279298
break;
280299
}
@@ -284,6 +303,27 @@ void ScreenMenu::draw()
284303
showNewAndDeleteOldScreen(screen);
285304
}
286305

306+
void ScreenMenu::refresh()
307+
{
308+
auto screen = lv_scr_act();
309+
auto cnt = 0;
310+
311+
/* go through all menu items and send a refresh to it */
312+
for (uint16_t menuItemId = 0; menuItemId < lv_obj_get_child_cnt(screen); ++menuItemId)
313+
{
314+
auto menuItem = lv_obj_get_child(screen, menuItemId);
315+
lv_event_send(menuItem, LV_EVENT_REFRESH, NULL);
316+
++cnt;
317+
/* look in sub items as well */
318+
for (uint16_t subItemId = 0; subItemId < lv_obj_get_child_cnt(menuItem); ++subItemId)
319+
{
320+
auto subItem = lv_obj_get_child(menuItem, subItemId);
321+
lv_event_send(subItem, LV_EVENT_REFRESH, NULL);
322+
++cnt;
323+
}
324+
}
325+
}
326+
287327
/**
288328
* @brief Event callback function for the incrementation button in modifier screen
289329
* @note The lvgl event user data hold a pointer to the spinbox lvgl object

lib/3rd_party_adapters/LVGL/Screen.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class IScreen
1919
virtual ~IScreen() = default;
2020

2121
virtual void draw() = 0;
22+
virtual void refresh() {};
2223
};
2324

2425
/**
@@ -33,6 +34,7 @@ class ScreenMenu final : public IScreen
3334
~ScreenMenu() override = default;
3435

3536
void draw() override;
37+
void refresh() override;
3638

3739
private:
3840
const MenuItemList &_List;

0 commit comments

Comments
 (0)