Commit d1a4b55a6c856a2f7ebe9d2d6f8c819db2bb9d0c

Authored by Imanol-Mikel Barba Sabariego
1 parent 71236059

--no commit message

Project/applications/smartcities/include/sensors.h
@@ -26,12 +26,15 @@ typedef struct { @@ -26,12 +26,15 @@ typedef struct {
26 char* additional_info; 26 char* additional_info;
27 } sensor; 27 } sensor;
28 28
29 -uint8_t register_sensor(sensor sens); 29 +void wakeup(uint8_t logic_address);
30 30
31 //SENSOR DEFINITIONS 31 //SENSOR DEFINITIONS
32 extern sensor light_sensor; 32 extern sensor light_sensor;
33 extern sensor ultrasound_sensor; 33 extern sensor ultrasound_sensor;
34 extern sensor pressure_sensor; 34 extern sensor pressure_sensor;
  35 +extern sensor humidity_temp_sensor;
  36 +extern sensor sound_sensor;
  37 +extern sensor battery;
35 38
36 //SENSOR FUNCTIONS 39 //SENSOR FUNCTIONS
37 40
@@ -65,10 +68,12 @@ typedef struct { @@ -65,10 +68,12 @@ typedef struct {
65 } bmp085_callibration; 68 } bmp085_callibration;
66 69
67 uint16_t get_pressure_data(void); 70 uint16_t get_pressure_data(void);
  71 +uint16_t get_pressure_temperature_data(void);
68 bmp085_callibration get_pressure_callibration_data(void); 72 bmp085_callibration get_pressure_callibration_data(void);
69 char* callibration_pressure_data_csv(bmp085_callibration parameters); 73 char* callibration_pressure_data_csv(bmp085_callibration parameters);
70 -char* pressure_value(uint16_t pressure); 74 +char* pressure_value(uint16_t pressure,uint16_t temperature);
71 void init_pressure(void); 75 void init_pressure(void);
  76 +void init_pressure_temperature(void);
