cancel
Showing results for 
Search instead for 
Did you mean: 

Missing ClickEvent::RELEASED event on Button

DPerr.2216
Associate II

Hi,

I'm struggling with a missing event in my application.

As far as I can see, the touch HW is generating the touch event, the touch controller's "sampleTouch" method is signalling the event to the library correctly, the view is detecting the PRESSED and RELEASED events but the button on the view very often misses the RELEASED event on which I rely to handle the event.

I have added debug messages to try an pinpoint the issue.

The printout is attached with my comments.

So, finally, my question is:

How can I guarantee I catch the RELEASED event from the button?

I'm currently using library version 4.9.3 running on a STM32F767 processor with a 320*240 touch display for which I have implemented the low level, it is not one of the evaluation boards.

Thanks,

Daniel

12 REPLIES 12
DPerr.2216
Associate II

I'd like to add another observation regarding the issue.

The view containing the button has some more graphical elements.

In particular, it has two elements which are containers holding a single TextAreaWithTwoWildcards and a box to paint a background behind the text.

These two elements are updated every second with dynamic data.

If I remove these two elements, the button behaves as expected.

When present it seems as if they somehow take the focus from the button while it is pressed resulting in it missing the RELEASED event.

Does this make sense? Is it the expected behavior or a bug and how can I overcome it?

Thanks!

belair55
Associate III

I am doing something similar. I am not sure how clickEvent gets called but the way I approached this was through using callbacks.

For my button I set up a callback and a callback handler. Directly initialize with the constructor. In setupScreen for a view I use setclickaction method for the button and give it the callback for the button.

Then in my callback handler I make sure the clicked object was the correct type and that it was a release. After that condition is met I execute the behavior of the buttons action.

ST has some examples like this as well.​

DPerr.2216
Associate II

Hi,

Thanks for your comment.

My code does include the callback setup. It does get called when the button receives the RELEASED event. The problem is when the RELEASED event is not received. In this case the callback is not called, either. I assume the button's implementation include an "onChange" mechanism in which the callback is called only once when the "pressed" state changes from PRESSED to RELEASED.

Martin KJELDSEN
Chief III

Buttons which are added to the root container on the screen will receive touch coordinates if they intersect with that touch coordinate. Can you debug inside handleClickEvent() of AbstractButton (Button inherits from this). Check if this method is getting called when you release.

#include <touchgfx/widgets/AbstractButton.hpp>
 
namespace touchgfx
{
void AbstractButton::handleClickEvent(const ClickEvent& event)
{
    bool wasPressed = pressed;
    pressed = (event.getType() == ClickEvent::PRESSED);
    if ((pressed && !wasPressed) || (!pressed && wasPressed))
    {
        // Pressed state changed, so invalidate
        invalidate();
    }
    if (wasPressed && (event.getType() == ClickEvent::RELEASED) && action)
    {
        // This is a click. Fire callback.
        if (action->isValid())
        {
            action->execute(*this);
        }
    }
}
} // namespace touchgfx

What TouchGFX HAL does is to determine (if a touch is not detected) whether or not a touch was just recorded, in which case it will send a very specific RELEASED event to the active view based on the last known coordinates.

gestures.registerClickEvent(ClickEvent::RELEASED, lastX, lastY);

/Martin

DPerr.2216
Associate II

Hi Martin,

I added your code to the project with some more prints in it to track the touches. See the trace below:

16:34:31.585 - Touch coordinates: 193,216

16:34:31.585 - Touch Result: TRUE

16:34:31.585 - POSButton Pressed: 193,216

16:34:31.585 - Abstract button pressed by library: 133,031

(The difference in coordinates here is the fact that I translated the POSButton's coordinates to the view's coordinates to match the data to the clicks on the view)

16:34:31.585 - Main Pressed: 193,216

16:34:31.618 - POSButton state changed to Pressed

16:34:32.001 - POSButton dragged: old - 193,216 new - 194, 216

16:34:32.001 - Main dragged: old - 193,216 new - 194, 216

16:34:32.015 - POSButton dragged: old - 194,216 new - 195, 215

16:34:32.015 - Main dragged: old - 194,216 new - 195, 215

16:34:32.031 - POSButton dragged: old - 195,215 new - 197, 215

16:34:32.031 - Main dragged: old - 195,215 new - 197, 215

16:34:32.047 - POSButton dragged: old - 197,215 new - 198, 215

16:34:32.047 - Main dragged: old - 197,215 new - 198, 215

16:34:32.986 - Touch Result: FALSE

16:34:32.986 - POS Button coordinates: 060,185,270,230

16:34:32.986 - I think I saw a touch...

16:34:32.986 - Main Released: 198,215

16:35:12.180 - Touch coordinates: 122,220

16:35:12.180 - Touch Result: TRUE

16:35:12.180 - POSButton Pressed: 122,220

16:35:12.180 - Abstract button pressed by library: 062,035

16:35:12.180 - Main Pressed: 122,220

16:35:12.355 - Touch Result: FALSE

16:35:12.355 - POS Button coordinates: 060,185,270,230

16:35:12.355 - I think I saw a touch...

16:35:12.355 - Main Released: 122,220

16:35:12.673 - Touch coordinates: 126,213

16:35:12.674 - Touch Result: TRUE

16:35:12.674 - POSButton Pressed: 126,213

16:35:12.674 - Abstract button pressed by library: 066,028

16:35:12.674 - Main Pressed: 126,213

16:35:12.912 - Touch Result: FALSE

16:35:12.912 - POSButton Released normally: 126,213

16:35:12.912 - Abstract button released by library: 066,028

16:35:12.912 - POS Button coordinates: 060,185,270,230

16:35:12.912 - I think I saw a touch...

16:35:12.913 - Main Released: 126,213

16:35:12.944 - POSButton state changed to Released

As far as I can see the first group indicates the button was pressed, the main detects the release bur neither the inherited nor the abstract button receive the event.

The same happens with the second group of traces.

The third finally captures the release event and changes state.

Still looks as if, for some reason, something blocks the release event from reaching the button.

Regards,

Daniel

Martin KJELDSEN
Chief III

Okay, i just have to get this thought out of my head before returning to the issue at hand:

If you have a button that moves across the screen really fast (For whatever odd reason) or changes position drastically, lastX and lastY might miss the "target" if you release the button before your finger is no longer in "contact" with it, and a CANCEL event is sent. In this case you would not receive your RELEASED event. But the state of the button _might_ be pressed still.

Sort of related.

/Martin

DPerr.2216
Associate II

No, the button is completely static. As I mentioned in the second post, the only dynamic data items on the view are two textArea drawables. They, too, are not moving, only updating their string value. In any case, the trace prints will print a cancel event, if it occurs. I did happen a couple of times if I pressed the button and then swiped out of the button area but not in the latest trace.

Martin KJELDSEN
Chief III

I know, it would be silly to have it moving around, but because of lastX and lastY it was just a general thought, not related to your problem.

Martin KJELDSEN
Chief III

What's your touch sample rate configured to?