cancel
Showing results for 
Search instead for 
Did you mean: 

Designer Generated Code: function not declared in the scope

cusp
Associate II

I am currently trying to follow the Designer Generated Code tutorial with `button1Clicked`. However, whenever I try to Run Target it says the function is not declared in the scope. I declared it in the MyView class as a public virtual function. Not sure if I am just missing something simple. If you think it is more complicated and I should add all the details for the situation, feel free to let me know. I am just thinking it is something very simple.

Edit:

Thank you for your reply Alexandre, I can definitely provide more information:

The board I am using is the STM32F469 Discovery Kit.

I am trying to implement a function called `user_button_clicked()` that is called when `button1` is clicked. Necessary code is below.

Include file startup_screenView.hpp:

#ifndef STARTUP_SCREENVIEW_HPP
#define STARTUP_SCREENVIEW_HPP
 
#include <gui_generated/startup_screen_screen/startup_screenViewBase.hpp>
#include <gui/startup_screen_screen/startup_screenPresenter.hpp>
 
class startup_screenView : public startup_screenViewBase
{
public:
    startup_screenView();
    virtual ~startup_screenView() {}
	virtual void user_button_clicked();
    virtual void setupScreen();
    virtual void tearDownScreen();
	
protected:
};
 
#endif // STARTUP_SCREENVIEW_HPP

Source file startup_screenView.cpp:

#include <gui/startup_screen_screen/startup_screenView.hpp>
#include <touchgfx/Color.hpp>
 
startup_screenView::startup_screenView()
{
 
}
 
void startup_screenView::setupScreen()
{
    startup_screenViewBase::setupScreen();
}
 
void startup_screenView::tearDownScreen()
{
    startup_screenViewBase::tearDownScreen();
}
 
void startup_screenView::user_button_clicked()
{
	//do this when user button pushed on dev board
	box2.setColor(Color::getColorFrom24BitRGB(255, 0, 0));
	box2.invalidate();
}

Uneditable generated source file startup_screenViewBase.cpp:

/*********************************************************************************/
/********** THIS FILE IS GENERATED BY TOUCHGFX DESIGNER, DO NOT MODIFY ***********/
/*********************************************************************************/
#include <gui_generated/startup_screen_screen/startup_screenViewBase.hpp>
#include <touchgfx/Color.hpp>
#include "BitmapDatabase.hpp"
#include <texts/TextKeysAndLanguages.hpp>
 
startup_screenViewBase::startup_screenViewBase() :
    buttonCallback(this, &startup_screenViewBase::buttonCallbackHandler)
{
 
    box1.setPosition(0, 0, 800, 480);
    box1.setColor(touchgfx::Color::getColorFrom24BitRGB(54, 40, 242));
 
    buttonWithLabel1.setXY(315, 210);
    buttonWithLabel1.setBitmaps(touchgfx::Bitmap(BITMAP_BLUE_BUTTONS_ROUND_EDGE_SMALL_ID), touchgfx::Bitmap(BITMAP_BLUE_BUTTONS_ROUND_EDGE_SMALL_PRESSED_ID));
    buttonWithLabel1.setLabelText(touchgfx::TypedText(T_SINGLEUSEID1));
    buttonWithLabel1.setLabelColor(touchgfx::Color::getColorFrom24BitRGB(255, 255, 255));
    buttonWithLabel1.setLabelColorPressed(touchgfx::Color::getColorFrom24BitRGB(255, 255, 255));
    buttonWithLabel1.setAction(buttonCallback);
 
    box2.setPosition(141, 112, 50, 50);
    box2.setColor(touchgfx::Color::getColorFrom24BitRGB(255, 255, 255));
 
    add(box1);
    add(buttonWithLabel1);
    add(box2);
}
 
void startup_screenViewBase::setupScreen()
{
 
}
 
void startup_screenViewBase::buttonCallbackHandler(const touchgfx::AbstractButton& src)
{
    if (&src == &buttonWithLabel1)
    {
        //Interaction1
        //When buttonWithLabel1 clicked execute C++ code
        //Execute C++ code
        user_button_clicked();
    }
}

