Commit 2da24931950fe78f801930839a30fed92d8856c1

Authored by Imanol-Mikel Barba Sabariego
1 parent 232c7713

--no commit message

Project/applications/smartcities/adc.h
... ... @@ -12,7 +12,7 @@
12 12 #define ADCbatt_MIN_VALUE (0)
13 13 #define ADCbatt_MAX_VALUE (0xfff) /* 12-bit adc */
14 14 #define ADCbatt_VREF_PLUS (3300) /* Vref+ is connected with Vdda (3.3v) */
15   -#define ADCbatt_VREF_MINUS (0) /* Vref- is connected with Vssa (0v) */
  15 +#define ADCbatt_VREF_MINUS (2300) /* Vref- is connected with Vssa (2.1v) */
16 16  
17 17 #define ADCsound_MIN_VALUE (0)
18 18 #define ADCsound_MAX_VALUE (0xfff) /* 12-bit adc */
... ...
Project/applications/smartcities/include/sensors.h
... ... @@ -12,9 +12,11 @@
12 12 #define DISTANCE_ADDR 0x01
13 13 #define PRESSURE_ADDR 0x77 //Cambiar a MPL115A
14 14 #define HUMIDITY_TEMP_ADDR 0x27
15   -#define SOUND_ADDR 0x27
  15 +#define SOUND_ADDR 0x72
16 16 //REMEMBER TO UPDATE I2C_scan ROUTINE WITH EACH NEW SENSOR!!!!
17   -#define TOTAL_SENSORS 4
  17 +#define TOTAL_SENSORS 5
  18 +
  19 +#define BATTERY_ADDR 0x00 //SIEMPRE PRESENTE, NUNCA BUSCAR EN i2c_scan
18 20  
19 21 typedef struct {
20 22 uint8_t ID;
... ... @@ -81,4 +83,10 @@ void init_sound(void);
81 83 uint32_t get_sound_data(void);
82 84 char* sound_value(uint32_t sound);
83 85  
  86 +//BATTERY SENSOR
  87 +
  88 +void init_battery(void);
  89 +uint32_t get_battery_data(void);
  90 +char* battery_value(uint32_t sound);
  91 +
84 92 #endif
... ...
Project/applications/smartcities/sensors.c
... ... @@ -4,6 +4,8 @@ sensor light_sensor = {LIGHT_ADDR, "Light sensor", "illumination", "lux",NULL}
4 4 sensor ultrasound_sensor = {DISTANCE_ADDR, "Ultrasound sensor", "distance", "cm",NULL};
5 5 sensor pressure_sensor = {PRESSURE_ADDR, "Pressure sensor", "pressure", "kPa",NULL};
6 6 sensor humidity_temp_sensor = {HUMIDITY_TEMP_ADDR, "Humidity and Temperature","ºC,RH",NULL};
  7 +sensor sound_sensor = {SOUND_ADDR, "Sound sensor","mV",NULL};
  8 +sensor battery = {BATTERY_ADDR, "Battery Level","mV",NULL};
7 9  
8 10 uint32_t get_light_data(void)
9 11 {
... ... @@ -297,8 +299,25 @@ uint32_t get_sound_data(void)
297 299 }
298 300 char* sound_value(uint32_t sound)
299 301 {
300   - char *value = chHeapAlloc(NULL,21 + 1);
301   - sprintf(value,"%d",(unsigned int)sound);
  302 + char *value = chHeapAlloc(NULL,11 + 1);
  303 + sprintf(value,"%4u",(unsigned int)sound);
  304 + return value;
  305 +}
  306 +
  307 +void init_battery(void)
  308 +{
  309 + adc_batt_init();
  310 +}
  311 +
  312 +uint32_t get_battery_data(void)
  313 +{
  314 + return adc_batt_process();
  315 +}
  316 +
  317 +char* battery_value(uint32_t sound)
  318 +{
  319 + char *value = chHeapAlloc(NULL,11 + 1);
  320 + sprintf(value,"%4u",(unsigned int)sound);
302 321 return value;
303 322 }
304 323  
... ...