@@ -159,6 +159,24 @@ static void ScreenMenu_value_cb(lv_event_t *e)
159
159
IScreen_leave ();
160
160
}
161
161
}
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
+ }
162
180
}
163
181
164
182
/* *
@@ -275,6 +293,7 @@ void ScreenMenu::draw()
275
293
lv_label_set_text_fmt (lab, " %.*f" , valItem->getDecimals (), *valItem->getPtrDouble ());
276
294
lv_obj_add_event_cb (btn, ScreenMenu_value_cb, LV_EVENT_SHORT_CLICKED, (void *)item); /* assign the value callback for event short clicked */
277
295
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);
278
297
}
279
298
break ;
280
299
}
@@ -284,6 +303,27 @@ void ScreenMenu::draw()
284
303
showNewAndDeleteOldScreen (screen);
285
304
}
286
305
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
+
287
327
/* *
288
328
* @brief Event callback function for the incrementation button in modifier screen
289
329
* @note The lvgl event user data hold a pointer to the spinbox lvgl object
0 commit comments