the fish that looks like a jet

Dependencies:   ADXL345 ADXL345_I2C IMUfilter ITG3200 mbed Servo

Revision:
6:a4d6f3e4bf28
Parent:
5:090ef6275773
Child:
7:e005cfaff8d1
--- a/PwmReader.cpp	Tue Jan 28 23:59:21 2014 +0000
+++ b/PwmReader.cpp	Wed Jan 29 05:04:50 2014 +0000
@@ -1,10 +1,16 @@
 #include "PwmReader.h"
 
 //Constructors
-PwmReader::PwmReader(PinName pwmInPort)
+PwmReader::PwmReader(PinName pwmInPort, float min, float max)
 {
+    if (min > max)
+    {
+        error("PwmReader min value greater than max value!");
+    }
+    
     di = new InterruptIn(pwmInPort);
-    
+    pwmMin = min;
+    pwmMax = max;
     lastRise = 0;
     period = 0;
     duty = 0.0;
@@ -20,7 +26,9 @@
 // public methods
 float PwmReader::getDuty()
 {
-    return duty;
+    float smallDelta = (duty > pwmMin) ? (duty - pwmMin) : 0.0;
+    float dutyAdjusted = smallDelta / (pwmMax-pwmMin);
+    return dutyAdjusted;
 }
 
 // private methods
@@ -36,9 +44,9 @@
 
 void PwmReader::pwmFall()
 {
-    int fallTime = t.read_us();
+    int fall = t.read_us();
     if(period > 0 ) {
-        int delta = fallTime - lastRise;
-        duty = float(delta)/float(period);
+        int delta = fall - lastRise;
+        duty = float(delta)/float(period); 
     }
 }
\ No newline at end of file