Charles Young's development fork. Going forward I only want to push mature code to main repository.
Fork of GEO_COUNTER_L432KC by
RotarySwitch.hpp@20:fb73eaaf0894, 2018-09-04 (annotated)
- Committer:
- charlesdavidyoung
- Date:
- Tue Sep 04 19:57:31 2018 +0000
- Revision:
- 20:fb73eaaf0894
- Parent:
- 19:fd3e33641aa7
- Child:
- 24:db7494389c03
Encapsulated rotary switch and associated LEDs code in a new class.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Charles David Young |
19:fd3e33641aa7 | 1 | /** |
Charles David Young |
19:fd3e33641aa7 | 2 | * @author Charles Young |
Charles David Young |
19:fd3e33641aa7 | 3 | * This class encapsulates the behavior of the rotary switch to change modes |
Charles David Young |
19:fd3e33641aa7 | 4 | */ |
Charles David Young |
19:fd3e33641aa7 | 5 | |
Charles David Young |
19:fd3e33641aa7 | 6 | #ifndef RotarySwitch_H |
Charles David Young |
19:fd3e33641aa7 | 7 | #define RotarySwitch_H |
Charles David Young |
19:fd3e33641aa7 | 8 | |
Charles David Young |
19:fd3e33641aa7 | 9 | /** |
Charles David Young |
19:fd3e33641aa7 | 10 | * Includes |
Charles David Young |
19:fd3e33641aa7 | 11 | */ |
Charles David Young |
19:fd3e33641aa7 | 12 | #include "mbed.h" |
Charles David Young |
19:fd3e33641aa7 | 13 | #include "QEI.h" // Quadrature Encoder functions |
charlesdavidyoung | 20:fb73eaaf0894 | 14 | #include "HwRegisters.hpp" |
Charles David Young |
19:fd3e33641aa7 | 15 | |
Charles David Young |
19:fd3e33641aa7 | 16 | /** |
charlesdavidyoung | 20:fb73eaaf0894 | 17 | * Code associated with rotary switch. |
Charles David Young |
19:fd3e33641aa7 | 18 | */ |
Charles David Young |
19:fd3e33641aa7 | 19 | class RotarySwitch { |
Charles David Young |
19:fd3e33641aa7 | 20 | |
Charles David Young |
19:fd3e33641aa7 | 21 | public: |
Charles David Young |
19:fd3e33641aa7 | 22 | |
Charles David Young |
19:fd3e33641aa7 | 23 | /** |
Charles David Young |
19:fd3e33641aa7 | 24 | * Constructor. |
Charles David Young |
19:fd3e33641aa7 | 25 | * |
Charles David Young |
19:fd3e33641aa7 | 26 | * @param channelA mbed pin for channel A input. |
Charles David Young |
19:fd3e33641aa7 | 27 | * @param channelB mbed pin for channel B input. |
Charles David Young |
19:fd3e33641aa7 | 28 | */ |
charlesdavidyoung | 20:fb73eaaf0894 | 29 | RotarySwitch(); |
Charles David Young |
19:fd3e33641aa7 | 30 | |
charlesdavidyoung | 20:fb73eaaf0894 | 31 | void UpdateOutput(); |
charlesdavidyoung | 20:fb73eaaf0894 | 32 | void UpdateInput(); |
Charles David Young |
19:fd3e33641aa7 | 33 | |
Charles David Young |
19:fd3e33641aa7 | 34 | /** |
charlesdavidyoung | 20:fb73eaaf0894 | 35 | * Get the current position of switch. |
Charles David Young |
19:fd3e33641aa7 | 36 | */ |
charlesdavidyoung | 20:fb73eaaf0894 | 37 | int GetPosition(void); |
Charles David Young |
19:fd3e33641aa7 | 38 | |
charlesdavidyoung | 20:fb73eaaf0894 | 39 | private: |
charlesdavidyoung | 20:fb73eaaf0894 | 40 | static const int WheelStateTimeout = 5; //timeout for wheel button pushed |
Charles David Young |
19:fd3e33641aa7 | 41 | |
Charles David Young |
19:fd3e33641aa7 | 42 | enum WheelState { |
Charles David Young |
19:fd3e33641aa7 | 43 | WHEEL_INACTIVE = 0, |
Charles David Young |
19:fd3e33641aa7 | 44 | WHEEL_MODE_SELECT = 1, |
Charles David Young |
19:fd3e33641aa7 | 45 | WHEEL_SUBMODE_SELECT = 2 |
Charles David Young |
19:fd3e33641aa7 | 46 | }; |
Charles David Young |
19:fd3e33641aa7 | 47 | enum WheelStateEvent { |
Charles David Young |
19:fd3e33641aa7 | 48 | WHEEL_Pressed = 0, |
Charles David Young |
19:fd3e33641aa7 | 49 | WHEEL_Timeout = 1 |
Charles David Young |
19:fd3e33641aa7 | 50 | }; |
charlesdavidyoung | 20:fb73eaaf0894 | 51 | |
Charles David Young |
19:fd3e33641aa7 | 52 | WheelState currentWheelState; |
charlesdavidyoung | 20:fb73eaaf0894 | 53 | uint8_t LED_status; |
charlesdavidyoung | 20:fb73eaaf0894 | 54 | uint8_t LED_status_index; |
charlesdavidyoung | 20:fb73eaaf0894 | 55 | int WheelCurrent; |
charlesdavidyoung | 20:fb73eaaf0894 | 56 | int WheelPrevious; |
charlesdavidyoung | 20:fb73eaaf0894 | 57 | bool QEPBpressed; // only react to button when pressed |
charlesdavidyoung | 20:fb73eaaf0894 | 58 | int WheelStateTimer; |
Charles David Young |
19:fd3e33641aa7 | 59 | |
Charles David Young |
19:fd3e33641aa7 | 60 | /** |
charlesdavidyoung | 20:fb73eaaf0894 | 61 | * Manage state machine |
Charles David Young |
19:fd3e33641aa7 | 62 | */ |
Charles David Young |
19:fd3e33641aa7 | 63 | void WheelStateMachine(WheelStateEvent event); |
charlesdavidyoung | 20:fb73eaaf0894 | 64 | void LEDs_write(unsigned short data_val); |
Charles David Young |
19:fd3e33641aa7 | 65 | }; |
Charles David Young |
19:fd3e33641aa7 | 66 | |
Charles David Young |
19:fd3e33641aa7 | 67 | #endif /* RotarySwitch_H */ |