@@ -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
0 commit comments