Esempio n. 1
0
        public void Process(int raw)
        {
            if (TapQueued)
            {
                Console.WriteLine("Tap queued at start...");
            }

            bool wasPressed = Pressed;
            bool isPressed  = (raw != 0);

            if (Raw != null && Raw.AcceptAnalog)
            {
                Raw.Analog(raw);
            }

            if (wasPressed != isPressed)
            {
                if (isPressed)
                {
                    // Pressed
                    if (PressReceived != null)
                    {
                        PressReceived(this, EventArgs.Empty);
                    }
                    if (Link != null)
                    {
                        Link.Press(Intensity);
                    }
                }
                else
                {
                    // Released
                    Held = false;

                    if (ReleaseReceived != null)
                    {
                        ReleaseReceived(this, EventArgs.Empty);
                    }
                    if (Link != null)
                    {
                        Link.Release(Intensity);
                    }

                    if (EnableGestures && PressedStamp + new TimeSpan(0, 0, 0, 0, Core.TapTimeout) > DateTime.Now)
                    {
                        // Tap

                        if (DoubleTap != null)
                        {
                            if (TapQueued && TapStamp + new TimeSpan(0, 0, 0, 0, Core.DoubleTapTimeout) > DateTime.Now)
                            {
                                // Second tap
                                Console.WriteLine("Double Tap!");
                                DoubleTap.Activate(Intensity);
                                TapStamp  = DateTime.Now;
                                TapQueued = false;
                            }
                            else if (!TapQueued)
                            {
                                // First tap
                                TapStamp  = DateTime.Now;
                                TapQueued = true;
                                Console.WriteLine("Tap! [queued]");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Tap!");
                            if (Tap != null)
                            {
                                Tap.Activate(Intensity);
                            }
                        }
                    }
                }

                Pressed      = isPressed;
                PressedStamp = DateTime.Now;
            }

            if (TapQueued)
            {
                Console.WriteLine("Tap queued in middle...");
            }

            if (EnableGestures && TapQueued && TapStamp + new TimeSpan(0, 0, 0, 0, Core.DoubleTapTimeout) < DateTime.Now)
            {
                Console.WriteLine("Real Tap!");
                if (Tap != null)
                {
                    Tap.Activate(Intensity);
                }
                TapQueued = false;
            }

            if (isPressed)
            {
                if (Link != null)
                {
                    Link.Active(Intensity);
                }

                if (EnableGestures && !Held && PressedStamp + new TimeSpan(0, 0, 0, 0, Core.HoldTimeout) <= DateTime.Now)
                {
                    Console.WriteLine("Hold!");
                    if (Hold != null)
                    {
                        Hold.Activate(Intensity);
                    }
                    Held = true;
                }
            }

            if (TapQueued)
            {
                Console.WriteLine("Tap queued at end...");
            }
        }