1 sensor using RTOS Timer, another 2 over RTOS Semaphore

Dependents:   Autonomous_quadcopter

Fork of HCSR04 by Antoniolinux B.

Revision:
6:7f98f258e8ef
Parent:
5:02948ae78be7
Child:
7:dcf0aa89bcd7
--- a/hcsr04.cpp	Sun Feb 04 15:20:37 2018 +0000
+++ b/hcsr04.cpp	Sun Feb 18 17:10:25 2018 +0000
@@ -25,7 +25,9 @@
         while(!self->echo){
             if(self->timer.read_us() > 4500){
                 //printf("moc1\n\r");
-                break;
+                // if no response from distance sensor -> let the quadcopter fall
+                self->distan = 500;
+                return;
             }    
         }
         if(self->timer.read_us() < 4500){
@@ -35,7 +37,9 @@
             while(self->echo){
                 if(self->timer.read_us() > 4500){
                     //printf("moc2\n\r");
-                    break;
+                    // if no response from distance sensor -> let the quadcopter fall
+                    self->distan = 500;
+                    return;
                 }
             }
             self->timer.stop();