sensors.h
2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef SENSORS_H
#define SENSORS_H
#include <stdint.h>
#include <stdio.h>
#include "i2c.h"
#include "libwismart.h"
#include "module.h"
#include "adc.h"
#define LIGHT_ADDR 0x39
#define DISTANCE_ADDR 0x01
#define PRESSURE_ADDR 0x77
#define HUMIDITY_TEMP_ADDR 0x27
#define SOUND_ADDR 0x72
#define TOTAL_SENSORS 5
//REMEMBER TO UPDATE collectData ROUTINE WITH EACH NEW SENSOR!!!!
//REMEMBER TO UPDATE I2C sensors in sensor definitions in this header and sensors.c WITH EACH NEW SENSOR!!!!
#define BATTERY_ADDR 0x00 //SIEMPRE PRESENTE, NUNCA BUSCAR EN i2c_scan
#define DBG_SENSORS(fmt,...) printf("%c[1;35msensors.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
//#define DBG_SENSORS(fmt,...) printf("")
typedef struct {
uint8_t ID;
char* description;
char* type;
char* unit;
} sensor;
void wakeup_sensors(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;
extern sensor* sensors[TOTAL_SENSORS+1];
//SENSOR FUNCTIONS
//LIGHT SENSOR
void init_light(void);
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);
char* distance_value(uint16_t distance);
//PRESSURE SENSOR
typedef struct bmp085_callibration bmp085_callibration_t;
struct bmp085_callibration {
uint16_t AC1;
uint16_t AC2;
uint16_t AC3;
uint16_t AC4;
uint16_t AC5;
uint16_t AC6;
uint16_t B1;
uint16_t B2;
uint16_t MB;
uint16_t MC;
uint16_t MD;
};
void init_pressure(void);
void init_pressure_temperature(void);
uint16_t get_pressure_data(void);
uint16_t get_pressure_temperature_data(void);
void get_pressure_callibration_data(bmp085_callibration_t *calib_data);
char* callibration_pressure_data_csv(bmp085_callibration_t *parameters);
char* pressure_value(uint16_t pressure,uint16_t temperature);
//HUMIDITY AND TEMPERATURE SENSOR
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);
//SOUND SENSOR
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 battery);
//Collect function
void collectData(char* valueSensors[], uint8_t* sensors);
#endif