Derivative QEI library to add an error counter and the ability to set the count and revolutions, and reset the error counter.

Revision:
1:cecfd2d4d286
Parent:
0:5c2ad81551aa
diff -r 5c2ad81551aa -r cecfd2d4d286 QEI.cpp
--- a/QEI.cpp	Thu Sep 02 16:48:55 2010 +0000
+++ b/QEI.cpp	Wed Jan 13 20:12:03 2021 +0000
@@ -3,6 +3,15 @@
  *
  * @section LICENSE
  *
+ * Derivative work created in Jan 2021 by D.Smart, which 
+ * has the following changes:
+ *  + Update for MBED OS 6 ('callback' added to member ISRs)
+ *  + Added counter for non-grey-code transitions
+ *  + Added set functions to initialize counts to known values
+ *  + Added get functions for error counters
+ *
+ * No copyright claim is being made on these changes.
+ *
  * Copyright (c) 2010 ARM Limited
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -137,6 +146,7 @@
 
     pulses_       = 0;
     revolutions_  = 0;
+    invalid_      = 0;
     pulsesPerRev_ = pulsesPerRev;
     encoding_     = encoding;
 
@@ -151,28 +161,43 @@
     //X2 encoding uses interrupts on only channel A.
     //X4 encoding uses interrupts on      channel A,
     //and on channel B.
-    channelA_.rise(this, &QEI::encode);
-    channelA_.fall(this, &QEI::encode);
+    channelA_.rise(callback(this, &QEI::encode));
+    channelA_.fall(callback(this, &QEI::encode));
 
     //If we're using X4 encoding, then attach interrupts to channel B too.
     if (encoding == X4_ENCODING) {
-        channelB_.rise(this, &QEI::encode);
-        channelB_.fall(this, &QEI::encode);
+        channelB_.rise(callback(this, &QEI::encode));
+        channelB_.fall(callback(this, &QEI::encode));
     }
     //Index is optional.
     if (index !=  NC) {
-        index_.rise(this, &QEI::index);
+        index_.rise(callback(this, &QEI::index));
     }
 
 }
 
+void QEI::setPulses(int newCount) {
+    pulses_     = newCount;
+}
+
+void QEI::setRevolutions(int newRevs) {
+    revolutions_    = newRevs;
+}
+
 void QEI::reset(void) {
 
     pulses_      = 0;
     revolutions_ = 0;
+    invalid_     = 0;
 
 }
 
+int QEI::getInvalidCount(void) {
+    int r = invalid_;
+    invalid_ = 0;
+    return r;
+}
+
 int QEI::getCurrentState(void) {
 
     return currState_;
@@ -260,6 +285,9 @@
             pulses_--;
 
         }
+        else {
+            invalid_++;
+        }
 
     } else if (encoding_ == X4_ENCODING) {