cancel
Showing results for 
Search instead for 
Did you mean: 

Can I change the template for code generation in TouchGFX

Lutz
Associate II

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))

17 REPLIES 17
Erlkoenig
Associate III

Can't you implement a base class in "TouchGFX/gui/include/gui/common/MyBaseClass.hpp" and "TouchGFX/gui/src/common/MyBaseClass.cpp" and then simply derive your screen classes from that base class, which will then inherit those functions?

LouisB
ST Employee

Hello @Lutz ,

Welcome to the TouchGFX community.

Just declare all of them in the FrontendApplication.hpp and FrontendApplication.cpp.
There, they will be available for all screens.

I hope it helps,
Regards

Louis BOUDO
ST Software Developer | TouchGFX

Thank you very much for your answer.
I apologize, but my question was not formulated precisely enough.
Each inserted function must then be modified for this one screen.

You mean to manually modify it? Can't this be automated using e.g. C++ templates?

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.

Panchev68
Senior

Why don't you create a class, for example Helper, and declare all the functions you wrote as virtual or pure virtual. Of course every Screen class must inherit this class. Each of the functions can be overridden in Screen.

We use a similar approach for Menu Scroller

#ifndef MENUMAINVIEW_HPP
#define MENUMAINVIEW_HPP

#include <TouchGFX/TouchMenu/MenuScroller.hpp>
#include <gui/menumain_screen/MenuMainPresenter.hpp>
#include <gui_generated/menumain_screen/MenuMainViewBase.hpp>

class MenuMainView : public MenuMainViewBase, Lib::TouchGFX::MenuScroller
{
public:

    MenuMainView ();

    virtual ~MenuMainView () {}

    virtual void setupScreen ();
    virtual void tearDownScreen ();

private:

    void sliderValueChangedCallback (int value) override;


};

#endif        // MENUMAINVIEW_HPP

 

/// \brief MenuMainView class
/// \file
/// \version 1 \date 21.02.2023

#include <gui/menumain_screen/MenuMainView.hpp>

MenuMainView::MenuMainView () : MenuScroller (scrollableContainer, menuSlider1, 10)
{
}

void MenuMainView::setupScreen ()
{
    MenuMainViewBase::setupScreen ();
    MenuScroller::setup ();
}

void MenuMainView::tearDownScreen ()
{
    MenuMainViewBase::tearDownScreen ();
}

void MenuMainView::sliderValueChangedCallback (int value)
{
    MenuScroller::handleSliderValueChanged (value);
}

I hope I have been helpful
greetings
Bobby

 

Lutz
Associate II

Thank you all for your effort to answer me.
But I am not looking for an answer to solve my examples, but actually a solution to change the real generated code.
Just like some other code generators allow.

