Library for decoding quadrature encoders. Uses a ring buffer so you can be sure to process every tick in the order that it happened. This library is not really intended for public use yet and does not have much documentation.

Dependents:   LineFollowing DeadReckoning

Files at this revision

API Documentation at this revision

Comitter:
DavidEGrayson
Date:
Thu Feb 20 20:09:21 2014 +0000
Parent:
1:138f5421c287
Child:
3:a2dd8d8bde4c
Commit message:
Don't do any I/O in the constructor; that's a bad idea because then people cannot set up their I/O lines in the right order and with the right delays.

Changed in this revision

PololuEncoder.h Show annotated file Show diff for this revision Revisions of this file
--- a/PololuEncoder.h	Thu Feb 20 18:54:43 2014 +0000
+++ b/PololuEncoder.h	Thu Feb 20 20:09:21 2014 +0000
@@ -46,15 +46,16 @@
     PololuEncoder(PinName pinNameA, PinName pinNameB, PololuEncoderBuffer * buffer, uint8_t id)
       : pinA(pinNameA), pinB(pinNameB), buffer(buffer), id(id)
     {
-        pinA.mode(PullUp);        // TODO: move this to the user code
-        pinB.mode(PullUp);        // TODO: move this to the user code
-        
+    }
+    
+    void init()
+    {
         pinA.rise(this, &PololuEncoder::isr);
         pinA.fall(this, &PololuEncoder::isr);
         pinB.rise(this, &PololuEncoder::isr);
         pinB.fall(this, &PololuEncoder::isr);
-        
         previousState = readState();
+        count = 0;
     }
     
     void isr()
@@ -86,7 +87,7 @@
         }        
         previousState = newState;
         
-        if (event != 0 && buffer->hasSpace())
+        if (event != 0 && buffer != NULL && buffer->hasSpace())
         {
             buffer->writeEvent(event);
         }