72 77
73 //HUMIDITY AND TEMPERATURE SENSOR 78 //HUMIDITY AND TEMPERATURE SENSOR
74 79
@@ -87,6 +92,6 @@ char* sound_value(uint32_t sound); @@ -87,6 +92,6 @@ char* sound_value(uint32_t sound);
87 92
88 void init_battery(void); 93 void init_battery(void);
89 uint32_t get_battery_data(void); 94 uint32_t get_battery_data(void);
90 -char* battery_value(uint32_t sound); 95 +char* battery_value(uint32_t battery);
91 96
92 #endif 97 #endif
Project/applications/smartcities/main.c
@@ -153,7 +153,7 @@ int main(void) @@ -153,7 +153,7 @@ int main(void)
153 } 153 }
154 } 154 }
155 else if(res==HARD_REACHED){ 155 else if(res==HARD_REACHED){
156 - printf("--------------hard limit-------------\r\n"); 156 + /*printf("--------------hard limit-------------\r\n");
157 157
158 // fem servir 085 de prova, però haurem de fer servir sensor_id[0] 158 // fem servir 085 de prova, però haurem de fer servir sensor_id[0]
159 while( send(buffers[0],&ind[0],&sizes[0], mod.ID, sensor_id[j]) != JSON_POST_OK ) 159 while( send(buffers[0],&ind[0],&sizes[0], mod.ID, sensor_id[j]) != JSON_POST_OK )
@@ -182,7 +182,7 @@ int main(void) @@ -182,7 +182,7 @@ int main(void)
182 else if(ok ==JSON_POST_OK){ 182 else if(ok ==JSON_POST_OK){
183 printf(" send OK \r\n"); 183 printf(" send OK \r\n");
184 } 184 }
185 - } 185 + }*/
186 } 186 }
187 } 187 }
188 //chThdSleepMilliseconds(100); 188 //chThdSleepMilliseconds(100);
Project/applications/smartcities/sensors.c
@@ -2,11 +2,77 @@ @@ -2,11 +2,77 @@
2 2
3 sensor light_sensor = {LIGHT_ADDR, "Light sensor", "illumination", "lux",NULL}; 3 sensor light_sensor = {LIGHT_ADDR, "Light sensor", "illumination", "lux",NULL};
4 sensor ultrasound_sensor = {DISTANCE_ADDR, "Ultrasound sensor", "distance", "cm",NULL}; 4 sensor ultrasound_sensor = {DISTANCE_ADDR, "Ultrasound sensor", "distance", "cm",NULL};
5 -sensor pressure_sensor = {PRESSURE_ADDR, "Pressure sensor", "pressure", "kPa",NULL}; 5 +sensor pressure_sensor = {PRESSURE_ADDR, "Pressure sensor", "pressure", "hPa",NULL};
6 sensor humidity_temp_sensor = {HUMIDITY_TEMP_ADDR, "Humidity and Temperature","ºC,RH",NULL}; 6 sensor humidity_temp_sensor = {HUMIDITY_TEMP_ADDR, "Humidity and Temperature","ºC,RH",NULL};
7 sensor sound_sensor = {SOUND_ADDR, "Sound sensor","mV",NULL}; 7 sensor sound_sensor = {SOUND_ADDR, "Sound sensor","mV",NULL};
8 sensor battery = {BATTERY_ADDR, "Battery Level","mV",NULL}; 8 sensor battery = {BATTERY_ADDR, "Battery Level","mV",NULL};
9 9
  10 +void wakeup(uint8_t logic_address)
  11 +{
  12 + /* Aquí habría que implementar un control
  13 + * inteligente de la alimentación de los
  14 + * sensores, levantándolos y durmiéndolos
  15 + * cuando tocara
  16 + */
  17 +
  18 + // X X X PA7 PA6 PA5 PA4 PA3
  19 + // b7 b6 b5 b4 b3 b2 b1 b0
  20 +
  21 + printf("GRAB A BRUSH AND PUT A LITTLE MAKE-UP\r\n");
  22 + GPIO_InitTypeDef GPIO_InitStructure;
  23 + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  24 + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
  25 + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  26 + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  27 + GPIO_Init(ADCsound_GPIO_PORT, &GPIO_InitStructure);
  28 +
  29 + if(logic_address & 0x1)
  30 + {
  31 + printf("Woken Pin 3\r\n");
  32 + GPIO_SetBits(GPIOA,GPIO_Pin_3);
  33 + }
  34 + else
  35 + {
  36 + GPIO_ResetBits(GPIOA,GPIO_Pin_3);
  37 + }
  38 + if(logic_address & 0x2)
  39 + {
  40 + printf("Woken Pin 4\r\n");
  41 + GPIO_SetBits(GPIOA,GPIO_Pin_4);
  42 + }
  43 + else
  44 + {
  45 + GPIO_ResetBits(GPIOA,GPIO_Pin_4);
  46 + }
  47 + if(logic_address & 0x4)
  48 + {
  49 + printf("Woken Pin 5\r\n");
  50 + GPIO_SetBits(GPIOA,GPIO_Pin_5);
  51 + }
  52 + else
  53 + {
  54 + GPIO_ResetBits(GPIOA,GPIO_Pin_5);
  55 + }
  56 + if(logic_address & 0x8)
  57 + {
  58 + printf("Woken Pin 6\r\n");
  59 + GPIO_SetBits(GPIOA,GPIO_Pin_6);
  60 + }
  61 + else
  62 + {
  63 + GPIO_ResetBits(GPIOA,GPIO_Pin_6);
  64 + }
  65 + if(logic_address & 0x10)
  66 + {
  67 + printf("Woken Pin 7\r\n");
  68 + GPIO_SetBits(GPIOA,GPIO_Pin_7);
  69 + }
  70 + else
  71 + {
  72 + GPIO_ResetBits(GPIOA,GPIO_Pin_7);
  73 + }
  74 +}
  75 +
10 uint32_t get_light_data(void) 76 uint32_t get_light_data(void)
11 { 77 {
12 uint32_t data = 0; 78 uint32_t data = 0;
@@ -123,6 +189,22 @@ uint16_t get_pressure_data(void) @@ -123,6 +189,22 @@ uint16_t get_pressure_data(void)
123 return data; 189 return data;
124 } 190 }
125 191
  192 +uint16_t get_pressure_temperature_data(void)
  193 +{
  194 + uint16_t data;
  195 + init_pressure_temperature();
  196 +
  197 + I2C_start(I2C1,DISTANCE_ADDR << 1, I2C_Direction_Transmitter);
  198 + I2C_write(I2C1, 0xF6);
  199 + I2C_stop(I2C1);
  200 +
  201 + I2C_start(I2C1, DISTANCE_ADDR << 1, I2C_Direction_Receiver);
  202 + data = I2C_read_ack(I2C1);
  203 + data = data << 8;
  204 + data = data | I2C_read_nack(I2C1);
  205 + return data;
  206 +}
  207 +
126 bmp085_callibration get_pressure_callibration_data(void) 208 bmp085_callibration get_pressure_callibration_data(void)
127 { 209 {
128 bmp085_callibration calib_data; 210 bmp085_callibration calib_data;
@@ -234,6 +316,16 @@ void init_pressure(void) @@ -234,6 +316,16 @@ void init_pressure(void)
234 chThdSleepMilliseconds(5); 316 chThdSleepMilliseconds(5);
235 } 317 }
236 318
  319 +void init_pressure_temperature(void)
  320 +{
  321 + I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter);
  322 + I2C_write(I2C1, 0xF4);
  323 + I2C_write(I2C1, 0x2E);
  324 + I2C_stop(I2C1);
  325 +
  326 + chThdSleepMilliseconds(5);
  327 +}
  328 +
