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:
18:ef5678ab1889
Parent:
17:6eed17197004
Child:
20:fb73eaaf0894
--- a/main.cpp	Mon Sep 03 17:31:41 2018 +0000
+++ b/main.cpp	Mon Sep 03 18:49:24 2018 +0000
@@ -71,6 +71,8 @@
 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,
@@ -181,7 +183,21 @@
 }
 
 void UpdateOutput()   
-{               
+{
+    // Blink mode LED
+    if (WHEEL_MODE_SELECT == currentWheelState)
+       LEDs_write(0);
+
+   if (WheelStateTimer)
+   {
+      WheelStateTimer++;
+      if (++WheelStateTimer > WheelStateTimeout)
+      {
+         WheelStateMachine(WHEEL_Timeout);
+         WheelStateTimer = 0;
+      }
+   }
+      
    if(Stopped)
    {    
       // disable interrupts on TRIG1 and TRIG2
@@ -241,17 +257,24 @@
       Count2 = 0;              
    }
 
+   // react to wheel if in proper state
+   WheelCurrent = int(Wheel.getPulses());
    if (   (WHEEL_MODE_SELECT    == currentWheelState)
        || (WHEEL_SUBMODE_SELECT == currentWheelState))
    {
-      WheelCurrent      = int(Wheel.getPulses());
-      if (WheelCurrent > WheelPrevious)
-         LED_status_index = ++LED_status_index % sizeof(LED_statuses);
-      else
-         if (WheelCurrent < WheelPrevious)
-            LED_status_index = --LED_status_index % sizeof(LED_statuses);
-      WheelPrevious = WheelCurrent;
+     if (WHEEL_MODE_SELECT == currentWheelState)
+     {
+        if (WheelCurrent > WheelPrevious)
+           LED_status_index = ++LED_status_index % sizeof(LED_statuses);
+        else
+            if (WheelCurrent < WheelPrevious)
+               LED_status_index = --LED_status_index % sizeof(LED_statuses);
+     }
+     // Keep resetting WheelStateTimer as long as wheel is moving
+     if (WheelPrevious != WheelCurrent)
+        WheelStateTimer = 1;
    }
+   WheelPrevious = WheelCurrent;
 
    // detect when wheel button is pressed but wait until it is released
    // before doing anything
@@ -278,18 +301,27 @@
    switch (currentWheelState) {
       case WHEEL_INACTIVE:
       if (WHEEL_Pressed == event)
+      {
          currentWheelState = WHEEL_MODE_SELECT;
+         WheelStateTimer = 1;
+      }
       break;
       case WHEEL_MODE_SELECT:
       if (WHEEL_Pressed == event)
+      {
          currentWheelState = WHEEL_SUBMODE_SELECT;
+         WheelStateTimer = 1;
+      }
       else
          if (WHEEL_Timeout == event)
             currentWheelState = WHEEL_INACTIVE;
       break;
       case WHEEL_SUBMODE_SELECT:
       if (WHEEL_Pressed == event)
+      {
          currentWheelState = WHEEL_MODE_SELECT;
+         WheelStateTimer = 1;
+      }
       else
          if (WHEEL_Timeout == event)
             currentWheelState = WHEEL_INACTIVE;