Touch handling

I am trying to implement a ‘hold’ function on the touchscreen. This is the touch handler interrupt:

    private void OnInterrupt(GpioPin sender, GpioPinValueChangedEventArgs e)
    {
        var points = this.ReadData(2, this.read1)[0];

        for (var i = 0; i < points; i++)
        {
            var data = this.ReadData(i * 6 + 3, this.read4);
            var flag = (data[0] & 0xC0) >> 6;
            var x = ((data[0] & 0x0F) << 8) | data[1];
            var y = ((data[2] & 0x0F) << 8) | data[3];

            (flag == 0 ? TouchDown : flag == 1 ? TouchUp : flag == 2 ? TouchMove : null)?.Invoke(this, new TouchEventArgs(x, y));
        }
    }

I found that ‘TouchUp’ is never called. ( I do get the touchdown and touchmove) Has that been implemented ?

Any recommendations for handling a touch ‘hold’ function?

This touch controller is tricky. We have made improvements that should be in GitHub.

The touch up happens after the touch count goes down, which is why you won’t see it in the old driver.

Where is it on GitHub ?

I found it and implemented it. The touch up works and I have implemented the ‘hold’ function. thanks

1 Like

I notice that the new driver has gestures. I have not been able to see a gesture event. What do I need to do ?

Just subscribe to the gesture event. It should work.

set breakpoint in the driver:

    private void OnInterrupt(GpioPin sender, GpioPinValueChangedEventArgs e)
    {
        this.i2c.WriteRead(this.addressBuffer, 0, 1, this.read32, 0, this.SampleCount * 6 + 2);

        if (this.read32[1] != 0 && this.GestureReceived != null)
            this.GestureReceived(this, new GestureEventArgs((Gesture)this.read32[1]));

        //We do not read the TD_STATUS register because it returns a touch count _excluding_ touch up events, even though the touch registers contain the proper touch up data.
        for (var i = 0; i < this.SampleCount; i++)
        {
            var idx = i * 6 + 3;
            var flag = (this.read32[0 + idx] & 0xC0) >> 6;
            var x = ((this.read32[0 + idx] & 0x0F) << 8) | this.read32[1 + idx];
            var y = ((this.read32[2 + idx] & 0x0F) << 8) | this.read32[3 + idx];

            (flag == 0 ? this.TouchDown : flag == 1 ? this.TouchUp : flag == 2 ? this.TouchMove : null)?.Invoke(this, new TouchEventArgs(x, y));

            if (flag == 3)
                break;
        }
    }

this.gesturereceivied

but does not hit the breakpoint.

I should see a gesture by moving my finger on the screen ???
(

Give it the fingers :rofl:

1 Like

setup the handler:
// gesture: register handler
touch.GestureReceived += (_, e) =>
{
G.screen.FillEllipse(G.RedBrush, 600, 200, 50, 50);

        };