237 void init_humidity_temp(void) 329 void init_humidity_temp(void)
238 { 330 {
239 I2C_start(I2C1,HUMIDITY_TEMP_ADDR << 1, I2C_Direction_Transmitter); 331 I2C_start(I2C1,HUMIDITY_TEMP_ADDR << 1, I2C_Direction_Transmitter);
@@ -241,6 +333,7 @@ void init_humidity_temp(void) @@ -241,6 +333,7 @@ void init_humidity_temp(void)
241 } 333 }
242 uint16_t get_humidity_data(void) 334 uint16_t get_humidity_data(void)
243 { 335 {
  336 + init_humidity_temp();
244 uint16_t data = 0; 337 uint16_t data = 0;
245 I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Receiver); 338 I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Receiver);
246 data = I2C_read_ack(I2C1) & 0x3F; 339 data = I2C_read_ack(I2C1) & 0x3F;
@@ -251,6 +344,7 @@ uint16_t get_humidity_data(void) @@ -251,6 +344,7 @@ uint16_t get_humidity_data(void)
251 } 344 }
252 uint16_t get_temperature_data(void) 345 uint16_t get_temperature_data(void)
253 { 346 {
  347 + init_humidity_temp();
254 uint16_t data = 0; 348 uint16_t data = 0;
255 I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Receiver); 349 I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Receiver);
256 I2C_read_ack(I2C1); 350 I2C_read_ack(I2C1);
@@ -275,15 +369,15 @@ char* distance_value(uint16_t distance) @@ -275,15 +369,15 @@ char* distance_value(uint16_t distance)
275 sprintf(value,"%d",distance); 369 sprintf(value,"%d",distance);
276 return value; 370 return value;
277 } 371 }
278 -char* pressure_value(uint16_t pressure) 372 +char* pressure_value(uint16_t pressure, uint16_t temperature)
279 { 373 {
280 - char *value = chHeapAlloc(NULL,5 + 1);  
281 - sprintf(value,"%d",pressure); 374 + char *value = chHeapAlloc(NULL,11 + 1);
  375 + sprintf(value,"%d,%d",pressure,temperature);
282 return value; 376 return value;
283 } 377 }
284 char* temp_humidity_value(uint16_t temp, uint16_t humidity) 378 char* temp_humidity_value(uint16_t temp, uint16_t humidity)
285 { 379 {
286 - char *value = chHeapAlloc(NULL,21 + 1); 380 + char *value = chHeapAlloc(NULL,11 + 1);
287 sprintf(value,"%d,%d",temp,humidity); 381 sprintf(value,"%d,%d",temp,humidity);
288 return value; 382 return value;
289 } 383 }
@@ -295,6 +389,7 @@ void init_sound(void) @@ -295,6 +389,7 @@ void init_sound(void)
295 } 389 }
296 uint32_t get_sound_data(void) 390 uint32_t get_sound_data(void)
297 { 391 {
  392 + init_sound();
298 return adc_sound_process(); 393 return adc_sound_process();
299 } 394 }
300 char* sound_value(uint32_t sound) 395 char* sound_value(uint32_t sound)
@@ -345,15 +440,17 @@ void init_battery(void) @@ -345,15 +440,17 @@ void init_battery(void)
345 440
346 uint32_t get_battery_data(void) 441 uint32_t get_battery_data(void)
347 { 442 {
  443 + init_battery();
348 return adc_batt_process(); 444 return adc_batt_process();
349 } 445 }
350 446
351 -char* battery_value(uint32_t sound) 447 +char* battery_value(uint32_t battery)
352 { 448 {
353 char *value = chHeapAlloc(NULL,11 + 1); 449 char *value = chHeapAlloc(NULL,11 + 1);
354 - sprintf(value,"%4u",(unsigned int)sound); 450 + sprintf(value,"%4u",(unsigned int)battery);
355 return value; 451 return value;
356 } 452 }
357 453
358 //light_value(get_light_data()); 454 //light_value(get_light_data());
359 -//temp_humidity_value(get_temperature_data(),get_humidity_data());  
360 \ No newline at end of file 455 \ No newline at end of file
  456 +//temp_humidity_value(get_temperature_data(),get_humidity_data());
  457 +//pressure_value(get_pressure_data(), get_pressure_temperature_data());
361 \ No newline at end of file 458 \ No newline at end of file