What MCU/Processor/Board and compiler are you using?
Raspberry PI4, GCC 8.3.0
What LVGL version are you using?
7.9
What do you want to achieve?
From screen A, create a new screen B
Do something within screen B and update a global shared variable
Re-load parent screen A
Check (new) value of shared variable
What have you tried so far?
Declared top-level variable V in screen A source module
Draw screen B (calling an exported function of B source module)
B source module has “extern V”
Update V within B
Re-load parent screen A with “lv_scr_load(parentScreen)” (parentScreen is passed to B draw method)
Code to reproduce
I’m unable to submit a code that compiles.
Summary:
ScreenA.c
[top-level] int g_presetNameEntered = 0;
[...]
drawSaveNewPresetDialog(lv_scr_act());
if (g_presetNameEntered) {...Never Enters Here... }
I’m accustomed to something like “onLoad()” which would be called as first method when a page is loaded (I would check “g_presetNameEntered” there), but I reckon there’s nothing like this in LVGL.
In this case the best thing to do would be to have an updateScreenA() function which you call whenever screen A is (re)loaded. That function should check the global variable and update any UI elements accordingly.
I found that having a central function to swap screens is simple and intuitive. Simplify define N screens and call a function to switch to the next one. That function can also call an ‘on_unload()’ function of the old screen and an ‘on_onload’ of the new screen. It’s easier with C++ but can also done with C structs and function pointers.
In my case, I can create all the screen when the program starts and then switch them as needed.