PinDetect rework, removed the continuous sampling, using just irq, timers and pin state sequence.

Fork of PinDetect by Andy K

Revision:
2:cb3afc45028b
Parent:
1:611a8f5ac65c
Child:
3:5ff38909c179
diff -r 611a8f5ac65c -r cb3afc45028b PinDetect.h
--- a/PinDetect.h	Thu Jan 13 09:53:26 2011 +0000
+++ b/PinDetect.h	Thu Jan 13 11:09:22 2011 +0000
@@ -166,6 +166,8 @@
     
 public:
 
+    friend class Ticker;
+    
     PinDetect() { error("You must supply a PinName"); }
 
     /** PinDetect constructor
@@ -202,6 +204,7 @@
      */
     void setSampleFrequency(int i = PINDETECT_SAMPLE_PERIOD) { 
         _sampleTime = i; 
+        _prevState  = _in->read();        
         _ticker->attach_us( this, &PinDetect::isr, _sampleTime );
     }
     
@@ -449,7 +452,8 @@
      * Read the value of the pin being sampled.
      */
     operator int() { return _in->read(); }
-    
+
+protected:    
     /** The Ticker periodic callback function
      */
     void isr(void) {