cancel
Showing results for 
Search instead for 
Did you mean: 

A question about creating a screen menu system

HHarj.1
Senior

I am trying to make a menu screen system which I thought first would be trivial, but until I figure it out it isn't... There are radio buttons for selecting the wanted measurement and a start button. The idea is to send the chosen test ID to the Model.cpp, which will then send it to the FreeRtos task, which handles the message. So, if radio button 1 is selected and start button pressed the message is 0x01, and if it's #2, then the message is 0x02 and so on. The problem is how to combine this with the correct screen switching? The program should run the chosen test and then switch to the corresponding screen showing the results. TouchGFX generates screen transitioning functions in the base class so should I modify that (even it has DO NOT MODIFY text with write-protection)? Any help how should I implement this would be appreciated.

5 REPLIES 5
Romain DIELEMAN
ST Employee

Hi,

I am unsure i understand your issue properly: you wish to go to another screen corresponding to the radio button pressed but cannot find a function to do it? As you said you cannot modify the base class. A simple solution would be to create a fake button interaction to enable the usage of the transition functions without having to take out and modify a lot of code.

In Designer go to the Interactions section and add a new interaction with "Hardware button is clicked" as trigger. Choose any button key (you will not have to use it) and select "Change screen" as Action. Select which screen you wish to go to.

0690X00000D8CznQAF.png

Now after generating the code in Designer (Generate Code button), you will find the following code in the <NameOfScreen>ViewBase.cpp (which you cannot modify):

//Handles when a key is pressed
void Screen1ViewBase::handleKeyEvent(uint8_t key)
{
    if(0 == key)
    {
        //InteractionGoToScreen2
        //When hardware button 0 clicked change screen to Screen2
        //Go to Screen2 with no screen transition
        application().gotoScreen2ScreenNoTransition();
    }
}

You can now copy/paste the "application().gotoScreen2ScreenNoTransition()" function wherever you need it in your code ( i suppose in the View file of your main page). You only need to create an interaction once for a screen to be able to use the function anywhere in your project.

Please tell me if I answered completely wrong or how i can help you more. Add some code or more details as well if you have more questions so that we can have a better insight of your problem.

Thanks

Hi,

thank you for your reply. Yes, you understood the problem correctly. I believe creating fake button interactions should do the trick nicely. The other issue is sending the test ID forward. What I'm trying to do is when the radio button is selected -> "execute C++ code". That seems to create the wanted variable in the base class of the Menu Screen. Then, if the start button is pressed, it calls a virtual function, which sends forward the chosen variable (which test will be done). I'm hesitant if this would work as I plan...Is this variable accessible elsewhere in my program? Should I declare it as global in somewhere else (where exatcly), and then update the value if a radio button is selected? Other suggestions are welcome.

Edit: Creating a virtual function when the start button is pressed creates a function which doesn't take any parameters (unlike e.g. slider bar), so I don't know how can I pass the variable for the function.

0690X00000D8E3bQAF.png

Romain DIELEMAN
ST Employee

Personally I never use the "execute C++ code" interaction: even thought it allows to add some code directly from Designer, it is annoying to use and adapt to what you want. I would use instead the "call new virtual function" interaction. This will create a function in the ViewBase.cpp below which you can overwrite in the View. I called mine functionPressButton1()

void MenuScreenViewBase::radioButtonSelectedCallbackHandler(const touchgfx::AbstractButton& src)
{
    if (&src == &radioButton1)
    {
        //InteractionTest
        //When radioButton1 selected call virtual function
        //Call functionPressButton1
        functionPressButton1();
    }
}

In View.cpp you can now for example do this to modify the text and change screen at once.

void Screen1View::functionPressButton1()
{
    NumberOfTest = 0x01;
    application().gotoScreen2ScreenNoTransition();
}

Do not forget to declare everything in the .hpp

class MenuScreenView : public MenuScreenViewBase
{
public:
    MenuScreen();
    virtual ~MenuScreenView() {}
    virtual void setupScreen();
    virtual void tearDownScreen();
 
                    // We override the function of ViewBase here
    virtual void functionPressButton1();
 
protected:
                    // NumberOfTest will be available everywhere in the View.cpp
    int8_t NumberOfTest;
};

Now if you want to have the value of NumberOfTest available everywhere i would suggest to make it go trough the Model. You can find a simple example in Tutorial 3 step 2 where we want to save some data (the time) and transfer it to another screen.

Another way to learn how to use buttons and events would be to learn how handleClickEvent() works (most UI templates available on Designer use it, especially the ones with buttons).

Hope this helps a bit.

/Romain

HHarj.1
Senior

Helped a ton, thank you! I believe I now have the needed info to get this working.

Hi

  1. //Handles when a key is pressed
  2. void Screen1ViewBase::handleKeyEvent(uint8_t key)
  3. {
  4. if(0 == key)
  5. {
  6. //InteractionGoToScreen2
  7. //When hardware button 0 clicked change screen to Screen2
  8. //Go to Screen2 with no screen transition
  9. application().gotoScreen2ScreenNoTransition();
  10. }
  11. }

After that, how can we link our generated code with the hardware button. Please tell what are the modules that needs modifications