Charles Young's development fork. Going forward I only want to push mature code to main repository.

Dependencies:   mbed

Fork of GEO_COUNTER_L432KC by Geo Electronics "Geo Counter"

Committer:
charlesdavidyoung
Date:
Sun Oct 07 13:13:53 2018 +0000
Revision:
80:5770804da1b0
Parent:
42:204c99cf3fde
get rid of pulldown

Who changed what in which revision?

UserRevisionLine numberNew 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 24:db7494389c03 31 void UpdateOutput();
charlesdavidyoung 24:db7494389c03 32 float 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;
Charles David Young 42:204c99cf3fde 55 static const uint8_t LED_status_index_size = 8;
Charles David Young 38:1642320d83a0 56 uint8_t LED_status_reported;
charlesdavidyoung 20:fb73eaaf0894 57 int WheelCurrent;
charlesdavidyoung 20:fb73eaaf0894 58 int WheelPrevious;
charlesdavidyoung 20:fb73eaaf0894 59 bool QEPBpressed; // only react to button when pressed
charlesdavidyoung 20:fb73eaaf0894 60 int WheelStateTimer;
Charles David Young 19:fd3e33641aa7 61
Charles David Young 19:fd3e33641aa7 62 /**
charlesdavidyoung 20:fb73eaaf0894 63 * Manage state machine
Charles David Young 19:fd3e33641aa7 64 */
Charles David Young 19:fd3e33641aa7 65 void WheelStateMachine(WheelStateEvent event);
charlesdavidyoung 20:fb73eaaf0894 66 void LEDs_write(unsigned short data_val);
Charles David Young 19:fd3e33641aa7 67 };
Charles David Young 19:fd3e33641aa7 68
Charles David Young 19:fd3e33641aa7 69 #endif /* RotarySwitch_H */