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; }