mcanet/knitic — pull request #22 by sconklin (2013-03-29 21:22:42+00:00)
Title: Handle encoders with a state machine

Differences between the old and new encoder methods:

Old code used string compares, New code uses an arrary lookup

Old code:

1. Tracked each change in the encoder signals
as a movement in a direction
2. Accepted two movements in the same direction as
movement in that direction.
3. Divided the number of changes by four to get a position

4. Old encoder made changes according to this table, which
treats "no change" conditions 00 and 11 as movement (*).
//directionEncoders +=_8segmentEncoder;
// head direction
// old new result old new
// 00 00 +1 0 0 (*)
// 00 10 +1 0 2
// 10 11 +1 2 3
// 11 01 +1 3 1
// 01 00 +1 1 0
//
// 01 11 -1 1 3
// 11 11 -1 3 3 (*)
// 11 10 -1 3 2
// 10 00 -1 2 0
// 00 01 -1 0 1

New Code:

1. Counts each cycle through all 4 encoder values as a
movement in a direction
2. Is able to declare a direction after one cycle
3. Does not divide by four to get a position
4. No movement is counted if input signals do not change

General Changes:

Used unsigned char where possible to save memory

Signed-off-by: Steve Conklin