element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Embedded and Microcontrollers
  • Technologies
  • More
Embedded and Microcontrollers
Blog STM32H7B3I - TouchGFX Simple Example: react on a button click
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Embedded and Microcontrollers to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 5 Aug 2020 9:12 PM Date Created
  • Views 6073 views
  • Likes 1 like
  • Comments 3 comments
  • stm32h7b3i
  • rt
  • stm32h7b3i-dk
Related
Recommended

STM32H7B3I - TouchGFX Simple Example: react on a button click

Jan Cumps
Jan Cumps
5 Aug 2020

I'm selected for the STM32H7B3I-DK -  DISCOVERY KIT road test.

In this part of the review, I'm writing a first custom handler for a button click.

 

image

 

The scenario is simple: you click a button, and that makes a square show up and disappear again.

What we'll see:

  • create an event handler
  • control the attributes of another graphical object based on that.

I'm assuming that you can bring up a TouchGFX aplication. If not, check STM32H7B3I - Create a TouchGFX Project.

 

Create a Screen

 

First the background. Start with putting a Box shape on the empty screen. Same size as the screen. White.

(you can also use another colour - or no box, but I leave it up to you to see what happens if you provide no background)

 

image

 

 

Then put a toggle button and another - red -  box on the screen.

Name the button btnOnOff (not critical), name the box boxSignal (critical, because we'll use it in our code).

Then, make the box invisible, so that it doesn't show at startup. We'll make it appear in the code.

 

React on a Button Toggle

 

The next step is to make our code realise that the toggle button is flipped. So that we can act on that event.

In Designer, you select the interactions tab.

image

Take care to use the exact same settings as above and use the same Function name.

 

Writing the Event Handler

 

In the CubeIDE, navigate to the screen class. We'll add the virtual handler that we asked for in Designer.

First add the virtual event handler to your screen class: TouchGFX/gui/include/gui/screen_screen/screenView.hpp.

 

class screenView : public screenViewBase
{
public:
    screenView();
    virtual ~screenView() {}
    virtual void setupScreen();
    virtual void tearDownScreen();
    virtual void btnToggled();

 

 

Then implement it. Here we're acting on a button push, and decide what to do based on it's state.

Open TouchGFX/gui/src/screen_screen/screenView.cpp and add this function:

 

void screenView::btnToggled()
{
bool bVisible = this->btnOnOff.getState();
this->boxSignal.setVisible(bVisible);
this->boxSignal.invalidate();
}

 

 

Build, start the debugger and test the effect.

A red square will show or hide ,depending on the button state.

The state is queried in line 03 above.

Then, the square's "visible" attribute is set on that in line 04.

Line 05 forces a redraw of the square.

 

 

Have fun!

(this also works without the board, if you just run it in the Designer's simulator)

 

Related Posts
First Experience with CubeIDE
Create a TouchGFX Project with support for the Designer, CubeIDE and Debugger - Pt 1: Screen Works
Create a TouchGFX Project with support for the Designer, CubeIDE and Debugger - Pt 2: Touch Works
TouchGFX Simple Example: react on a button click
USB, freeRTOS ,Task Notifications and Interrupts
the Development Kit STMod+ Connector and Using UART2
TouchGFX Application Framework: Model, View, Presentation, Message Queue
TouchGFX Application Framework: A Mock GUI - Show Statuses, Switch Screens
TouchGFX Application Framework: MVP and the ModelListener
Write a CubeIDE MX application: Hardware Cryptography with DMA
  • Sign in to reply

Top Comments

  • Jan Cumps
    Jan Cumps over 5 years ago +1
    I got UART working too now. This is a naive and random try. Just echoing any character arriving at the port. I'll embed it in the rtos tasks now for my road test example project. It'll exchange SCPI commands…
  • DAB
    DAB over 5 years ago

    Good process walk through Jan.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 5 years ago in reply to Jan Cumps

    Leaving this here for my own documentation, just before I enable freertos...

     

      /* Infinite loop */
      /* USER CODE BEGIN WHILE */
    
      uint8_t str[] = "*IDN?;";
      HAL_UART_Transmit(&huart1, str, sizeof(str), 100);
      uint8_t in[100];
      uint16_t buffersize = 100;
      while (1)
      {
        /* USER CODE END WHILE */
    
        /* USER CODE BEGIN 3 */
        HAL_StatusTypeDef ret;
        ret = HAL_UART_Receive(&huart1, in, buffersize, 100);
    
        if(ret == HAL_OK) {
          HAL_UART_Transmit(&huart1, in, buffersize, 10);
        } else {
          HAL_UART_Transmit(&huart1, in, buffersize - (huart1).RxXferCount, 10);
        }
    
      }
      /* USER CODE END 3 */

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 5 years ago

    I got UART working too now.

    image

     

    This is a naive and random try. Just echoing any character arriving at the port.

    I'll embed it in the rtos tasks now for my road test example project. It'll exchange SCPI commands with my electronic load to query data and set modes...

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube