Ultrasound Ranging Sensor module

Dependents:   HC-SR04

Revision:
2:0acb6ade091c
Parent:
1:093521f56089
Child:
3:e6795cb9439c
--- a/hcsr04.cpp	Sat Mar 30 17:32:04 2013 +0000
+++ b/hcsr04.cpp	Sat Mar 30 18:41:34 2013 +0000
@@ -21,25 +21,30 @@
 #include "hcsr04.h"
 
 
-DistMeasure::DistMeasure(PinName TrigPin,PinName EchoPin,unsigned int maxtime):
-    trigger(TrigPin), echo(EchoPin), timeout(maxtime)
+DistMeasure::DistMeasure(PinName TrigPin,PinName EchoPin):
+    trigger(TrigPin), echo(EchoPin)
 {
     pulsetime.stop();
     pulsetime.reset();
     echo.rise(this,&DistMeasure::isr_rise);
-    echo.fall(this,&DistMeasure::isr_fall);    
+    echo.fall(this,&DistMeasure::isr_fall);
+    trigger=0;
 }
 
-
 DistMeasure::~DistMeasure()
 {
 }
 
- 
 void DistMeasure::isr_rise(void)
 {
     pulsetime.start();
 }
+void DistMeasure::start_measurement(void)
+{
+    trigger=1;
+    wait_us(10);
+    trigger=0;
+}
 
 void DistMeasure::isr_fall(void)
 {
@@ -48,6 +53,7 @@
     distance= (pulsedur*343)/20000;
     pulsetime.reset();
 }
+ 
 void DistMeasure::rise (void (*fptr)(void))
 {
     echo.rise(fptr);
@@ -57,11 +63,11 @@
     echo.fall(fptr);
 }
 
-unsigned int DistMeasure::get_distance_cm()
+unsigned int DistMeasure::get_dist_cm()
 {
-    if(distance > 65530) {
-        return -1;
-    } else {
-        return distance;
-    }
+    return distance;
 }
+unsigned int DistMeasure::get_pulse_us()
+{
+    return pulsedur;
+}