Build Log:

    Compile
        make -f target/gcc/Makefile -j10
        Converting images
        Compiling gui/src/startup_screen_screen/startup_screenView.cpp
        Compiling generated/gui_generated/src/startup_screen_screen/startup_screenViewBase.cpp
        generated/gui_generated/src/startup_screen_screen/startup_screenViewBase.cpp: In member function 'void startup_screenViewBase::buttonCallbackHandler(const touchgfx::AbstractButton&)':
        generated/gui_generated/src/startup_screen_screen/startup_screenViewBase.cpp:43:9: error: 'user_button_clicked' was not declared in this scope
                 user_button_clicked();
                 ^~~~~~~~~~~~~~~~~~~
        target/gcc/Makefile:337: recipe for target 'build/ST/STM32469IDISCO/generated/gui_generated/src/startup_screen_screen/startup_screenViewBase.o' failed
        make[2]: *** [build/ST/STM32469IDISCO/generated/gui_generated/src/startup_screen_screen/startup_screenViewBase.o] Error 1
        make[2]: *** Waiting for unfinished jobs....
        make[1]: *** [generate_assets] Error 2
        target/gcc/Makefile:304: recipe for target 'generate_assets' failed
        target/gcc/Makefile:46: recipe for target 'all' failed
        make: *** [all] Error 2
        Failed
    Failed

End Goal: call a function created by me (user) from an event not associated with the touch screen interactions. For example, change the color of the screen or change the screen when the user button on the dev board is clicked. This is what I started with the tutorial Designer Generated Code.

I have not simulated the project like this because I did not make the makefile changes to the simulation makefile; I will do that in the meantime. If you need anymore information, feel free to let me know. Thank you for your help!

1 ACCEPTED SOLUTION

Accepted Solutions
Alexandre RENOUX
Principal

Hi,

I see what you are doing wrong. The action when the button is clicked you set is "execute C++ code" and in the Code field you just call foo();, this function call will be generated in the generated file but this file has no knowledge about the definition of this function. Therefore you have this error.

The right approach is to set the action to "call new virtual function" then generate code.

0693W000000UmNwQAK.png

Then you will see in the header of the generated file (for me it is Screen1ViewBase.hpp) :

    /*
     * Virtual Action Handlers
     */
    virtual void user_button_clicked()
    {
        // Override and implement this function in Screen1
    }

Now you implement it in your files (mine are Screen1View.hpp and .cpp)

ScreenView.hpp

#ifndef SCREEN1VIEW_HPP
#define SCREEN1VIEW_HPP
 
#include <gui_generated/screen1_screen/Screen1ViewBase.hpp>
#include <gui/screen1_screen/Screen1Presenter.hpp>
 
class Screen1View : public Screen1ViewBase
{
public:
    Screen1View();
    virtual ~Screen1View() {}
    virtual void setupScreen();
    virtual void tearDownScreen();
    virtual void user_button_clicked();
protected:
};
 
#endif // SCREEN1VIEW_HPP

Screen1View.cpp

void Screen1View::user_button_clicked()
{
    box1.setColor(Color::getColorFrom24BitRGB(255, 0, 0));
	box1.invalidate();
}

This should work as it works on my side.

/Alexandre

View solution in original post

8 REPLIES 8
Alexandre RENOUX
Principal

Hello,

Indeed more information would help answering. When you click on run target, it executes the makefile to build the project and to download directly into the connected board.

Which board do you use to run this example ? Did you make sure that the simulator is working properly ?

/Alexandre

Not sure if you get notified, but I add more information to the original question. Thank you for your help! :)

Alexandre RENOUX
Principal

Hello,

Thank you for these information.

Do you use the application template from TouchGFX Generator ? It is strange because when I create the same interaction as you in Designer and run simulator or target, there's no compiling error for this file. Could you try to open a new project in TouchGFX Designer by selecting the STM32F469 Disco application template and an empty GUI, then add a box and a button as you already did, add an interaction and run simulator ?

