Exemplo n.º 1
0
        protected override bool ProcessEventInternal(string cmd, string com, int idx, int val)
        {
            if (!"BUTTON".Equals(com, StringComparison.InvariantCultureIgnoreCase))
            {
                return(false);
            }

            bool ret = true;
            var  old = Pressed;

            switch (cmd?.ToUpperInvariant())
            {
            default: ret = false;
                break;

            case "PRESSED":
                Pressed = true;
                break;

            case "RELEASED":
                Pressed = false;
                break;
            }
            if (ret && old != Pressed)
            {
                PressedChanged?.Invoke(this, new ButtonChangedEventArgs(Pressed));
            }
            return(ret);
        }
Exemplo n.º 2
0
        private void Callback(object _, PinValueChangedEventArgs pinValueChangedEventArgs)
        {
            switch (pinValueChangedEventArgs.ChangeType)
            {
            case PinEventTypes.Rising:
                IsPressed = false;
                Released?.Invoke(this, EventArgs.Empty);
                break;

            case PinEventTypes.Falling:
                IsPressed = true;
                Pressed?.Invoke(this, EventArgs.Empty);
                break;
            }
            PressedChanged?.Invoke(this, IsPressed);
        }
        private void OnPressedChanged()
        {
            PressedChanged?.Invoke(this, this.IsPressed);

            // Don't execute the command on release

            if (IsPressed)
            {
                FireCommand();
            }
            else
            {
                // TODO I'm not sure if it executes on the "Release" correctly
                // try to do: click -> keep mouse down for a while -> release
                if (ExecuteOnPressAndRelease)
                {
                    FireCommand();
                }
            }
        }
Exemplo n.º 4
0
 public virtual void OnPressedChanged()
 {
     PressedChanged.Invoke(this);
 }
Exemplo n.º 5
0
        protected override bool ProcessEventInternal(string cmd, string com, int idx, int val)
        {
            if ("ENCODER".Equals(com, StringComparison.InvariantCultureIgnoreCase))
            {
                bool ret = true;
                switch (cmd?.ToUpperInvariant())
                {
                default: ret = false;
                    break;

                case "TURNED_RIGHT":
                    TurnedRight?.Invoke(this, EventArgs.Empty);
                    break;

                case "TURNED_LEFT":
                    TurnedLeft?.Invoke(this, EventArgs.Empty);
                    break;
                }
                return(ret);
            }

            if ("BUTTON".Equals(com, StringComparison.InvariantCultureIgnoreCase))
            {
                var  old = idx == TouchIndex ? Touched : Pressed;
                bool ret = true;
                switch (cmd?.ToUpperInvariant())
                {
                default:
                    ret = false;
                    break;

                case "PRESSED":
                    if (idx == TouchIndex)
                    {
                        Touched = true;
                    }
                    else
                    {
                        Pressed = true;
                    }
                    break;

                case "RELEASED":
                    if (idx == TouchIndex)
                    {
                        Touched = false;
                    }
                    else
                    {
                        Pressed = false;
                    }
                    break;
                }

                if (ret)
                {
                    if (idx == TouchIndex)
                    {
                        if (old != Touched)
                        {
                            TouchedChanged?.Invoke(this, new ButtonChangedEventArgs(Touched));
                        }
                    }
                    else if (old != Pressed)
                    {
                        PressedChanged?.Invoke(this, new ButtonChangedEventArgs(Pressed));
                    }
                }

                return(ret);
            }

            return(false);
        }