Rotork Research Team / QEI

Fork of QEI by Simon Truelove

Revision:
3:ee47e451eb7c
Parent:
2:5bdf87e1ca68
Child:
4:609710214f6d
--- a/QEI.cpp	Thu Nov 15 15:56:06 2018 +0000
+++ b/QEI.cpp	Mon Nov 19 11:13:53 2018 +0000
@@ -135,6 +135,7 @@
          Encoding encoding) : channelA_(channelA), channelB_(channelB),
         index_(index) {
 
+    whoop_        = 0;
     yay_          = 0;
     pulses_       = 0;
     revolutions_  = 0;
@@ -206,6 +207,19 @@
 
 }
 
+int QEI::getWhoop(void) {
+
+   return whoop_;
+
+}
+
+void QEI::ResetWhoop(void) 
+{
+
+  whoop_ = 0;
+
+}
+
 // +-------------+
 // | X2 Encoding |
 // +-------------+
@@ -250,7 +264,8 @@
 // We might enter an invalid state for a number of reasons which are hard to
 // predict - if this is the case, it is generally safe to ignore it, update
 // the state and carry on, with the error correcting itself shortly after.
-void QEI::encode(void) {
+void QEI::encode(void) 
+{
 
     int change = 0;
     int chanA  = channelA_.read();
@@ -297,12 +312,19 @@
                             
             pulses_ -= change;
             PulseCount_++;
+            PulseCount2_++;
             
             if  (PulseCount_==1)
             {
                 yay_=1;
                 PulseCount_ = 0;   
             }
+            
+            if (PulseCount2_==80)
+            {
+                whoop_=1;
+                PulseCount2_ = 0;
+            }
         }
 
     }