Your end goal is using a physical button so I do not think that trying a graphic button will help. You already have a buttonController called KeySampler in the application template so the only thing left to do should be to implement handleKeyEvent(uint8_t key) function in your GUI.

If you want more information on how to interface with physical buttons, you can have look at https://touchgfx.zendesk.com/hc/en-us/articles/205074551-Interfacing-with-physical-buttons.

/Alexandre

Hi,

I just tried what you suggested: I made a new project with a blank template for the particular board I stated earlier. I generated the project and changed only the things I mentioned above (I made the function foo this time around but I made sure to change it everywhere necessary). Other than the files that I put in my original post, do I need to change any others? I am very lost as to why this is not working. Any help would be greatly appreciated.

0693W000000UfQjQAK.png

Alexandre RENOUX
Principal

Hi,

I see what you are doing wrong. The action when the button is clicked you set is "execute C++ code" and in the Code field you just call foo();, this function call will be generated in the generated file but this file has no knowledge about the definition of this function. Therefore you have this error.

The right approach is to set the action to "call new virtual function" then generate code.

0693W000000UmNwQAK.png

Then you will see in the header of the generated file (for me it is Screen1ViewBase.hpp) :

    /*
     * Virtual Action Handlers
     */
    virtual void user_button_clicked()
    {
        // Override and implement this function in Screen1
    }

Now you implement it in your files (mine are Screen1View.hpp and .cpp)

ScreenView.hpp

#ifndef SCREEN1VIEW_HPP
#define SCREEN1VIEW_HPP
 
#include <gui_generated/screen1_screen/Screen1ViewBase.hpp>
#include <gui/screen1_screen/Screen1Presenter.hpp>
 
class Screen1View : public Screen1ViewBase
{
public:
    Screen1View();
    virtual ~Screen1View() {}
    virtual void setupScreen();
    virtual void tearDownScreen();
    virtual void user_button_clicked();
protected:
};
 
#endif // SCREEN1VIEW_HPP

Screen1View.cpp

void Screen1View::user_button_clicked()
{
    box1.setColor(Color::getColorFrom24BitRGB(255, 0, 0));
	box1.invalidate();
}

This should work as it works on my side.

/Alexandre

Awesome, thank you, that worked for me. I honestly just didn't see that option in the interactions and it wasn't clear to me to use that in the tutorial. In regards to my actual goal, thank you for linking that other tutorial. I am trying to overall link touchgfx with c software that is written for a STM32 microcontroller. Is there any way I can call touchgfx functions from outside of the classes? It seems all the tutorials use the view classes to make user generated code to interact with the display. However, let's say I have another task running and it hits an event in which it performs multiple different actions, one being changing the value of a text box on the display. Let me know if you have any guidance on this, and I will continue researching. Thank you again for all your help!

@Alexandre RENOUX 

I realize this is an old topic, but I am having issues doing this for a slider on a project generated by the TouchGFX Designer (4.24.1) and imported into Stm32CubieIDE (v1.16.0). I am using a Stm32F46-Disco board.

I setup an interaction, to call a virtual function:

scottSD_0-1729007283144.png

Which does create a virtual function declaration in the base header file:

scottSD_1-1729007352419.png

I then added a virtual declaration to my screen's hpp file:

scottSD_2-1729007420767.png

And added the function to the cpp file. But I get the following error in the cpp when attempting to compile:

scottSD_3-1729007802080.png

And yes, I did import the files into the Project Explorer from the filesystem so I could actually see them and edit them. The process of getting the files imported in the Project Explorer is very tedious when starting with a project generated from the TouchGFX Designer (to say the least). The folders of the project don't resemble the file system whatsoever (there are no "include" and "src" directories, for instance).

This has something to do with the screen file not being able to see the base header file, even though the include for that base file is right at the top of the screen view file. I checked the project properties paths and symbols and they are correct.