2020-02-23 12:51 PM
Hello,
I have to send send the status of one flexbutton(even a group of flexbuttons...) to a communication task.
I created a Queue in Model.cpp via the Vien-Presenter chain. And while the button is pressed com task receives '1'. So far so good.
But what I want is to send is the pressed status but also released, because it could be used for actuator.
The status could be send one time or multiple time.
I tried a solution with 3 interactions:
1.Button is clicked call virtual function
2.Timer
3.When timer is done call the same virtual function.
In the virtual function, I check the button status with getPressed() function.
But this method doesn't always work.
Is there a more elegant method to do this?
Pierre
2020-02-23 01:26 PM
Please review and test the methods described here:
https://touchgfx.zendesk.com/hc/en-us/articles/360018095132-Button?mobile_site=true
2020-02-23 11:41 PM
Thank you Mon2 for your answer but in the example I didn't find the method to get the Pressed and Release state.
I tried with TRIGGER as touch or repeat but no success.
I don't know if I can add a polling virtual function that runs continously with getPressed() for all of the buttons on the screen.
Thank you,
Pierre
2020-02-24 12:16 AM
What do you mean by "The method doesn't always work" ?
How did you make it work for when the button is being pressed? You should be able to do the exact same thing for released?
I'd create a subclass and overwrite the internal handler that sends the pressed callback to also support a released callback. If you create your own handler, then you can also modify it to support a "long press" as you described - To send a signal every x seconds the button is being held down.
/Martin
2020-02-24 02:25 AM
Hi Martin,
I mean that sometimes I get the new status of the button, sometimes not.
This is the virtual function for my screen:
void MainView::sendstate()
{
boutonState = flexButton1.getPressed();
presenter->sendstate(boutonState);
}
As mentionned above, there is an interaction with a timer that calls 'sendstate()' again after a period to check if the button is released, but not really good.
Is there an example on how to create a subclass and add it to the project?
Thank you,
Pierre
2020-02-24 04:54 AM
Simply inherit from FlexButton:
class MyButton : public FlexButton
{
public:
MyButton();
....
};
Since this is not accessible through the designer, simply add this widget to your screen in the user code version of your screen class. Add it to your project for compilation. Does that make sense?
class MainView : public MainViewBase
{
public:
MainView();
virtual ~MainView() {}
virtual void setupScreen();
virtual void tearDownScreen();
private:
MyButton button;
};
...
void MainView::setupScreen()
{
add(button);
}
/Martin
2020-02-25 05:40 AM
Another possibility that is not very clean but works is shown in following community thread ;
Basically you create your own Button class based on the implementation of a Flex Button. Some code is shown if you click the link above.
/Alexandre
2020-02-25 01:15 PM
Hi Alexandre,
Thank you for your code.
I tried it and it works. I have a question and I will ask in the other thread.
It would nice if this function was native in the future.
Pierre
2023-11-20 03:55 AM
Hi PCu1,
Are you able to read the status of the flexbutton ?
You manged to get it working ?
Possible to share your solution.
Thanks in advance.