V1/Toolbox.NETMF.Hardware.Port/RotaryEncoder.cs
/// <summary>
/// One of the pins has triggered an interrupt
/// </summary>
/// <param name="PinId">The Id of the pin</param>
/// <param name="Value">It's new value</param>
/// <param name="Time">Timestamp of the event</param>
One of the pins has triggered an interrupt
One of the pins has triggered an interrupt
private void _Pin_OnInterrupt(uint PinId, uint Value, DateTime Time)
        {
            bool CurrA = this._PinA.Read();
            bool CurrB = this._PinB.Read();
            this._Even = !this._Even;
            if (!this._Even)
            {
                this._OddA = CurrA;
                this._OddB = CurrB;
                return;
            }
            if (CurrA == this._OddA && CurrB == this._OddB)
                return;
            int delta;
            if (this._OddA && !CurrB)
                delta = -1;
            else if (this._OddA)
                delta = 1;
            else if (CurrB)
                delta = -1;
            else
                delta = 1;
            this.Value += delta;
        }
private void _Pin_OnInterrupt ( uint PinId , uint Value , DateTime Time ) { bool CurrA = this . _PinA . Read ( ) ; bool CurrB = this . _PinB . Read ( ) ; this . _Even = ! this . _Even ; if ( ! this . _Even ) { this . _OddA = CurrA ; this . _OddB = CurrB ; return ; } if ( CurrA == this . _OddA && CurrB == this . _OddB ) return ; int delta ; if ( this . _OddA && ! CurrB ) delta = - 1 ; else if ( this . _OddA ) delta = 1 ; else if ( CurrB ) delta = - 1 ; else delta = 1 ; this . Value += delta ; }
One of the pins has triggered an interrupt
One of the pins has triggered an interrupt
// Takes the last value // This is an odd measurement, we store the data so we can compare it with the measurement next time // Was there an actual change? // If pin A is high and pin B just went low, we're moving counterclockwise // If Pin A is high and pin B didn't went low, we're moving clockwise // If pin A was low and pin B just went high, we're moving counterclockwise // If pin A was low and pin B didn't went high, we're moving clockwise
PinId
uint
The Id of the pin
The Id of the pin
Value
uint
It's new value
It ' s new value
Time
DateTime
Timestamp of the event
Timestamp of the event