Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1702 | - | 1 | #ifndef __CONTROLS_H__ |
2 | #define __CONTROLS_H__ |
||
3 | |||
4 | #include <inttypes.h> |
||
5 | #include <avr/pgmspace.h> |
||
6 | |||
7 | class StateMachine |
||
8 | { |
||
9 | static StateMachine *currentState; |
||
10 | |||
11 | protected: |
||
12 | virtual bool OnInitialState() { return true; }; |
||
13 | |||
14 | public: |
||
15 | static void SetState(StateMachine *state) { currentState = state; currentState->OnInitialState(); }; |
||
16 | static StateMachine* GetState() { return StateMachine::currentState; }; |
||
17 | }; |
||
18 | |||
19 | class ControlEvents : public StateMachine |
||
20 | { |
||
21 | public: |
||
22 | virtual bool OnEncoderChanged(int8_t value) { return true; }; |
||
23 | virtual bool OnEncButtonUp() { return true; }; |
||
24 | virtual bool OnEncButtonDown() { return true; }; |
||
25 | virtual bool OnExtButtonUp() { return true; }; |
||
26 | virtual bool OnExtButtonDown() { return true; }; |
||
27 | }; |
||
28 | |||
29 | #define GPIN_ENCODER_MASK 0x03 |
||
30 | #define GPIN_ENC_BUT_MASK 0x08 |
||
31 | #define GPIN_EXT_BUT_MASK 0x10 |
||
32 | |||
33 | #define GPIN_ENC_BUT_MASK 0x04 |
||
34 | #define GPIN_EXT_BUT_MASK 0x08 |
||
35 | |||
36 | |||
37 | typedef uint8_t ControlStates; |
||
38 | |||
39 | class GPInRegister |
||
40 | { |
||
41 | ControlStates controlStates; |
||
42 | MAX3421E *pMax; |
||
43 | int8_t encoderValue; |
||
44 | |||
45 | public: |
||
46 | GPInRegister(MAX3421E *pmax) : controlStates(GPIN_ENCODER_MASK | GPIN_ENC_BUT_MASK | GPIN_EXT_BUT_MASK), pMax(pMax), encoderValue(0) {}; |
||
47 | void CheckControls(); |
||
48 | }; |
||
49 | |||
50 | #endif // __CONTROLS_H__ |