Sensos Module Updated

Dependents:   SmartLabProyect

Fork of Middleware by Roberto Herrera

Revision:
3:1704050210b5
Parent:
1:fd355dc296b1
Child:
4:c59485faea9f
--- a/Sensors.cpp	Wed Dec 09 04:50:13 2015 +0000
+++ b/Sensors.cpp	Thu Dec 10 02:31:36 2015 +0000
@@ -1,6 +1,4 @@
 #include "Sensors.h"
-#include "Initial.h"
-
 
 /*Functions*/
 
@@ -87,14 +85,92 @@
     return LightStatus;
 }
 
-//PERSON COUNTER FUNCTION
-unsigned int GetPersonStatus(){
-    static unsigned int PersonNumber = 0;   
+//PERSON COUNTER FUNCTIONS
+static void dist(int distance)
+{
+    /*Void*/
+}
+static void dist2(int distance2)
+{
+    /*Void*/
+}
+
+//START ULTRASONIC INIT
+ultrasonic mu(D10, D11, .1, 1, &dist);    //Set the trigger pin to D10 and the echo pin to D11
+                                        //have updates every .1 seconds and a timeout after 1
+                                        //second, and call dist when the distance changes
+ultrasonic mu2(D12, D13, .1, 1, &dist2);  //Set the trigger pin to D12 and the echo pin to D13
+                                        //have updates every .1 seconds and a timeout after 1
+                                        //second, and call dist when the distance changes 
+//END ULTRASONIC INIT
+
+unsigned int GetPersonStatus()
+{
+    static int CDistance = 0;
+    static int CDistance2 = 0;
+    static unsigned int PersonNumber = 0;
+    static int flag=0;
+    mu.startUpdates();//start mesuring the distance
+    mu2.startUpdates();//start mesuring the distance
     
-    //TODO Insert code here
-    /***      TODO      ***/
-    /***      TODO      ***/
-    /***      TODO      ***/
+    printf("--------------------------------------------- \r\n");
+        //Do something else here
+        mu.checkDistance();     //call checkDistance() as much as possible, as this is where
+                                //the class checks if dist needs to be called.
+        mu2.checkDistance();     //call checkDistance() as much as possible, as this is where
+                                //the class checks if dist needs to be called.
+        CDistance = mu.getCurrentDistance();
+        CDistance2 = mu2.getCurrentDistance();
+        
+        if(CDistance <= RANGE && flag == 0)
+        {
+            flag = 1;
+            printf("Entrando %d\r\n", flag);
+        }
+        if(CDistance2 <= RANGE && flag == 0)
+        {
+           flag = 2;
+           printf("Saliendo %d\r\n", flag);
+        }
+
+        switch(flag)
+            {
+              case 1:
+                    wait(0.3);
+                    CDistance2 = mu2.getCurrentDistance();
+                    if(CDistance2 <= RANGE)
+                    {
+                       PersonNumber++;
+                       printf("Entro una persona \r\n");
+                    }
+                    else
+                    {
+                        printf("No entro nadie \r\n");
+                    }
+                    break;
+                    
+                case 2:
+                    wait(0.3);
+                    CDistance = mu.getCurrentDistance();
+                    if(CDistance <= RANGE)
+                    {
+                       if(PersonNumber > 0)PersonNumber--;
+                       printf("Salio una persona \r\n");
+                    }
+                        else
+                    {
+                        printf("No salio nadie \r\n");
+                    }
+                    break;
+                    
+                default:
+
+                    break;
+            }
+            printf("Personas adentro %d\r\n", PersonNumber);      
+            printf("+++++++++++++++++++ \r\n");
+            wait(0.5);
+            flag = 0;
     
     return PersonNumber;
-}
\ No newline at end of file
+}