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"

Revision:
19:fd3e33641aa7
Child:
20:fb73eaaf0894
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RotarySwitch.hpp	Tue Sep 04 08:28:34 2018 -0700
@@ -0,0 +1,95 @@
+/**
+ * @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
+
+/**
+ * Quadrature Encoder Interface.
+ */
+class RotarySwitch {
+
+public:
+
+   /**
+    * Constructor.
+    *
+    * @param channelA mbed pin for channel A input.
+    * @param channelB mbed pin for channel B input.
+    */
+   RotarySwitch(PinName channelA, PinName channelB);
+
+   /**
+    * 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
+
+   /**
+    * Defines
+    */
+#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;
+
+   DigitalIn   QEPB  (D9);    // Quadrature encoder pushbutton
+
+   // 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,
+      WHEEL_SUBMODE_SELECT = 2
+   };
+   enum WheelStateEvent {
+      WHEEL_Pressed = 0,
+      WHEEL_Timeout = 1
+   };
+   WheelState currentWheelState;
+
+   /**
+    * 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.
+    */
+   void WheelStateMachine(WheelStateEvent event);
+
+   void RotatySwitch::UpdateOutput();
+   void RotatySwitch::UpdateInput();
+};
+
+#endif /* RotarySwitch_H */