Charles Young's development fork. Going forward I only want to push mature code to main repository.
Fork of GEO_COUNTER_L432KC by
Diff: RotarySwitch.hpp
- Revision:
- 20:fb73eaaf0894
- Parent:
- 19:fd3e33641aa7
- Child:
- 24:db7494389c03
diff -r fd3e33641aa7 -r fb73eaaf0894 RotarySwitch.hpp --- a/RotarySwitch.hpp Tue Sep 04 08:28:34 2018 -0700 +++ b/RotarySwitch.hpp Tue Sep 04 19:57:31 2018 +0000 @@ -11,9 +11,10 @@ */ #include "mbed.h" #include "QEI.h" // Quadrature Encoder functions +#include "HwRegisters.hpp" /** - * Quadrature Encoder Interface. + * Code associated with rotary switch. */ class RotarySwitch { @@ -25,48 +26,19 @@ * @param channelA mbed pin for channel A input. * @param channelB mbed pin for channel B input. */ - RotarySwitch(PinName channelA, PinName channelB); + RotarySwitch(); - /** - * Reset the encoder. - * - * Sets the pulses and revolutions count to zero. - */ - void GetPosition(void); - -private: - - PinName channelA_; - PinName channelB_; - Ticker SecTenth_Beat; // .1 second ticker - Ticker Sec_Beat; // 1 second ticker + void UpdateOutput(); + void UpdateInput(); /** - * Defines + * Get the current position of switch. */ -#define CPM 0x01 -#define CPS 0x02 -#define PLS 0x04 -#define VOLTS 0x08 -#define CNT1 0x10 -#define CNT2 0x20 -#define HV 0x40 -#define MENU 0x80 - uint8_t LED_statuses[] = {CPM, CPS, PLS, VOLTS, CNT1, CNT2, HV, MENU}; - uint8_t LED_status = CPM; - uint8_t LED_status_index = 0; + int GetPosition(void); - DigitalIn QEPB (D9); // Quadrature encoder pushbutton +private: + static const int WheelStateTimeout = 5; //timeout for wheel button pushed - // QEI class supports the mode wheel. In its most basic function it will tell - // us which direction the wheel is moving (right or left) so that we can - // use it to select the current mode. - QEI Wheel(D12, D11, NC, 16); // Quadrature encoder - int WheelCurrent = 0; - int WheelPrevious = 0; - bool QEPBpressed = false; // only react to button when pressed - int WheelStateTimer = 0; - const int WheelStateTimeout = 5; //timeout for wheel button pushed enum WheelState { WHEEL_INACTIVE = 0, WHEEL_MODE_SELECT = 1, @@ -76,20 +48,20 @@ WHEEL_Pressed = 0, WHEEL_Timeout = 1 }; + WheelState currentWheelState; + uint8_t LED_status; + uint8_t LED_status_index; + int WheelCurrent; + int WheelPrevious; + bool QEPBpressed; // only react to button when pressed + int WheelStateTimer; /** - * Update the pulse count. - * - * Called on every rising/falling edge of channels A/B. - * - * Reads the state of the channels and determines whether a pulse forward - * or backward has occured, updating the count appropriately. + * Manage state machine */ void WheelStateMachine(WheelStateEvent event); - - void RotatySwitch::UpdateOutput(); - void RotatySwitch::UpdateInput(); + void LEDs_write(unsigned short data_val); }; #endif /* RotarySwitch_H */