示例#1
0
        private void Pin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
        {
            var dataValue  = dataPin.Pin.Read();
            var clockValue = clockPin.Pin.Read();

            var highCount = (dataValue == GpioPinValue.High ? 1 : 0) + (clockValue == GpioPinValue.High ? 1 : 0);

            if (highCount == (previousHighCount + 1))
            {
                if (previousHighCount == 0)
                {
                    direction = (dataValue == GpioPinValue.High) ? RotaryEncoderDirection.Anticlockwise : RotaryEncoderDirection.Clockwise;
                }

                previousHighCount = highCount;
            }
            else if (previousHighCount == 2 && highCount == 1)
            {
                RaiseEventHelper.CheckRaiseEventOnUIThread(this, Rotate, new RotaryEncoderEventArgs(direction), RaiseEventsOnUIThread);
                previousHighCount = 0;
            }
            else
            {
                previousHighCount = 0;
            }
        }
示例#2
0
 public RotaryEncoderEventArgs(RotaryEncoderDirection direction)
 {
     Direction = direction;
 }
示例#3
0
 public RotaryEncoderEventArgs(RotaryEncoderDirection direction)
 {
     Direction = direction;
 }