Button multiclick prevented

Hi
I add some filtering in FT5xx6 library to prevent firing many events on single touch.
Also found that the flags were wrongly assigned to the touch types.

it is now: flag = 0 for TouchDown ; flag = 1 for TouchUp ; flag = 2 for TouchMove
but it should be: flag = 0 for TouchMove; flag = 1 for TouchUp; flag = 2 for TouchDown:

Partial code with my filters and corrected flags assignment:

        try
        {
            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];

               //multitouch filter

                if (flag==touchFlag && Math.Abs(x - filterX)<8 && Math.Abs(y - filterY) < 8 && (DateTime.Now.Ticks-touchTimeStamp)< TimeSpan.TicksPerSecond )
                return; 

                else
                if (x!=4095 && y!=4095)
                {
                   filterX = x;
                    filterY = y;
                    touchTimeStamp = DateTime.Now.Ticks;
                    touchFlag = flag;
                }

                if (this.Orientation != TouchOrientation.Degrees0)
                {
                    // Need width, height to know do swap x,y
                    if (this.Width == 0 || this.Height == 0)
                    {
                        //this.interrupt.ValueChanged += this.OnInterrupt;
                        return;

                    }

                    switch (this.Orientation)
                    {
                        case TouchOrientation.Degrees180:
                            x = this.Width - x;
                            y = this.Height - y;
                            break;

                        case TouchOrientation.Degrees270:
                            var temp = x;
                            x = this.Width - y;
                            y = temp;

                            break;

                        case TouchOrientation.Degrees90:
                            var tmp = x;
                            x = y;
                            y = this.Width - tmp;
                            break;
                    }
                }

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

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

                if (flag == 3)
                    break;
            }
        }
        catch
        {
            
            return; // Don't stop main application
        }

Can you clarify which repo please? It is better to post this on GitHub so it is not lost. Thanks

This is touch driver TinyCLR-Drivers/FocalTech/ FT5xx6 /

@Dat_Tran what do you think?

For “prevent firing many events”, I think just need to increase debouce time interrupt pin.

For flag, we will confirm soon. Thanks