2024-04-26 01:21 AM - edited 2024-04-26 09:45 AM
Hello everyone,
I have been working with TouchGFX for some time now and have created a collection of functions that I need in each screen.
At the moment I have to copy them manually into each newly generated screen and rename the function names.
Is there a way to automate this by copying "my" functions into a template?
After generation, these functions must then be adapted to this one screen.
Example
Each screen needs the "update" function, but each screen needs a different update because it has different objects
The screen::update() function should therefore be generated automatically, but the content must be adapted manually.
Different approach, same problem:
"Can I customize the code generation templates in TouchGFX Designer to tailor the generated code to my specific requirements. This customization should allows me to adapt the generated code to fit my coding standards, project structure, or integration with other frameworks or libraries."
I have found a directory "\template\" with sources, but these sources do not seem to be used in the generation.
Best regards
Lutz
Edit1: added "(...) adapted (...)"
Edit2: added "Example (...)"
Edit3: added "Different approach, same problem(...)"
(Translated with DeepL.com (free version))
2024-05-04 05:04 AM
//Unicode::snprintf(textMethodeBuffer, TEXTMETHODE_SIZE, "%02i", gt.AktMethode.ActMethodenNummer ); //textMethode.setWildcard(textMethodeBuffer); //textMethode.invalidate();
Do you want to generate those comments? This appears to be pretty screen-specific, i.e. not very suitable for a code generation template.
The stuff inside RcvdCommand could be generated using a base class and C++ templates, without code generation by TouchGFX.
2024-05-04 05:11 AM
Extremely hard to read code! Why not consider some C++ annotation. This TouchGFX style isn't bad at all. I still can't understand your question. There are enough answers above that are a solution to your problem.
Consider an editor too: here's an example of what it looks like in VSCode:
2024-05-05 07:53 AM
Yes, I wish to generate this (and all other) comment.
As a reminder how to change text in a screen.
Most comments are for reminding how to do things at there specific place.
The structure inside RcvdCommand is only the starting point for adding screen specific things by adding
Case "COMMANDTOKEN":
// do specific command things here
break:
2024-05-05 08:10 AM
No thanks, I want to use my own editor and format style.
There are even companies that have fixed formatting rules for their programmers so that colleagues and future generations can also read it later (according to these rules).
As an individual employee, you can no longer argue about it.
My question was “How can I change the code generation so that it complies with my rules and specifications?”
(With examples of my rules and ideas)
My question was not “What can I do to use the existing code generation with my ideas.”
Translated with DeepL.com (free version)
2024-05-05 09:05 AM - edited 2024-05-06 12:02 AM
As you should know by now you cannot modify the code generation at the moment as there are no fields for customization of the generator and the source code is closed source (for obvious reasons). TouchGFX allows you to type inline code in the editor, call virtual methods and they also allow you to overload implemented classes. This already makes it very customizable. It is not perfect, but I had no problems with it. Much less challenging then STM32CubeMX customization (requires weird preprocessor tricks sometimes). I don't think they are going to change TouchGFX for your very specific needs. And I think all our solutions showed that customizing the code generation process is not needed.
If you really disagree that our solutions can solve your problem you need to show that to us by uploading a simplified project of what you want. You just posted some code of one file. It's not clear how that would fit in your project. Especially since you said you had multiple screens and you only posted 1 file. My German is not that good so that makes it harder to understand your comments.
Here is what I meant with a simple example project:
I do have an alternative solution to the ideas I and others already proposed:
TouchGFX allows you to modify the build process to suit your needs. You can have TouchGFX (and/or STM32CubeIDE) call a custom script before building. There's nothing stopping you from writing a code generator in python and calling it during build. But I don't think that is necessary unless you really want to generate things like comments.
2024-05-05 09:19 AM - edited 2024-05-05 12:51 PM
I'm not trying to argue.
and I don't want to impose an opinion. Just friendly advice that would help you and others around you.
Yes you are indeed right about enforcing coding standards
here are a few of them
https://google.github.io/styleguide/cppguide.html
https://isocpp.org/wiki/faq/coding-standards
Case "COMMANDTOKEN": // do specific command things here break:
pls share what language this is written in...maybe pascal....definitely not in c++ or c.
with best wishes
2024-05-06 02:33 AM
Yes, I now realise that there is no way to modify the code generator.
I had hoped there was a (hidden?) switch to use the template in the directory
C:\TouchGFX\4.23.2\app\template\EmptyApplication
and not use the "template" permanently implied in the code
I imagine that implementing the switch between external and internal templates is pretty easy.
However.
Too bad, then I'll just write a wizard in C# that rewrites every freshly generated source according to my ideas.
A thousand thanks to everyone who has tried to help me.
Translated with DeepL.com (free version)
2024-05-06 02:49 AM
You are absolutely right, the code is nonsense, at best "pseudo-code"
It should just be another CASE inserted into the existing switch structure in RcvdCommand(), line 108 to 117
switch ( m_token )
{
case TOKEN_UPDATE_SCREEN :
SCR__BASE_IntroView::updateScreen();
//
break;
Case COMMANDTOKEN :
// do specific command things here
break;
default:
break;
}
Many thanks for your efforts.
I had found the template in the directory
C:\TouchGFX\4.23.2\app\template\EmptyApplication
and hoped that it could be used and modified.
But that's probably not possible.
I will write a small wizard in C# that reformats newly generated code according to my ideas.