cancel
Showing results for 
Search instead for 
Did you mean: 

Simulate HW buttons in Simulator

Leonhardt
Associate II

Hi.

We have an application with a touch screen and 4 physical buttons. We have designed a demonstration GIU in TouchGFX, but to allow the simulator to handle presses on the hardware buttons, we have added the hardware buttons on the display. Consequently the display is made 100 pixels higher to have room for the buttons. It works fine for the simulator, but we cannot use the GUI design as it is for building the target application.

I expected that it was possible to setup the simulator to hold the hardware buttons as an addition the the application display. But apparently not. 

It would be nice if it was possible to design the hardware button arrangement in addition the the GUI. The buttons should of cause have a legend and the button ID in addition to the arrangement. And of cause this should not be included in the target build. But it would be nice if it could hold additional fields (e.g. text areas and radio buttons) for simulating the rest of the hardware

Did I miss something?

 

Regards

Kasper.

1 ACCEPTED SOLUTION

Accepted Solutions
LouisB
ST Employee

Hello @Leonhardt,

It's already possible to do so, when you create an interaction, with hardware button click you have a number and a character next to it :

LouisB_0-1751287042973.png

The character next to it is the keyboard character that will simulate the button.
In the case of the image, the hardware button id will be 65 which is also the ascii char A, so in the sim clicking on A will simulate the behaviour of the hw button.

 

I hope it answers your question,
BR,

Louis BOUDO
ST Software Engineer | TouchGFX

View solution in original post

2 REPLIES 2
LouisB
ST Employee

Hello @Leonhardt,

It's already possible to do so, when you create an interaction, with hardware button click you have a number and a character next to it :

LouisB_0-1751287042973.png

The character next to it is the keyboard character that will simulate the button.
In the case of the image, the hardware button id will be 65 which is also the ascii char A, so in the sim clicking on A will simulate the behaviour of the hw button.

 

I hope it answers your question,
BR,

Louis BOUDO
ST Software Engineer | TouchGFX

You can create a skin with buttons on it. Those are not clickable. But you could modify the code so that those are clickable.
You could modify the code so you create a second window with just buttons.

Below an example of a skin and code to use external buttons on skin + keyboard keys

skin_with_buttons.png

HALSDL2.cpp:

uint8_t HALSDL2::keyPressed = 0;
bool key[3];
bool key_old[3];

bool HALSDL2::doSampleTouch(int32_t& x, int32_t& y) const
{
    x = _x - getCurrentSkinX();
    y = _y - getCurrentSkinY();

    if (DISPLAY_ROTATION == rotate90)
    {
        int32_t tmp = x;
        x = y;
        y = DISPLAY_WIDTH - tmp;
    }

    bool touched = popTouch();

    if (touched)
    {
        if (isSkinActive && currentSkin != 0 && currentSkin->surface != 0)
        {
            if (_x >= 100 && _x < 100 + 150 && _y >= 30 && _y < 30 + 40)
            {
                key[0] = true;
                key[1] = false;
                key[2] = false;
            }
            else if (_x >= 300 && _x < 300 + 150 && _y >= 30 && _y < 30 + 40)
            {
                key[0] = false;
                key[1] = true;
                key[2] = false;
            }
            else if (_x >= 500 && _x < 500 + 150 && _y >= 30 && _y < 30 + 40)
            {
                key[0] = false;
                key[1] = false;
                key[2] = true;
            }
            else
            {
                key[0] = false;
                key[1] = false;
                key[2] = false;
            }
        }
        else
        {
            key[0] = false;
            key[1] = false;
            key[2] = false;
        }
    }
    else
    {
        key[0] = false;
        key[1] = false;
        key[2] = false;
    }

    // modify on rising edge
    if (key[0] && !key_old[0])
    {
        keyPressed = '1';
    }
    else if (key[1] && !key_old[1])
    {
        keyPressed = '2';
    }
    if (key[2] && !key_old[2])
    {
        keyPressed = '3';
    }

    key_old[0] = key[0];
    key_old[1] = key[1];
    key_old[2] = key[2];

    return touched;
}

bool HALSDL2::sampleKey(uint8_t& key)
{
    if (keyPressed)
    {
        key = keyPressed;
        keyPressed = 0;
        return true;
    }
    return false;
}

 

 

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.