MiddleWare GUS

Dependents:   MainTaskGus

Committer:
RoHe
Date:
Thu Dec 10 23:28:58 2015 +0000
Revision:
4:a7da6ca6aef2
Parent:
3:d527bae62c60
update Sensors People

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RoHe 1:fd355dc296b1 1 #include "Sensors.h"
RoHe 1:fd355dc296b1 2
RoHe 1:fd355dc296b1 3 /*Functions*/
RoHe 1:fd355dc296b1 4
RoHe 1:fd355dc296b1 5 //PRESCENCE DETECTION FUNCTION
RoHe 1:fd355dc296b1 6 bool GetPrescenceStatus(){
RoHe 1:fd355dc296b1 7 static bool RoomStatus = FALSE;
RoHe 1:fd355dc296b1 8
RoHe 1:fd355dc296b1 9 if(PIR1==TRUE || PIR2==TRUE)
RoHe 1:fd355dc296b1 10 {
RoHe 1:fd355dc296b1 11 RoomStatus = TRUE;
RoHe 1:fd355dc296b1 12 }
RoHe 1:fd355dc296b1 13 else
RoHe 1:fd355dc296b1 14 {
RoHe 1:fd355dc296b1 15 RoomStatus = FALSE;
RoHe 1:fd355dc296b1 16 }
RoHe 1:fd355dc296b1 17
RoHe 1:fd355dc296b1 18 return RoomStatus;
RoHe 1:fd355dc296b1 19 }
RoHe 1:fd355dc296b1 20
RoHe 1:fd355dc296b1 21 //DOOR STATUS FUNCION
RoHe 1:fd355dc296b1 22 bool GetDoorStatus(){
RoHe 1:fd355dc296b1 23 static bool DoorStatus = CLOSED;
RoHe 1:fd355dc296b1 24
RoHe 1:fd355dc296b1 25 if(DOORSensor == TRUE)
RoHe 1:fd355dc296b1 26 DoorStatus = OPEN;
RoHe 1:fd355dc296b1 27 else
RoHe 1:fd355dc296b1 28 DoorStatus = CLOSED;
RoHe 1:fd355dc296b1 29
RoHe 1:fd355dc296b1 30 return DoorStatus;
RoHe 1:fd355dc296b1 31 }
RoHe 1:fd355dc296b1 32
RoHe 1:fd355dc296b1 33
RoHe 1:fd355dc296b1 34 //WINDOW STATUS FUNCTION
RoHe 1:fd355dc296b1 35 int GetWindowStatus(int window){
RoHe 1:fd355dc296b1 36 static int WindowStatus = CLOSED;
RoHe 1:fd355dc296b1 37
RoHe 1:fd355dc296b1 38 switch(window)
RoHe 1:fd355dc296b1 39 {
RoHe 1:fd355dc296b1 40 case 1:
RoHe 1:fd355dc296b1 41 if(W1)
RoHe 1:fd355dc296b1 42 WindowStatus = OPEN;
RoHe 1:fd355dc296b1 43 else
RoHe 1:fd355dc296b1 44 WindowStatus = CLOSED;
RoHe 1:fd355dc296b1 45 break;
RoHe 1:fd355dc296b1 46 case 2:
RoHe 1:fd355dc296b1 47 if(W2)
RoHe 1:fd355dc296b1 48 WindowStatus = OPEN;
RoHe 1:fd355dc296b1 49 else
RoHe 1:fd355dc296b1 50 WindowStatus = CLOSED;
RoHe 1:fd355dc296b1 51 break;
RoHe 1:fd355dc296b1 52 case 3:
RoHe 1:fd355dc296b1 53 if(W3)
RoHe 1:fd355dc296b1 54 WindowStatus = OPEN;
RoHe 1:fd355dc296b1 55 else
RoHe 1:fd355dc296b1 56 WindowStatus = CLOSED;
RoHe 1:fd355dc296b1 57 break;
RoHe 1:fd355dc296b1 58 default:
RoHe 1:fd355dc296b1 59 WindowStatus = BAD_PARAMETER;
RoHe 1:fd355dc296b1 60 break;
RoHe 1:fd355dc296b1 61 }
RoHe 1:fd355dc296b1 62
RoHe 1:fd355dc296b1 63 return WindowStatus;
RoHe 1:fd355dc296b1 64 }
RoHe 1:fd355dc296b1 65
RoHe 1:fd355dc296b1 66 //LIGHT CONTROL FUNCTION
RoHe 1:fd355dc296b1 67 int SetLight(bool Light){
RoHe 1:fd355dc296b1 68 static int LightStatus = 0;
RoHe 1:fd355dc296b1 69
RoHe 1:fd355dc296b1 70 switch(Light)
RoHe 1:fd355dc296b1 71 {
RoHe 1:fd355dc296b1 72 case 0:
RoHe 1:fd355dc296b1 73 LightStatus = OFF;
RoHe 1:fd355dc296b1 74 LightControl = OFF;
RoHe 1:fd355dc296b1 75 break;
RoHe 1:fd355dc296b1 76 case 1:
RoHe 1:fd355dc296b1 77 LightStatus = ON;
RoHe 1:fd355dc296b1 78 LightControl = ON;
RoHe 1:fd355dc296b1 79 break;
RoHe 1:fd355dc296b1 80 default:
RoHe 1:fd355dc296b1 81 LightStatus = BAD_PARAMETER;
RoHe 1:fd355dc296b1 82 break;
RoHe 1:fd355dc296b1 83 }
RoHe 1:fd355dc296b1 84
RoHe 1:fd355dc296b1 85 return LightStatus;
RoHe 1:fd355dc296b1 86 }
RoHe 1:fd355dc296b1 87
RoHe 3:d527bae62c60 88 //PERSON COUNTER FUNCTIONS
RoHe 3:d527bae62c60 89 static void dist(int distance)
RoHe 3:d527bae62c60 90 {
RoHe 3:d527bae62c60 91 /*Void*/
RoHe 3:d527bae62c60 92 }
RoHe 3:d527bae62c60 93 static void dist2(int distance2)
RoHe 3:d527bae62c60 94 {
RoHe 3:d527bae62c60 95 /*Void*/
RoHe 3:d527bae62c60 96 }
RoHe 3:d527bae62c60 97
RoHe 3:d527bae62c60 98 //START ULTRASONIC INIT
RoHe 3:d527bae62c60 99 ultrasonic mu(D10, D11, .1, 1, &dist); //Set the trigger pin to D10 and the echo pin to D11
RoHe 3:d527bae62c60 100 //have updates every .1 seconds and a timeout after 1
RoHe 3:d527bae62c60 101 //second, and call dist when the distance changes
RoHe 3:d527bae62c60 102 ultrasonic mu2(D12, D13, .1, 1, &dist2); //Set the trigger pin to D12 and the echo pin to D13
RoHe 3:d527bae62c60 103 //have updates every .1 seconds and a timeout after 1
RoHe 3:d527bae62c60 104 //second, and call dist when the distance changes
RoHe 3:d527bae62c60 105 //END ULTRASONIC INIT
RoHe 3:d527bae62c60 106
RoHe 3:d527bae62c60 107 unsigned int GetPersonStatus()
RoHe 3:d527bae62c60 108 {
RoHe 3:d527bae62c60 109 static int CDistance = 0;
RoHe 3:d527bae62c60 110 static int CDistance2 = 0;
RoHe 4:a7da6ca6aef2 111 static unsigned int PersonNumber = 0;
RoHe 3:d527bae62c60 112 static int flag=0;
RoHe 3:d527bae62c60 113 mu.startUpdates();//start mesuring the distance
RoHe 3:d527bae62c60 114 mu2.startUpdates();//start mesuring the distance
RoHe 1:fd355dc296b1 115
RoHe 3:d527bae62c60 116 printf("--------------------------------------------- \r\n");
RoHe 3:d527bae62c60 117 //Do something else here
RoHe 3:d527bae62c60 118 mu.checkDistance(); //call checkDistance() as much as possible, as this is where
RoHe 3:d527bae62c60 119 //the class checks if dist needs to be called.
RoHe 3:d527bae62c60 120 mu2.checkDistance(); //call checkDistance() as much as possible, as this is where
RoHe 3:d527bae62c60 121 //the class checks if dist needs to be called.
RoHe 3:d527bae62c60 122 CDistance = mu.getCurrentDistance();
RoHe 3:d527bae62c60 123 CDistance2 = mu2.getCurrentDistance();
RoHe 3:d527bae62c60 124
RoHe 3:d527bae62c60 125 if(CDistance <= RANGE && flag == 0)
RoHe 3:d527bae62c60 126 {
RoHe 3:d527bae62c60 127 flag = 1;
RoHe 3:d527bae62c60 128 printf("Entrando %d\r\n", flag);
RoHe 3:d527bae62c60 129 }
RoHe 3:d527bae62c60 130 if(CDistance2 <= RANGE && flag == 0)
RoHe 3:d527bae62c60 131 {
RoHe 3:d527bae62c60 132 flag = 2;
RoHe 3:d527bae62c60 133 printf("Saliendo %d\r\n", flag);
RoHe 3:d527bae62c60 134 }
RoHe 3:d527bae62c60 135
RoHe 3:d527bae62c60 136 switch(flag)
RoHe 3:d527bae62c60 137 {
RoHe 3:d527bae62c60 138 case 1:
RoHe 3:d527bae62c60 139 wait(0.3);
RoHe 3:d527bae62c60 140 CDistance2 = mu2.getCurrentDistance();
RoHe 3:d527bae62c60 141 if(CDistance2 <= RANGE)
RoHe 3:d527bae62c60 142 {
RoHe 3:d527bae62c60 143 PersonNumber++;
RoHe 3:d527bae62c60 144 printf("Entro una persona \r\n");
RoHe 3:d527bae62c60 145 }
RoHe 3:d527bae62c60 146 else
RoHe 3:d527bae62c60 147 {
RoHe 3:d527bae62c60 148 printf("No entro nadie \r\n");
RoHe 3:d527bae62c60 149 }
RoHe 3:d527bae62c60 150 break;
RoHe 3:d527bae62c60 151
RoHe 3:d527bae62c60 152 case 2:
RoHe 3:d527bae62c60 153 wait(0.3);
RoHe 3:d527bae62c60 154 CDistance = mu.getCurrentDistance();
RoHe 3:d527bae62c60 155 if(CDistance <= RANGE)
RoHe 3:d527bae62c60 156 {
RoHe 3:d527bae62c60 157 if(PersonNumber > 0)PersonNumber--;
RoHe 3:d527bae62c60 158 printf("Salio una persona \r\n");
RoHe 3:d527bae62c60 159 }
RoHe 3:d527bae62c60 160 else
RoHe 3:d527bae62c60 161 {
RoHe 3:d527bae62c60 162 printf("No salio nadie \r\n");
RoHe 3:d527bae62c60 163 }
RoHe 3:d527bae62c60 164 break;
RoHe 3:d527bae62c60 165
RoHe 3:d527bae62c60 166 default:
RoHe 3:d527bae62c60 167
RoHe 3:d527bae62c60 168 break;
RoHe 3:d527bae62c60 169 }
RoHe 3:d527bae62c60 170 printf("Personas adentro %d\r\n", PersonNumber);
RoHe 3:d527bae62c60 171 printf("+++++++++++++++++++ \r\n");
RoHe 3:d527bae62c60 172 wait(0.5);
RoHe 3:d527bae62c60 173 flag = 0;
RoHe 1:fd355dc296b1 174
RoHe 1:fd355dc296b1 175 return PersonNumber;
RoHe 3:d527bae62c60 176 }
RoHe 3:d527bae62c60 177
RoHe 3:d527bae62c60 178 //LIGHT FEEDBACK FUNCION
RoHe 3:d527bae62c60 179 bool GetLightStatus(){
RoHe 3:d527bae62c60 180 static bool LightFeedback = OFF;
RoHe 3:d527bae62c60 181
RoHe 3:d527bae62c60 182 if(LIGHTSTATUS == ON)
RoHe 3:d527bae62c60 183 LightFeedback = ON;
RoHe 3:d527bae62c60 184 else
RoHe 3:d527bae62c60 185 LightFeedback = OFF;
RoHe 3:d527bae62c60 186
RoHe 3:d527bae62c60 187 return LightFeedback;
RoHe 3:d527bae62c60 188 }