From 2da24931950fe78f801930839a30fed92d8856c1 Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Thu, 22 May 2014 07:53:09 +0000 Subject: [PATCH] --- Project/applications/smartcities/adc.h | 2 +- Project/applications/smartcities/include/sensors.h | 12 ++++++++++-- Project/applications/smartcities/sensors.c | 23 +++++++++++++++++++++-- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/Project/applications/smartcities/adc.h b/Project/applications/smartcities/adc.h index 85a8a47..97c7d07 100644 --- a/Project/applications/smartcities/adc.h +++ b/Project/applications/smartcities/adc.h @@ -12,7 +12,7 @@ #define ADCbatt_MIN_VALUE (0) #define ADCbatt_MAX_VALUE (0xfff) /* 12-bit adc */ #define ADCbatt_VREF_PLUS (3300) /* Vref+ is connected with Vdda (3.3v) */ -#define ADCbatt_VREF_MINUS (0) /* Vref- is connected with Vssa (0v) */ +#define ADCbatt_VREF_MINUS (2300) /* Vref- is connected with Vssa (2.1v) */ #define ADCsound_MIN_VALUE (0) #define ADCsound_MAX_VALUE (0xfff) /* 12-bit adc */ diff --git a/Project/applications/smartcities/include/sensors.h b/Project/applications/smartcities/include/sensors.h index c27050f..50a1adf 100644 --- a/Project/applications/smartcities/include/sensors.h +++ b/Project/applications/smartcities/include/sensors.h @@ -12,9 +12,11 @@ #define DISTANCE_ADDR 0x01 #define PRESSURE_ADDR 0x77 //Cambiar a MPL115A #define HUMIDITY_TEMP_ADDR 0x27 -#define SOUND_ADDR 0x27 +#define SOUND_ADDR 0x72 //REMEMBER TO UPDATE I2C_scan ROUTINE WITH EACH NEW SENSOR!!!! -#define TOTAL_SENSORS 4 +#define TOTAL_SENSORS 5 + +#define BATTERY_ADDR 0x00 //SIEMPRE PRESENTE, NUNCA BUSCAR EN i2c_scan typedef struct { uint8_t ID; @@ -81,4 +83,10 @@ void init_sound(void); uint32_t get_sound_data(void); char* sound_value(uint32_t sound); +//BATTERY SENSOR + +void init_battery(void); +uint32_t get_battery_data(void); +char* battery_value(uint32_t sound); + #endif diff --git a/Project/applications/smartcities/sensors.c b/Project/applications/smartcities/sensors.c index 40f04f6..ece4d1a 100644 --- a/Project/applications/smartcities/sensors.c +++ b/Project/applications/smartcities/sensors.c @@ -4,6 +4,8 @@ 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 sound_sensor = {SOUND_ADDR, "Sound sensor","mV",NULL}; +sensor battery = {BATTERY_ADDR, "Battery Level","mV",NULL}; uint32_t get_light_data(void) { @@ -297,8 +299,25 @@ uint32_t get_sound_data(void) } char* sound_value(uint32_t sound) { - char *value = chHeapAlloc(NULL,21 + 1); - sprintf(value,"%d",(unsigned int)sound); + char *value = chHeapAlloc(NULL,11 + 1); + sprintf(value,"%4u",(unsigned int)sound); + return value; +} + +void init_battery(void) +{ + adc_batt_init(); +} + +uint32_t get_battery_data(void) +{ + return adc_batt_process(); +} + +char* battery_value(uint32_t sound) +{ + char *value = chHeapAlloc(NULL,11 + 1); + sprintf(value,"%4u",(unsigned int)sound); return value; } -- libgit2 0.22.2