charles young / Mbed 2 deprecated GEO_COUNTER_L432KC

Dependencies:   mbed

Fork of GEO_COUNTER_L432KC by Geo Electronics "Geo Counter"

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RotarySwitch.hpp Source File

RotarySwitch.hpp

00001 /**
00002  * @author Charles Young
00003  * This class encapsulates the behavior of the rotary switch to change modes
00004  */
00005 
00006 #ifndef RotarySwitch_H
00007 #define RotarySwitch_H
00008 
00009 /**
00010  * Includes
00011  */
00012 #include "mbed.h"
00013 #include "QEI.h"        // Quadrature Encoder functions
00014 #include "HwRegisters.hpp"
00015 
00016 /**
00017  * Code associated with rotary switch.
00018  */
00019 class RotarySwitch {
00020 
00021 public:
00022 
00023    /**
00024     * Constructor.
00025     *
00026     * @param channelA mbed pin for channel A input.
00027     * @param channelB mbed pin for channel B input.
00028     */
00029    RotarySwitch();
00030 
00031    void  UpdateOutput();
00032    float UpdateInput();
00033 
00034    /**
00035     * Get the current position of switch.
00036     */
00037    int GetPosition(void);
00038 
00039 private:
00040    static const int WheelStateTimeout = 5; //timeout for wheel button pushed
00041 
00042    enum WheelState {
00043       WHEEL_INACTIVE       = 0,
00044       WHEEL_MODE_SELECT    = 1,
00045       WHEEL_SUBMODE_SELECT = 2
00046    };
00047    enum WheelStateEvent {
00048       WHEEL_Pressed = 0,
00049       WHEEL_Timeout = 1
00050    };
00051    
00052    WheelState currentWheelState;
00053    uint8_t LED_status;
00054    uint8_t LED_status_index;
00055    static const uint8_t LED_status_index_size = 8;
00056    uint8_t LED_status_reported;
00057    int WheelCurrent;
00058    int WheelPrevious;
00059    bool QEPBpressed; // only react to button when pressed
00060    int WheelStateTimer;
00061 
00062    /**
00063     * Manage state machine
00064     */
00065    void WheelStateMachine(WheelStateEvent event);
00066    void LEDs_write(unsigned short data_val);
00067 };
00068 
00069 #endif /* RotarySwitch_H */