Subversion Repositories Projects

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1702 - 1
#include <Max3421e.h>
2
#include "controls.h"
3
 
4
StateMachine* StateMachine::currentState = NULL;
5
 
6
void GPInRegister::CheckControls()
7
{
8
    int8_t           enc_states[]    = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};
9
    ControlStates    previous        = controlStates;
10
                     controlStates   = (pMax->gpioRd() & (GPIN_ENCODER_MASK | GPIN_ENC_BUT_MASK | GPIN_EXT_BUT_MASK));
11
    ControlStates    changes         = (previous ^ controlStates);
12
 
13
    if (previous == controlStates)
14
        return;
15
 
16
    ControlEvents *state_machine = (ControlEvents*)StateMachine::GetState();
17
 
18
    if ((changes & GPIN_ENCODER_MASK))
19
    {
20
        uint8_t  encoder = (previous & GPIN_ENCODER_MASK);
21
        encoder     <<= 2;
22
        encoder     |= (controlStates & GPIN_ENCODER_MASK);
23
        encoderValue += enc_states[(encoder & 0x0f)];
24
 
25
        if (encoderValue > 3 || encoderValue < -3)
26
        {
27
            if (state_machine)
28
                state_machine->OnEncoderChanged(encoderValue >> 2);
29
            encoderValue = 0;
30
        }
31
    }
32
    if (!state_machine)
33
        return;
34
 
35
    if ((changes & GPIN_ENC_BUT_MASK))
36
    {
37
        if ((controlStates & GPIN_ENC_BUT_MASK))
38
            state_machine->OnEncButtonUp();
39
        else
40
            state_machine->OnEncButtonDown();
41
    }
42
    if ((changes & GPIN_EXT_BUT_MASK))
43
    {
44
        if ((controlStates & GPIN_EXT_BUT_MASK))
45
            state_machine->OnExtButtonUp();
46
        else
47
            state_machine->OnExtButtonDown();
48
    }
49
}
50