Is there perhaps one of the TouchGFX programmers here, who could contact me?
Or who could tell me definitively: No, we don't allow changing the code template?
(Then I'll write myself a wizard that rewrites the generated source code according to my ideas).

 

(Translated with DeepL.com (free version))

Can you make a simplified project and upload it? Maybe with 2 screens.
It's not clear what class you want modified. I'm pretty sure you can do it without code generation since you can make use of inheritance. TouchGFX works with model-view-presenter. You can add common code in ModelListener as virtual methods. All screen presenter and view classes inherit from this class.

"Each screen needs the "update" function, but each screen needs a different update because it has different objects"
Not necessarily. If you put pointers to the objects in an array/vector you can have your update method simply loop through the list of objects and call the necessary methods. The update method can be the same in that case. You just need to update the list of objects in each screen, but that can be done in 1 line. Though this is pure speculation on my part since you did not specify what this update method should do and what type of objects it should interact with.

TouchGFX works with model-view-presenter. An "update" method would not make much sense. The application already has a tick. That is the update. You modify the model. And the presenter will communicate with the model and may decide to communicate with the view to change something such as updating a value or hiding/unhiding a widget. If every screen has a clock, for example, you may write a updateClock method in ModelListener. You can also use containers if there are things in common between screens.

Kudo posts if you have the same problem and kudo replies if the solution works.
Click "Accept as Solution" if a reply solved your problem. If no solution was posted please answer with your own.
Lutz
Associate II

Thanks again to everyone who has tried to help me.
Unfortunately, all the help is related to my examples and not to my actual question about the possibility of customizing the code generator.
Here is a very simple example of what I would like to have:

This is how the code is currently generated:

#include <gui/scr_intro_screen/scr_IntroView.hpp>

scr_IntroView::scr_IntroView()
{

}

void scr_IntroView::setupScreen()
{
    scr_IntroViewBase::setupScreen();
}

void scr_IntroView::tearDownScreen()
{
    scr_IntroViewBase::tearDownScreen();
}


This is how I would like the code to be generated:

/*--------------------------------------------------------------------------------------*/
#include <gui/scr__base_intro_screen/SCR__BASE_IntroView.hpp>

//
extern "C"
{
}

/*--------------------------------------------------------------------------------------*/

//uint8_t         Speed;
//Unicode::UnicodeChar    buffer1[30];

//
/*--------------------------------------------------------------------------------------*/

#define     NOTUSED     0

//

SCR__BASE_IntroView::SCR__BASE_IntroView()
{
    /*--------------------------------------------------------------------------------------*/
    //
    //char    mcmd[10];
    
    //
    SCR__BASE_IntroView::updateScreen();
    //
}

void SCR__BASE_IntroView::setupScreen()
{
    SCR__BASE_IntroViewBase::setupScreen();
}

void SCR__BASE_IntroView::tearDownScreen()
{
    SCR__BASE_IntroViewBase::tearDownScreen();
}

/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
void    SCR__BASE_IntroView::updateScreen( void )
{
    /*--------------------------------------------------------------------------------------*/
    //
    //char    mbuf[30];
    
    //char    dummy = 0;  /* Brechpunkt */
    
    //
    /*--------------------------------------------------------------------------------------*/
    /* Unicode::    snprintf(UnicodeChar dst, uint16_t dstSize, const char format, ... )    */
    //Unicode::snprintf( flexMethodeBuffer, sizeof(flexMethodeBuffer), "%02i", gt.AktMethode );
    
    //dummy++;    /* Brechpunkt */
    
    //Unicode::snprintf(textMethodeBuffer, TEXTMETHODE_SIZE, "%02i", gt.AktMethode.ActMethodenNummer );
    //textMethode.setWildcard(textMethodeBuffer);
    //textMethode.invalidate();
    
    
    // gt.AktMethode.steps[ gt.AktMethode.ActStep
    //AktGT.IstStepDaten.
    //
}

/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
void    SCR__BASE_IntroView::RcvdCommand(long m_screen, int m_token,  char *m_mess, long m_val1, long m_val2 )
{
    /*--------------------------------------------------------------------------------------*/
    /*                                                                                      */
    /*  Aus _Screens.h die defines fuer die Screen-ID und die Befehle (token) die           */
    /*  dieser Screeen kennt.                                                               */
    /*--------------------------------------------------------------------------------------*/
    //
    //#define     SCR_ALLE                         		1000
    //
    //#define     TOKEN_SCR__ALLE_ACTTIME        		1000
    //
    //
    //#define     SCR__START                        	2000
    //
    //#define     TOKEN_SCR__START_RUNSTART          	1000
    //
    //    
    /*                                                                                      */
    /*--------------------------------------------------------------------------------------*/
    //static  int dummy = 0;
    
    //
    switch ( m_screen )
    {
    case SCR__ALLE :
        switch ( m_token )
        {
        case TOKEN_UPDATE_SCREEN :
            SCR__BASE_IntroView::updateScreen();
            //
            break;
        default:
            break;
        }
        break;
    case SCR__BASE_Intro :
        switch ( m_token )
        {
        case TOKEN_UPDATE_SCREEN :
            SCR__BASE_IntroView::updateScreen();
            //
            break;
        default:
            break;
        }
        break;
    default:
        break;
    }
}

void    SCR__BASE_IntroView::V_SndCommand( int m_token,  char *m_mess, long m_val1, long m_val2 )
{
    //char    mcmd[30];         /*                                                              */
    
    //
    //https://www.youtube.com/watch?v=SYdyJBehcYY
    presenter->P_SndCommand( m_token, m_mess, 0, 0 );
}

/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
#if NOTUSED
#endif 
/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
#ifdef __CC_ARM
#elif SIMULATOR
#else 
#endif 
/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/

And yes, the V_SndCommand() function belong in “FrontApplication.cpp”.
That comes next.

Oh yes, and this is what it looks like in my favorite editor:

 

Generated:

scr_intro_simple.jpg

 

 

 

 

 

 

 

 

 

 

 

wish:

scr_intro_CODE1.jpgscr_intro_CODE2.jpg

 

(I also like to call myself a “formatting fetishist”)

Translated with DeepL.com (free version)