cancel
Showing results for 
Search instead for 
Did you mean: 

How to use hardware button interaction?

qqAnton
Senior

Hi,

I am making a project where I need to use hardware buttons,

I found some examples with queue and Model:: tick and it works well,

but also I found harware button interaction in TouchGFX Designer

0690X000008iLICQA2.png

I want to know how to use it, because it seems like it could be useful for me.

When I generated the code i found only this function:

//Handles when a key is pressed
void Screen2ViewBase::handleKeyEvent(uint8_t key)
{
    if(1 == key)
    {
        //Interaction1
        //When hardware button 1 clicked fade textArea2
        //Fade textArea2 to alpha:0 with LinearIn easing in 2000 ms (120 Ticks)
        textArea2.clearFadeAnimationEndedAction();
        textArea2.startFadeAnimation(0, 120, EasingEquations::linearEaseIn);
    }
}

So, how could I connect my hardware button to the function?

Thanks

Anton

1 ACCEPTED SOLUTION

Accepted Solutions
Martin KJELDSEN
Chief III

Hi @qqAnton​,

I understand your confusion. The designer indicates that this is somehow related to hardware which it isn't from a simulator perspective (Notice how the values are ASCII values - which means you can use your keyboard in the simulator to react to things. e.g. 48 for 0, 49 for 1). What you can do to hook this designer feature to your board is to use a ButtonController that reports simular values.

I will show you how to do this when i have a moment and i'll also show you how to react to a button press without the designer/ButtonController where you might have a separate OS Task to handle peripherals like buttons.

/Martin

View solution in original post

7 REPLIES 7
Martin KJELDSEN
Chief III

Hi @qqAnton​,

I understand your confusion. The designer indicates that this is somehow related to hardware which it isn't from a simulator perspective (Notice how the values are ASCII values - which means you can use your keyboard in the simulator to react to things. e.g. 48 for 0, 49 for 1). What you can do to hook this designer feature to your board is to use a ButtonController that reports simular values.

I will show you how to do this when i have a moment and i'll also show you how to react to a button press without the designer/ButtonController where you might have a separate OS Task to handle peripherals like buttons.

/Martin

Thank you for the answer, waiting your tutorials)

I have a little problem and dont wanna create a special topic for it, could you answer here.

I changed screen name from Screen2 to MainScreen,

0690X000008iM41QAE.png

but every time i click "Generate Code" in TouchGFX Designer, it generates old screen's folder and cpp file.

0690X000008iM67QAE.png

Project works fine If i delete the folder, but what should i do resolve the problem?

I guess it is my bad, but i still can not find what did i forget to change.

Thanks

Anton

Update:

Deleted Screen2.hpp and problem was resolved

MHugn.1
Associate

Hello @qqAnton​ and @Martin KJELDSEN​,

I have the same problem than you @qqAnton​. Is it possible to see your tutorial about the hardware button ?

Thanks a lot !

Mathieu

Thanks a lot @Martin KJELDSEN​ ! =)

I understand the global idea of your tutorial but I have some questions :

1) I understand that you created a "H7B3ButtonController" class from a "ButtonController" class. I understand the "init" and "sample" functions but where did you write the following code ? :

*****

...

H7B3ButtonController bc;

void touchgfx_init()

{

...

hal.initialize();

hal.setButtonController(&bc);

}

*****

2) What is the object "hal" ? Is it generated by TouchGFX Designer or I have to create this object ?

3) At the end you wrote in your tutorial : "To use a value sampled by the ButtonController in interactions from the TouchGFX designer a name/value-mapping must be created in the .touchgfx project file". I understand what you want to do but I can't find a file with ".touchgfx". The only ".touchgfx" I found is the one I can open in TouchGFXDesigner but I can't write in it, no? Where can I find it ?

I'm a beginner in TouchGFX (only 2 weeks of work), your answer will help me a lot 😀.

Mathieu

Great questions, @MHugn.1​, and i'll take your input as opportunities to update the documentation if something is not clear.

1) The TouchGFX configuration is located in a file called TouchGFXConfiguration. It should be in TouchGFX/target/generated/TouchGFXConfiguration.cpp. For the article i cheated a bit and a) modified TouchGFXConfiguration.cpp (which is read only) and i also defined the H7B3ButtonController class directly in the same file. I may change that for clarity.

2) HAL is the core Framework HAL. HAL.hpp is available to you but the code itself is inside the library. What the Generator does for you is _generate_ a subclass of HAL, TouchGFX HAL, in the same loaction as 1). The GeneratedHAL is read-only, but TouchGFXHAL is something you can modify as you wish.

3) The .touchgfx file is inside the TouchGFX folder. In fact, the TouchGFX folder is what you get when you use the Generator.

Hope this helps

/Martin

Martin,

I have these same questions. Where would you recommend we write the buttonController initialization code besides the read-only file (not practical if I am going to continue to edit the TGFX canvas, which I will). For what it's worth, I think clarification on this front would be helpful in the documentation.