Sensos Module Updated
Fork of Middleware by
Revision 3:1704050210b5, committed 2015-12-10
- Comitter:
- Jorge_Beltran
- Date:
- Thu Dec 10 02:31:36 2015 +0000
- Parent:
- 2:a56763667f20
- Child:
- 4:c59485faea9f
- Commit message:
- Updateed middleware library; Added ultrasonic function on sensors module
Changed in this revision
--- a/Initial.h Wed Dec 09 04:50:13 2015 +0000 +++ b/Initial.h Thu Dec 10 02:31:36 2015 +0000 @@ -22,7 +22,6 @@ static DigitalOut ledRED(LED1); static DigitalOut ledGREEN(LED2); static DigitalOut ledBLUE(LED3); -static DigitalIn enable1(D8); static InterruptIn sw2(SW2); static EthernetInterface eth; static TCPSocketServer serverTCP; @@ -30,31 +29,10 @@ static TCPSocketConnection socketTCP2; static UDPSocket socketUDP; static StringManager stringManager; -//sstatic TCPSocketConnection socket; static char *cad; static char *s_myIP; -//static char c_myIP[256]; static char *s_end="\n\r"; static bool bo_somethingWrong=false; -/*Extern Variables*/ -//START PIR SENSOR INPUT INIT -static DigitalIn PIR1(D0); -static DigitalIn PIR2(D1); -//END PIR SENSOR INPUT INIT -//START WINDOW SENSOR INPUT -static DigitalIn W1(D2); -static DigitalIn W2(D3); -static DigitalIn W3(D4); -//END WINDOW SENSOR INPUT INIT -//START DOOR SENSOR INPUT -static DigitalIn DOORSensor(D5); -//END DOOR SENSOR INPUT INIT -//START LIGHT CONTROL OUTPUT -static DigitalOut LightControl(D6); -//END LIGHT CONTROL OUTPUT - - - #endif \ No newline at end of file
--- 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 +}
--- a/Sensors.h Wed Dec 09 04:50:13 2015 +0000 +++ b/Sensors.h Thu Dec 10 02:31:36 2015 +0000 @@ -1,4 +1,9 @@ +#ifndef SENSORS_H_ +#define SENSORS_H_ + + #include "mbed.h" +#include "ultrasonic.h" /*Macros*/ #define BAD_PARAMETER (-1) @@ -8,9 +13,25 @@ #define TRUE 1 #define CLOSED 0 #define OPEN 1 +#define RANGE 500 - +/*Function Initialization*/ +//START PIR SENSOR INPUT INIT +static DigitalIn PIR1(D0); +static DigitalIn PIR2(D1); +//END PIR SENSOR INPUT INIT +//START WINDOW SENSOR INPUT +static DigitalIn W1(D2); +static DigitalIn W2(D3); +static DigitalIn W3(D4); +//END WINDOW SENSOR INPUT INIT +//START DOOR SENSOR INPUT +static DigitalIn DOORSensor(D5); +//END DOOR SENSOR INPUT INIT +//START LIGHT CONTROL OUTPUT +static DigitalOut LightControl(D6); +//END LIGHT CONTROL OUTPUT /*Extern Functions*/ //////////////////////////////////////////////////// @@ -55,4 +76,6 @@ Input parameters -> void Output parameters -> unsigned int PersonNumber; 0 - 4294967296. -*/ \ No newline at end of file +*/ + +#endif \ No newline at end of file