1 sensor using RTOS Timer, another 2 over RTOS Semaphore

Dependents:   Autonomous_quadcopter

Fork of HCSR04 by Antoniolinux B.

Revision:
8:0a10bacaf501
Parent:
7:dcf0aa89bcd7
Child:
11:49a0feca5d71
--- a/hcsr04.cpp	Sun Feb 25 18:31:44 2018 +0000
+++ b/hcsr04.cpp	Sat Mar 03 15:37:39 2018 +0000
@@ -7,7 +7,7 @@
 */
 HCSR04::HCSR04(PinName t1, PinName e1, PinName t2, PinName e2) : trig1(t1), echo1(e1), trig2(t2), echo2(e2) {
     
-    int rate = (1.0 / FLIGHT_CONTROLLER_FREQUENCY) * 1000;
+    int rate = (1.0 / FLIGHT_CONTROLLER_FREQUENCY) * 1000; //ms
     
     limit = (rate * 1000 - rate * 200);
     
@@ -29,23 +29,21 @@
         //printf("wait\n\r");
         self->trig1=0;  // trigger low
         // start pulseIN
-        self->timer1.reset();
-        self->timer1.start();
+        self->timerLimit.reset();
+        self->timerLimit.start();
         while(!self->echo1){
-            if(self->timer1.read_us() > self->limit){
+            if(self->timerLimit.read_us() > self->limit){
                 //printf("moc1\n\r");
-                // if no response from distance sensor -> let the quadcopter fall
                 break;
             }    
         }
-        if(self->timer1.read_us() < self->limit){
-            self->timer1.stop();
+        if(self->timerLimit.read_us() < self->limit){
+            //self->timer1.stop();
             self->timer1.reset();  //reset timer
             self->timer1.start();
             while(self->echo1){
-                if(self->timer1.read_us() > self->limit){
+                if(self->timerLimit.read_us() > self->limit){
                     //printf("moc2\n\r");
-                    // if no response from distance sensor -> let the quadcopter fall
                     break;
                 }
             }
@@ -90,7 +88,7 @@
         }
 }
 
-uint16_t HCSR04::getDistan1(){
+int HCSR04::getDistan1(){
     return distan1;    
 }