From d1a4b55a6c856a2f7ebe9d2d6f8c819db2bb9d0c Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Thu, 22 May 2014 09:51:37 +0000 Subject: [PATCH] --- Project/applications/smartcities/include/sensors.h | 11 ++++++++--- Project/applications/smartcities/main.c | 4 ++-- Project/applications/smartcities/sensors.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 115 insertions(+), 13 deletions(-) diff --git a/Project/applications/smartcities/include/sensors.h b/Project/applications/smartcities/include/sensors.h index 50a1adf..75fe36a 100644 --- a/Project/applications/smartcities/include/sensors.h +++ b/Project/applications/smartcities/include/sensors.h @@ -26,12 +26,15 @@ typedef struct { char* additional_info; } sensor; -uint8_t register_sensor(sensor sens); +void wakeup(uint8_t logic_address); //SENSOR DEFINITIONS extern sensor light_sensor; extern sensor ultrasound_sensor; extern sensor pressure_sensor; +extern sensor humidity_temp_sensor; +extern sensor sound_sensor; +extern sensor battery; //SENSOR FUNCTIONS @@ -65,10 +68,12 @@ typedef struct { } bmp085_callibration; uint16_t get_pressure_data(void); +uint16_t get_pressure_temperature_data(void); bmp085_callibration get_pressure_callibration_data(void); char* callibration_pressure_data_csv(bmp085_callibration parameters); -char* pressure_value(uint16_t pressure); +char* pressure_value(uint16_t pressure,uint16_t temperature); void init_pressure(void); +void init_pressure_temperature(void); //HUMIDITY AND TEMPERATURE SENSOR @@ -87,6 +92,6 @@ char* sound_value(uint32_t sound); void init_battery(void); uint32_t get_battery_data(void); -char* battery_value(uint32_t sound); +char* battery_value(uint32_t battery); #endif diff --git a/Project/applications/smartcities/main.c b/Project/applications/smartcities/main.c index 3886506..38e2019 100644 --- a/Project/applications/smartcities/main.c +++ b/Project/applications/smartcities/main.c @@ -153,7 +153,7 @@ int main(void) } } else if(res==HARD_REACHED){ - printf("--------------hard limit-------------\r\n"); + /*printf("--------------hard limit-------------\r\n"); // fem servir 085 de prova, però haurem de fer servir sensor_id[0] while( send(buffers[0],&ind[0],&sizes[0], mod.ID, sensor_id[j]) != JSON_POST_OK ) @@ -182,7 +182,7 @@ int main(void) else if(ok ==JSON_POST_OK){ printf(" send OK \r\n"); } - } + }*/ } } //chThdSleepMilliseconds(100); diff --git a/Project/applications/smartcities/sensors.c b/Project/applications/smartcities/sensors.c index acccf9f..fb97989 100644 --- a/Project/applications/smartcities/sensors.c +++ b/Project/applications/smartcities/sensors.c @@ -2,11 +2,77 @@ sensor light_sensor = {LIGHT_ADDR, "Light sensor", "illumination", "lux",NULL}; sensor ultrasound_sensor = {DISTANCE_ADDR, "Ultrasound sensor", "distance", "cm",NULL}; -sensor pressure_sensor = {PRESSURE_ADDR, "Pressure sensor", "pressure", "kPa",NULL}; +sensor pressure_sensor = {PRESSURE_ADDR, "Pressure sensor", "pressure", "hPa",NULL}; sensor humidity_temp_sensor = {HUMIDITY_TEMP_ADDR, "Humidity and Temperature","ºC,RH",NULL}; sensor sound_sensor = {SOUND_ADDR, "Sound sensor","mV",NULL}; sensor battery = {BATTERY_ADDR, "Battery Level","mV",NULL}; +void wakeup(uint8_t logic_address) +{ + /* Aquí habría que implementar un control + * inteligente de la alimentación de los + * sensores, levantándolos y durmiéndolos + * cuando tocara + */ + + // X X X PA7 PA6 PA5 PA4 PA3 + // b7 b6 b5 b4 b3 b2 b1 b0 + + printf("GRAB A BRUSH AND PUT A LITTLE MAKE-UP\r\n"); + GPIO_InitTypeDef GPIO_InitStructure; + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_Init(ADCsound_GPIO_PORT, &GPIO_InitStructure); + + if(logic_address & 0x1) + { + printf("Woken Pin 3\r\n"); + GPIO_SetBits(GPIOA,GPIO_Pin_3); + } + else + { + GPIO_ResetBits(GPIOA,GPIO_Pin_3); + } + if(logic_address & 0x2) + { + printf("Woken Pin 4\r\n"); + GPIO_SetBits(GPIOA,GPIO_Pin_4); + } + else + { + GPIO_ResetBits(GPIOA,GPIO_Pin_4); + } + if(logic_address & 0x4) + { + printf("Woken Pin 5\r\n"); + GPIO_SetBits(GPIOA,GPIO_Pin_5); + } + else + { + GPIO_ResetBits(GPIOA,GPIO_Pin_5); + } + if(logic_address & 0x8) + { + printf("Woken Pin 6\r\n"); + GPIO_SetBits(GPIOA,GPIO_Pin_6); + } + else + { + GPIO_ResetBits(GPIOA,GPIO_Pin_6); + } + if(logic_address & 0x10) + { + printf("Woken Pin 7\r\n"); + GPIO_SetBits(GPIOA,GPIO_Pin_7); + } + else + { + GPIO_ResetBits(GPIOA,GPIO_Pin_7); + } +} + uint32_t get_light_data(void) { uint32_t data = 0; @@ -123,6 +189,22 @@ uint16_t get_pressure_data(void) return data; } +uint16_t get_pressure_temperature_data(void) +{ + uint16_t data; + init_pressure_temperature(); + + I2C_start(I2C1,DISTANCE_ADDR << 1, I2C_Direction_Transmitter); + I2C_write(I2C1, 0xF6); + I2C_stop(I2C1); + + I2C_start(I2C1, DISTANCE_ADDR << 1, I2C_Direction_Receiver); + data = I2C_read_ack(I2C1); + data = data << 8; + data = data | I2C_read_nack(I2C1); + return data; +} + bmp085_callibration get_pressure_callibration_data(void) { bmp085_callibration calib_data; @@ -234,6 +316,16 @@ void init_pressure(void) chThdSleepMilliseconds(5); } +void init_pressure_temperature(void) +{ + I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter); + I2C_write(I2C1, 0xF4); + I2C_write(I2C1, 0x2E); + I2C_stop(I2C1); + + chThdSleepMilliseconds(5); +} + void init_humidity_temp(void) { I2C_start(I2C1,HUMIDITY_TEMP_ADDR << 1, I2C_Direction_Transmitter); @@ -241,6 +333,7 @@ void init_humidity_temp(void) } uint16_t get_humidity_data(void) { + init_humidity_temp(); uint16_t data = 0; I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Receiver); data = I2C_read_ack(I2C1) & 0x3F; @@ -251,6 +344,7 @@ uint16_t get_humidity_data(void) } uint16_t get_temperature_data(void) { + init_humidity_temp(); uint16_t data = 0; I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Receiver); I2C_read_ack(I2C1); @@ -275,15 +369,15 @@ char* distance_value(uint16_t distance) sprintf(value,"%d",distance); return value; } -char* pressure_value(uint16_t pressure) +char* pressure_value(uint16_t pressure, uint16_t temperature) { - char *value = chHeapAlloc(NULL,5 + 1); - sprintf(value,"%d",pressure); + char *value = chHeapAlloc(NULL,11 + 1); + sprintf(value,"%d,%d",pressure,temperature); return value; } char* temp_humidity_value(uint16_t temp, uint16_t humidity) { - char *value = chHeapAlloc(NULL,21 + 1); + char *value = chHeapAlloc(NULL,11 + 1); sprintf(value,"%d,%d",temp,humidity); return value; } @@ -295,6 +389,7 @@ void init_sound(void) } uint32_t get_sound_data(void) { + init_sound(); return adc_sound_process(); } char* sound_value(uint32_t sound) @@ -345,15 +440,17 @@ void init_battery(void) uint32_t get_battery_data(void) { + init_battery(); return adc_batt_process(); } -char* battery_value(uint32_t sound) +char* battery_value(uint32_t battery) { char *value = chHeapAlloc(NULL,11 + 1); - sprintf(value,"%4u",(unsigned int)sound); + sprintf(value,"%4u",(unsigned int)battery); return value; } //light_value(get_light_data()); -//temp_humidity_value(get_temperature_data(),get_humidity_data()); \ No newline at end of file +//temp_humidity_value(get_temperature_data(),get_humidity_data()); +//pressure_value(get_pressure_data(), get_pressure_temperature_data()); \ No newline at end of file -- libgit2 0.22.2