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"

RotarySwitch.hpp

Committer:
charlesdavidyoung
Date:
2018-09-04
Revision:
20:fb73eaaf0894
Parent:
19:fd3e33641aa7
Child:
24:db7494389c03

File content as of revision 20:fb73eaaf0894:

/**
 * @author Charles Young
 * This class encapsulates the behavior of the rotary switch to change modes
 */

#ifndef RotarySwitch_H
#define RotarySwitch_H

/**
 * Includes
 */
#include "mbed.h"
#include "QEI.h"        // Quadrature Encoder functions
#include "HwRegisters.hpp"

/**
 * Code associated with rotary switch.
 */
class RotarySwitch {

public:

   /**
    * Constructor.
    *
    * @param channelA mbed pin for channel A input.
    * @param channelB mbed pin for channel B input.
    */
   RotarySwitch();

   void UpdateOutput();
   void UpdateInput();

   /**
    * Get the current position of switch.
    */
   int GetPosition(void);

private:
   static const int WheelStateTimeout = 5; //timeout for wheel button pushed

   enum WheelState {
      WHEEL_INACTIVE       = 0,
      WHEEL_MODE_SELECT    = 1,
      WHEEL_SUBMODE_SELECT = 2
   };
   enum WheelStateEvent {
      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;

   /**
    * Manage state machine
    */
   void WheelStateMachine(WheelStateEvent event);
   void LEDs_write(unsigned short data_val);
};

#endif /* RotarySwitch_H */