2025-02-24 3:12 AM
Hello there! I am new to STM32, I have an STM32F746G_DISCO, I have a project where I have to control the frequencies and duty cycles of a machine, that's kind of besides the point, I have set up all the screens I need and I have to make it so that that every value I set (ie: frequencies and duty cycles) to be kept in the memory and not only the screen values should be the same, I also need to have the counters I use on the code (which I will use to determine the signals to control the values, I will make a more detailed post to ask how I will do this)
Basically I need these values stay the same even after a screen change, can anyone help me with this?
2025-02-24 4:01 AM - edited 2025-02-24 4:02 AM
Hello @Simecrafter and welcome to TouchGFX!
We have made a guide for that exact question.
I am sure you will acquire the skills necessary to achieve your project once you follow the tutorial!
The basic concept is that you have to save your data in the Model.cpp file and access them from your screens.
Regards,
2025-02-24 11:35 PM
Thanks a lot, it really is a great guide, however I unfortunately can't get it to work on my project, I'm constantly getting up to 50 error despite of me doing pretty much the same thing just with the names I'm using on my project
For example, I only want to keep my "freqCounter" and "dutyScreenCounter" (later on dutyRealCounter) saved, they are basically numbers that go up and down according to the button you're pressing, which will control a PWM signal based on their values (I don't know how to do it yet, I might make a post asking about it when I get this done). I have made the save values as "savefreqCounter" and "savedutyScreenCounter" and I changed the int16_t to int32_t which I'm using, this results in 'freqCounter' was not declared in this scope & 'dutyCounter' was not declared in this scope errors, along with 'void Model::tick()' is protected within this context and Invalid project path: Include path not found. As I said I am new into all this and I'm kind of rushing to get these done, I can provide my code if needed, I'd appreciate any help as I need to fix this asap to continue anything about my project.
2025-02-25 12:11 AM
Hello Simecrafter,
When i want to save a value, in my particular case, what i do is that when i for example change a value from a container says a number picker, or i write a value, etc, it generates an interaction, even changing the screen generates an interaction like the ScreenSetUp or SetDown.
In those kind interactions, in which ever fits your project, as in any C/C++ code, you can have a global variable, and then in the desire interaction, you can save the value in the mentioned global variable, then when you come back to the screen, saying you did change the screen, in the SetUpView function, you then take the value from the global variable and put in the container/textarea or wherever you need it.
Hope it helps.
Greetings
2025-02-25 1:01 AM
That would probably work but what are the steps for me to update my code to make my counter variables a global variable and also call them when needed?
2025-02-25 1:11 AM
You have to open the source code for the screen you are working in, and find/add the interaction function where you want the value capture to happen and also the interaction function where you want the value to update a container, in this particular my recomendation is in the ScreenSetUp function which is the one called when you join a screen.
About the global variable, you do it as you do in C/C++ conventional programs. You can create it as global in any part/file, and add it to your .C .CPP
Hope it helps.
Greetings
2025-02-25 1:40 AM
Hi @Simecrafter
"I'm constantly getting up to 50 error "
If you could share a bare-bones GfxDesigner example of what you're trying to achieve, it's much easier to discuss the code. Before 7zip-ing the project, delete these folders
/build
/generated
/simulator/msvs/.vs
2025-02-25 2:24 AM
Thanks a lot! With the help of AI I managed to adapt my code to the global values and now my values stay the same across screens!
2025-02-25 2:31 AM - edited 2025-02-25 2:32 AM
Glad to know it helped out!