I’m sure this has been addressed, but I can’t find quite what I’m looking for.
And that is, in general, how do you eliminate globals in lvgl?
I see it in things like a button creation. But I have external events and functions that may receive a new value. And I’ve having a bit of a time using those values and integrating into the lvgl app where I don’t have so many globals.
I figured I would use a data struct, much like the timer. But do I need a different struct for things? Multiple timers? (both seem like a bad idea). Does the one timer struct keep track of everything?
So far, when I have tried to use a struct, lvgl blows up and esp32 starts reseting.
I can do some things with bindings, but I’d like to know “how it’s done”…
Usually global variables can be avoided with passing LVGL objects along as user data for callbacks, other objects, events etc.
For updating LVGL objects (for instance a label) with new data, you will have to do that within an LVGL timer callback or use the “new” observer system.
The code is still a work in progress, everything keeps changing, much faster than I would like it too.
I have a timer, and that’s working, doing what it should, updating variables for the screen.
I’m just trying to get the best way to do this, before I write too much. I’m working on the binding, which would simplify things (but haven’t got it working just yet).
I have a stuct named timer_data_t, and a pointer to that is being passed into the LV_timer.
So I guess I’m trying to find out, do you have multiple timers for various functions, updating parts of the screen? Or does (almost) everything you need to update go into that one struct?
That’s what I’m currently doing, but I just think there’s a better way.
I think this is more descriptive of what I was trying to ask.
I’m writing a program for a 7" display that displays information about the state of our holding tanks. (yeah, still…)
Part of start up creates the timer (lv_timer_t * timer = lv_timer_create(my_timer, 30, &my_data))
using the struct “timer”.
Using lvgl related functions, I can update various things like labels.
But the data comes from ESP-NOW. Which doesn’t have access to the timer data.
If I try to access it via timer.tank_level, it’s accessing another memory space, NOT the timer struct. It’s an automatic callback, so I can’t manually call it with the struct.
So other than copying the data each tme, how does one go about getting outside data into the lvgl timer stuct, so lvgl has access to it (or, how do I go about accessing data from the lvgl timer struct so other functions have access to that)
It may be a bit of basic programming, but I’m missing it, or just not seeing it.
It’s not that much data, and doesn’t come in too often, so copying it inside the timer works, I just think there’s a better way, and I would rather do it “correctly”.