From ba4f550806460eb5d2124aae9022b5a0b54270c6 Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Tue, 20 May 2014 11:25:29 +0000 Subject: [PATCH] --- Project/applications/smartcities/include/sensors.h | 7 ++++++- Project/applications/smartcities/sensors.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Project/applications/smartcities/include/sensors.h b/Project/applications/smartcities/include/sensors.h index a2e80ac..6adb26f 100644 --- a/Project/applications/smartcities/include/sensors.h +++ b/Project/applications/smartcities/include/sensors.h @@ -10,7 +10,7 @@ #define LIGHT_ADDR 0x39 #define DISTANCE_ADDR 0x01 -#define PRESSURE_ADDR 0x77 +#define PRESSURE_ADDR 0x77 //Cambiar a MPL115A #define HUMIDITY_TEMP_ADDR 0x27 //REMEMBER TO UPDATE I2C_scan ROUTINE WITH EACH NEW SENSOR!!!! #define TOTAL_SENSORS 4 @@ -36,12 +36,15 @@ extern sensor pressure_sensor; uint32_t get_light_data(void); uint16_t get_light_ch0(void); uint16_t get_light_ch1(void); +char* light_value(uint32_t light); //ULTRASONIC SENSOR uint16_t get_distance_data(void); void init_ultrasound(void); uint8_t get_distance_low(void); uint8_t get_distance_high(void); +char* distance_value(uint16_t distance); + //PRESSURE SENSOR typedef struct { @@ -61,6 +64,7 @@ typedef struct { uint16_t get_pressure_data(void); bmp085_callibration get_pressure_callibration_data(void); char* callibration_pressure_data_csv(bmp085_callibration parameters); +char* pressure_value(uint16_t pressure); void init_pressure(void); //HUMIDITY AND TEMPERATURE SENSOR @@ -68,5 +72,6 @@ void init_pressure(void); void init_humidity_temp(void); uint16_t get_humidity_data(void); uint16_t get_temperature_data(void); +char* temp_humidity_value(uint16_t temp, uint16_t humidity); #endif diff --git a/Project/applications/smartcities/sensors.c b/Project/applications/smartcities/sensors.c index a702178..61356da 100644 --- a/Project/applications/smartcities/sensors.c +++ b/Project/applications/smartcities/sensors.c @@ -3,7 +3,7 @@ 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 humidity_temp_sensor = {HUMIDITY_TEMP_ADDR, "Humidity and Temperature","ºC,RH",NULL}; +sensor humidity_temp_sensor = {HUMIDITY_TEMP_ADDR, "Humidity and Temperature","ºC,RH",NULL}; uint32_t get_light_data(void) { @@ -260,3 +260,31 @@ uint16_t get_temperature_data(void) I2C_stop(I2C1); return data; } + +char* light_value(uint32_t light) +{ + char *value = chHeapAlloc(NULL,10 + 1); + sprintf(value,"%d",light); + return value; +} +char* distance_value(uint16_t distance) +{ + char *value = chHeapAlloc(NULL,5 + 1); + sprintf(value,"%d",distance); + return value; +} +char* pressure_value(uint16_t pressure) +{ + char *value = chHeapAlloc(NULL,5 + 1); + sprintf(value,"%d",pressure); + return value; +} +char* temp_humidity_value(uint16_t temp, uint16_t humidity) +{ + char *value = chHeapAlloc(NULL,21 + 1); + sprintf(value,"%d,%d",temp,humidity); + return value; +} + +//light_value(get_light_data()); +//temp_humidity_value(get_temperature_data(),get_humidity_data()); \ No newline at end of file -- libgit2 0.22.2