ECE56810 Project 2 - Runner's Monitor

Dependencies:   mbed rohm-bh1790glc-driver mbed-http FXAS21000 FXOS8700Q ESP8266 RegisterWriter

Files at this revision

API Documentation at this revision

Comitter:
prabhuvd
Date:
Sat Mar 30 18:41:34 2013 +0000
Parent:
1:093521f56089
Child:
3:e6795cb9439c
Commit message:
Updated libray

Changed in this revision

hcsr04.cpp Show annotated file Show diff for this revision Revisions of this file
hcsr04.h Show annotated file Show diff for this revision Revisions of this file
--- 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;
+}
--- a/hcsr04.h	Sat Mar 30 17:32:04 2013 +0000
+++ b/hcsr04.h	Sat Mar 30 18:41:34 2013 +0000
@@ -35,14 +35,16 @@
     /** Create a DistMeasure object connected to the specified pin
     * @param pin i/o pin to connect to
     */
-    DistMeasure(PinName TrigPin,PinName EchoPin,unsigned int maxtime);
+    DistMeasure(PinName TrigPin,PinName EchoPin);
     ~DistMeasure();
 
     /** Return the distance from obstacle in cm
     * @param distance in cms and returns -1, in case of failure
     */
  
-    unsigned int get_distance_cm(void);
+    unsigned int get_dist_cm(void);
+    unsigned int get_pulse_us(void);
+    void start_measurement(void );
     void isr_rise(void);
     void isr_fall(void);
     void fall (void (*fptr)(void));
@@ -55,7 +57,6 @@
     Timer pulsetime;
     DigitalOut  trigger;
     InterruptIn echo;
-    unsigned int timeout;
     unsigned int pulsedur;
     unsigned int distance;    
 };