Skip to content

rotary state machine may be suboptimal #22

@nettings

Description

@nettings
/* Yay. A bit-wise state machine :)
 *
 * State:
 *   nnnn
 *   |||+----> clk bit
 *   ||+-----> dt bit
 *   |+------> clockwise bit
 *   +-------> outer ring bit
 *
 * The clk and dt bits are set by interrupt handlers.
 * They can change rapidly when the switch hardware
 * bounces.
 *
 * Two rings:
 *  Outer        1100*_    _1000*
 *                /    \  /    \
 *  Inner        /     0x00     \
 *              |      /  \      |
 *            1101  0010  0101  1010
  *             |     |    |     |
 *               \  0011* 0111* /
 *                \    \  /    /
 *                 \___1x11___/ 
 *
 * The starred states will fire a callback.
 * Between two unstarred states, we tolerate bouncing.
 * A starred state cannot bounce back, because we 
 * change rings immediately, so that it cannot trigger 
 * again.
 * We need two firing states per ring, because
 * in the (clk == dt) case, we cannot tell which
 * direction we're going.
 */

Right now, CLOCKWISE is only updated when we pass a 01 or 10 state, i.e. when CLK and DT differ.
On 00 and 11 states, it remains unchanged. If we could "unset" it, we might be able to catch more invalid states, so the state machine might not be complete yet. It's very hard to trigger spurious directions changes already, but if they occur, then almost always in bursts of three or so.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions