Firmware SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
bc_module_climate.c
1 #include <bc_module_climate.h>
2 #include <bc_tmp112.h>
3 #include <bc_sht20.h>
4 #include <bc_opt3001.h>
5 #include <bc_mpl3115a2.h>
6 
7 static struct
8 {
9  void (*event_handler)(bc_module_climate_event_t, void *);
10  void *event_param;
11  bc_tmp112_t tmp112;
12  bc_sht20_t sht20;
13  bc_opt3001_t opt3001;
14  bc_mpl3115a2_t mpl3115a2;
15 
16 } _bc_module_climate;
17 
18 static void _bc_module_climate_tmp112_event_handler(bc_tmp112_t *self, bc_tmp112_event_t event, void *event_param);
19 
20 static void _bc_module_climate_sht20_event_handler(bc_sht20_t *self, bc_sht20_event_t event, void *event_param);
21 
22 static void _bc_module_climate_opt3001_event_handler(bc_opt3001_t *self, bc_opt3001_event_t event, void *event_param);
23 
24 static void _bc_module_climate_mpl3115a2_event_handler(bc_mpl3115a2_t *self, bc_mpl3115a2_event_t event, void *event_param);
25 
27 {
28  memset(&_bc_module_climate, 0, sizeof(_bc_module_climate));
29 
30  bc_tmp112_init(&_bc_module_climate.tmp112, BC_I2C_I2C0, 0x48);
31  bc_tmp112_set_event_handler(&_bc_module_climate.tmp112, _bc_module_climate_tmp112_event_handler, NULL);
32 
33  bc_sht20_init(&_bc_module_climate.sht20, BC_I2C_I2C0, 0x40);
34  bc_sht20_set_event_handler(&_bc_module_climate.sht20, _bc_module_climate_sht20_event_handler, NULL);
35 
36  bc_opt3001_init(&_bc_module_climate.opt3001, BC_I2C_I2C0, 0x44);
37  bc_opt3001_set_event_handler(&_bc_module_climate.opt3001, _bc_module_climate_opt3001_event_handler, NULL);
38 
39  bc_mpl3115a2_init(&_bc_module_climate.mpl3115a2, BC_I2C_I2C0, 0x60);
40  bc_mpl3115a2_set_event_handler(&_bc_module_climate.mpl3115a2, _bc_module_climate_mpl3115a2_event_handler, NULL);
41 }
42 
43 void bc_module_climate_set_event_handler(void (*event_handler)(bc_module_climate_event_t, void *), void *event_param)
44 {
45  _bc_module_climate.event_handler = event_handler;
46  _bc_module_climate.event_param = event_param;
47 }
48 
50 {
51  bc_tmp112_set_update_interval(&_bc_module_climate.tmp112, interval);
52  bc_sht20_set_update_interval(&_bc_module_climate.sht20, interval);
53  bc_opt3001_set_update_interval(&_bc_module_climate.opt3001, interval);
54  bc_mpl3115a2_set_update_interval(&_bc_module_climate.mpl3115a2, interval);
55 }
56 
58 {
59  bc_tmp112_set_update_interval(&_bc_module_climate.tmp112, interval);
60 }
61 
63 {
64  bc_sht20_set_update_interval(&_bc_module_climate.sht20, interval);
65 }
66 
68 {
69  bc_opt3001_set_update_interval(&_bc_module_climate.opt3001, interval);
70 }
71 
73 {
74  bc_mpl3115a2_set_update_interval(&_bc_module_climate.mpl3115a2, interval);
75 }
76 
78 {
79  bool ret = true;
80 
81  if (!bc_tmp112_measure(&_bc_module_climate.tmp112))
82  {
83  ret = false;
84  }
85 
86  if (!bc_sht20_measure(&_bc_module_climate.sht20))
87  {
88  ret = false;
89  }
90 
91  if (!bc_opt3001_measure(&_bc_module_climate.opt3001))
92  {
93  ret = false;
94  }
95 
96  if (!bc_mpl3115a2_measure(&_bc_module_climate.mpl3115a2))
97  {
98  ret = false;
99  }
100 
101  return ret;
102 }
103 
105 {
106  return bc_tmp112_measure(&_bc_module_climate.tmp112);
107 }
108 
110 {
111  return bc_sht20_measure(&_bc_module_climate.sht20);
112 }
113 
115 {
116  return bc_opt3001_measure(&_bc_module_climate.opt3001);
117 }
118 
120 {
121  return bc_mpl3115a2_measure(&_bc_module_climate.mpl3115a2);
122 }
123 
125 {
126  return bc_tmp112_get_temperature_celsius(&_bc_module_climate.tmp112, celsius);
127 }
128 
130 {
131  return bc_tmp112_get_temperature_fahrenheit(&_bc_module_climate.tmp112, fahrenheit);
132 }
133 
135 {
136  return bc_tmp112_get_temperature_kelvin(&_bc_module_climate.tmp112, kelvin);
137 }
138 
140 {
141  return bc_sht20_get_humidity_percentage(&_bc_module_climate.sht20, percentage);
142 }
143 
145 {
146  return bc_opt3001_get_illuminance_lux(&_bc_module_climate.opt3001, lux);
147 }
148 
150 {
151  return bc_mpl3115a2_get_altitude_meter(&_bc_module_climate.mpl3115a2, meter);
152 }
153 
155 {
156  return bc_mpl3115a2_get_pressure_pascal(&_bc_module_climate.mpl3115a2, pascal);
157 }
158 
159 static void _bc_module_climate_tmp112_event_handler(bc_tmp112_t *self, bc_tmp112_event_t event, void *event_param)
160 {
161  (void) self;
162  (void) event_param;
163 
164  if (_bc_module_climate.event_handler == NULL)
165  {
166  return;
167  }
168 
169  if (event == BC_TMP112_EVENT_UPDATE)
170  {
171  _bc_module_climate.event_handler(BC_MODULE_CLIMATE_EVENT_UPDATE_THERMOMETER, _bc_module_climate.event_param);
172  }
173  else if (event == BC_TMP112_EVENT_ERROR)
174  {
175  _bc_module_climate.event_handler(BC_MODULE_CLIMATE_EVENT_ERROR_THERMOMETER, _bc_module_climate.event_param);
176  }
177 }
178 
179 static void _bc_module_climate_sht20_event_handler(bc_sht20_t *self, bc_sht20_event_t event, void *event_param)
180 {
181  (void) self;
182  (void) event_param;
183 
184  if (_bc_module_climate.event_handler == NULL)
185  {
186  return;
187  }
188 
189  if (event == BC_SHT20_EVENT_UPDATE)
190  {
191  _bc_module_climate.event_handler(BC_MODULE_CLIMATE_EVENT_UPDATE_HYGROMETER, _bc_module_climate.event_param);
192  }
193  else if (event == BC_SHT20_EVENT_ERROR)
194  {
195  _bc_module_climate.event_handler(BC_MODULE_CLIMATE_EVENT_ERROR_HYGROMETER, _bc_module_climate.event_param);
196  }
197 }
198 
199 static void _bc_module_climate_opt3001_event_handler(bc_opt3001_t *self, bc_opt3001_event_t event, void *event_param)
200 {
201  (void) self;
202  (void) event_param;
203 
204  if (_bc_module_climate.event_handler == NULL)
205  {
206  return;
207  }
208 
209  if (event == BC_OPT3001_EVENT_UPDATE)
210  {
211  _bc_module_climate.event_handler(BC_MODULE_CLIMATE_EVENT_UPDATE_LUX_METER, _bc_module_climate.event_param);
212  }
213  else if (event == BC_OPT3001_EVENT_ERROR)
214  {
215  _bc_module_climate.event_handler(BC_MODULE_CLIMATE_EVENT_ERROR_LUX_METER, _bc_module_climate.event_param);
216  }
217 }
218 
219 static void _bc_module_climate_mpl3115a2_event_handler(bc_mpl3115a2_t *self, bc_mpl3115a2_event_t event, void *event_param)
220 {
221  (void) self;
222  (void) event_param;
223 
224  if (_bc_module_climate.event_handler == NULL)
225  {
226  return;
227  }
228 
229  if (event == BC_MPL3115A2_EVENT_UPDATE)
230  {
231  _bc_module_climate.event_handler(BC_MODULE_CLIMATE_EVENT_UPDATE_BAROMETER, _bc_module_climate.event_param);
232  }
233  else if (event == BC_MPL3115A2_EVENT_ERROR)
234  {
235  _bc_module_climate.event_handler(BC_MODULE_CLIMATE_EVENT_ERROR_BAROMETER, _bc_module_climate.event_param);
236  }
237 }
bool bc_module_climate_measure_all_sensors(void)
Start measurement of all sensors manually.
void bc_opt3001_set_event_handler(bc_opt3001_t *self, void(*event_handler)(bc_opt3001_t *, bc_opt3001_event_t, void *), void *event_param)
Set callback function.
Definition: bc_opt3001.c:26
bool bc_module_climate_get_altitude_meter(float *meter)
Get measured altitude in meters.
void bc_tmp112_init(bc_tmp112_t *self, bc_i2c_channel_t i2c_channel, uint8_t i2c_address)
Initialize TMP112.
Definition: bc_tmp112.c:11
uint64_t bc_tick_t
Timestamp data type.
Definition: bc_tick.h:16
Error event.
Definition: bc_sht20.h:16
void bc_opt3001_set_update_interval(bc_opt3001_t *self, bc_tick_t interval)
Set measurement interval.
Definition: bc_opt3001.c:32
bc_tmp112_event_t
Callback events.
Definition: bc_tmp112.h:13
Update event.
Definition: bc_sht20.h:19
bool bc_module_climate_measure_thermometer(void)
Start thermometer measurement manually.
struct bc_mpl3115a2_t bc_mpl3115a2_t
MPL3115A2 instance.
Definition: bc_mpl3115a2.h:25
bool bc_module_climate_get_temperature_celsius(float *celsius)
Get measured temperature in degrees of Celsius.
I2C channel I2C0.
Definition: bc_i2c.h:18
bool bc_sht20_measure(bc_sht20_t *self)
Start measurement manually.
Definition: bc_sht20.c:51
bool bc_mpl3115a2_get_pressure_pascal(bc_mpl3115a2_t *self, float *pascal)
Get measured pressured in Pascal.
Definition: bc_mpl3115a2.c:76
bool bc_opt3001_measure(bc_opt3001_t *self)
Start measurement manually.
Definition: bc_opt3001.c:48
void bc_module_climate_set_update_interval_thermometer(bc_tick_t interval)
Set measurement interval for thermometer.
bool bc_module_climate_get_pressure_pascal(float *pascal)
Get measured pressure in Pascal.
void bc_module_climate_set_update_interval_barometer(bc_tick_t interval)
Set measurement interval for barometer.
Update event.
Definition: bc_tmp112.h:19
void bc_module_climate_set_update_interval_all_sensors(bc_tick_t interval)
Set measurement interval for all sensors.
bc_sht20_event_t
Callback events.
Definition: bc_sht20.h:13
void bc_module_climate_set_update_interval_hygrometer(bc_tick_t interval)
Set measurement interval for hygrometer.
bool bc_opt3001_get_illuminance_lux(bc_opt3001_t *self, float *lux)
Get measured illuminance in lux.
Definition: bc_opt3001.c:74
bool bc_tmp112_get_temperature_fahrenheit(bc_tmp112_t *self, float *fahrenheit)
Get measured temperature in degrees of Fahrenheit.
Definition: bc_tmp112.c:97
void bc_tmp112_set_update_interval(bc_tmp112_t *self, bc_tick_t interval)
Set measurement interval.
Definition: bc_tmp112.c:41
struct bc_tmp112_t bc_tmp112_t
TMP112 instance.
Definition: bc_tmp112.h:25
bc_mpl3115a2_event_t
Callback events.
Definition: bc_mpl3115a2.h:13
void bc_mpl3115a2_init(bc_mpl3115a2_t *self, bc_i2c_channel_t i2c_channel, uint8_t i2c_address)
Initialize MPL3115A2.
Definition: bc_mpl3115a2.c:11
Error event.
Definition: bc_tmp112.h:16
void bc_opt3001_init(bc_opt3001_t *self, bc_i2c_channel_t i2c_channel, uint8_t i2c_address)
Initialize OPT3001 driver.
Definition: bc_opt3001.c:11
bool bc_tmp112_get_temperature_kelvin(bc_tmp112_t *self, float *kelvin)
Get measured temperature in kelvin.
Definition: bc_tmp112.c:111
void bc_sht20_init(bc_sht20_t *self, bc_i2c_channel_t i2c_channel, uint8_t i2c_address)
Initialize SHT20.
Definition: bc_sht20.c:14
bool bc_tmp112_get_temperature_celsius(bc_tmp112_t *self, float *celsius)
Get measured temperature in degrees of Celsius.
Definition: bc_tmp112.c:83
bc_module_climate_event_t
Callback events.
bool bc_module_climate_measure_lux_meter(void)
Start lux meter measurement manually.
bool bc_sht20_get_humidity_percentage(bc_sht20_t *self, float *percentage)
Get measured humidity as percentage.
Definition: bc_sht20.c:77
bc_opt3001_event_t
Callback events.
Definition: bc_opt3001.h:13
void bc_module_climate_set_update_interval_lux_meter(bc_tick_t interval)
Set measurement interval for lux meter.
void bc_tmp112_set_event_handler(bc_tmp112_t *self, void(*event_handler)(bc_tmp112_t *, bc_tmp112_event_t, void *), void *event_param)
Set callback function.
Definition: bc_tmp112.c:35
bool bc_mpl3115a2_get_altitude_meter(bc_mpl3115a2_t *self, float *meter)
Get measured altitude in meters.
Definition: bc_mpl3115a2.c:62
struct bc_sht20_t bc_sht20_t
SHT20 instance.
Definition: bc_sht20.h:25
Error event.
Definition: bc_opt3001.h:16
void bc_sht20_set_update_interval(bc_sht20_t *self, bc_tick_t interval)
Set measurement interval.
Definition: bc_sht20.c:35
void bc_mpl3115a2_set_event_handler(bc_mpl3115a2_t *self, void(*event_handler)(bc_mpl3115a2_t *, bc_mpl3115a2_event_t, void *), void *event_param)
Set callback function.
Definition: bc_mpl3115a2.c:26
struct bc_opt3001_t bc_opt3001_t
OPT3001 instance.
Definition: bc_opt3001.h:25
bool bc_module_climate_get_humidity_percentage(float *percentage)
Get measured humidity as percentage.
bool bc_module_climate_get_temperature_fahrenheit(float *fahrenheit)
Get measured temperature in degrees of Fahrenheit.
void bc_module_climate_init(void)
Initialize BigClown Climate Module.
bool bc_module_climate_get_temperature_kelvin(float *kelvin)
Get measured temperature in kelvin.
bool bc_module_climate_get_illuminance_lux(float *lux)
Get measured illuminance in lux.
bool bc_module_climate_measure_hygrometer(void)
Start hygrometer measurement manually.
bool bc_module_climate_measure_barometer(void)
Start barometer measurement manually.
bool bc_mpl3115a2_measure(bc_mpl3115a2_t *self)
Start measurement manually.
Definition: bc_mpl3115a2.c:48
void bc_mpl3115a2_set_update_interval(bc_mpl3115a2_t *self, bc_tick_t interval)
Set measurement interval.
Definition: bc_mpl3115a2.c:32
bool bc_tmp112_measure(bc_tmp112_t *self)
Start measurement manually.
Definition: bc_tmp112.c:57
Update event.
Definition: bc_opt3001.h:19
void bc_sht20_set_event_handler(bc_sht20_t *self, void(*event_handler)(bc_sht20_t *, bc_sht20_event_t, void *), void *event_param)
Set callback function.
Definition: bc_sht20.c:29
void bc_module_climate_set_event_handler(void(*event_handler)(bc_module_climate_event_t, void *), void *event_param)
Set callback function.