Firmware SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
bc_tag_humidity.c
1 #include <bc_tag_humidity.h>
2 
3 static void _bc_tag_humidity_event_handler_hts221(bc_hts221_t *child, bc_hts221_event_t event, void *event_param);
4 
5 static void _bc_tag_humidity_event_handler_hdc2080(bc_hdc2080_t *child, bc_hdc2080_event_t event, void *event_param);
6 
7 static void _bc_tag_humidity_event_handler_sht20(bc_sht20_t *child, bc_sht20_event_t event, void *event_param);
8 
9 static void _bc_tag_humidity_event_handler_sht30(bc_sht30_t *child, bc_sht30_event_t event, void *event_param);
10 
12 {
13  memset(self, 0, sizeof(*self));
14 
15  self->_revision = revision;
16 
17  if (self->_revision == BC_TAG_HUMIDITY_REVISION_R1)
18  {
19  bc_hts221_init(&self->_sensor.hts221, i2c_channel, 0x5f);
20 
21  bc_hts221_set_event_handler(&self->_sensor.hts221, _bc_tag_humidity_event_handler_hts221, self);
22  }
23  else if (self->_revision == BC_TAG_HUMIDITY_REVISION_R2)
24  {
25  bc_hdc2080_init(&self->_sensor.hdc2080, i2c_channel, i2c_address == BC_TAG_HUMIDITY_I2C_ADDRESS_DEFAULT ? 0x40 : 0x41);
26 
27  bc_hdc2080_set_event_handler(&self->_sensor.hdc2080, _bc_tag_humidity_event_handler_hdc2080, self);
28  }
29  else if (self->_revision == BC_TAG_HUMIDITY_REVISION_R3)
30  {
31  bc_sht20_init(&self->_sensor.sht20, i2c_channel, 0x40);
32 
33  bc_sht20_set_event_handler(&self->_sensor.sht20, _bc_tag_humidity_event_handler_sht20, self);
34  }
35  else
36  {
37  bc_sht30_init(&self->_sensor.sht30, i2c_channel, i2c_address == BC_TAG_HUMIDITY_I2C_ADDRESS_DEFAULT ? 0x44 : 0x45);
38 
39  bc_sht30_set_event_handler(&self->_sensor.sht30, _bc_tag_humidity_event_handler_sht30, self);
40  }
41 }
42 
43 void bc_tag_humidity_set_event_handler(bc_tag_humidity_t *self, void (*event_handler)(bc_tag_humidity_t *, bc_tag_humidity_event_t, void *), void *event_param)
44 {
45  self->_event_handler = event_handler;
46  self->_event_param = event_param;
47 }
48 
50 {
51  if (self->_revision == BC_TAG_HUMIDITY_REVISION_R1)
52  {
53  bc_hts221_set_update_interval(&self->_sensor.hts221, interval);
54  }
55  else if (self->_revision == BC_TAG_HUMIDITY_REVISION_R2)
56  {
57  bc_hdc2080_set_update_interval(&self->_sensor.hdc2080, interval);
58  }
59  else if (self->_revision == BC_TAG_HUMIDITY_REVISION_R3)
60  {
61  bc_sht20_set_update_interval(&self->_sensor.sht20, interval);
62  }
63  else
64  {
65  bc_sht30_set_update_interval(&self->_sensor.sht30, interval);
66  }
67 }
68 
70 {
71  if (self->_revision == BC_TAG_HUMIDITY_REVISION_R1)
72  {
73  return bc_hts221_measure(&self->_sensor.hts221);
74  }
75  else if (self->_revision == BC_TAG_HUMIDITY_REVISION_R2)
76  {
77  return bc_hdc2080_measure(&self->_sensor.hdc2080);
78  }
79  else if (self->_revision == BC_TAG_HUMIDITY_REVISION_R3)
80  {
81  return bc_sht20_measure(&self->_sensor.sht20);
82  }
83  else
84  {
85  return bc_sht30_measure(&self->_sensor.sht30);
86  }
87 }
88 
90 {
91  if (self->_revision == BC_TAG_HUMIDITY_REVISION_R1)
92  {
93  return false;
94  }
95  else if (self->_revision == BC_TAG_HUMIDITY_REVISION_R2)
96  {
97  return bc_hdc2080_get_temperature_raw(&self->_sensor.hdc2080, raw);
98  }
99  else if (self->_revision == BC_TAG_HUMIDITY_REVISION_R3)
100  {
101  return bc_sht20_get_temperature_raw(&self->_sensor.sht20, raw);
102  }
103  else
104  {
105  return bc_sht30_get_temperature_raw(&self->_sensor.sht30, raw);
106  }
107 }
108 
110 {
111  if (self->_revision == BC_TAG_HUMIDITY_REVISION_R1)
112  {
113  return false;
114  }
115  else if (self->_revision == BC_TAG_HUMIDITY_REVISION_R2)
116  {
117  return bc_hdc2080_get_temperature_celsius(&self->_sensor.hdc2080, celsius);
118  }
119  else if (self->_revision == BC_TAG_HUMIDITY_REVISION_R3)
120  {
121  return bc_sht20_get_temperature_celsius(&self->_sensor.sht20, celsius);
122  }
123  else
124  {
125  return bc_sht30_get_temperature_celsius(&self->_sensor.sht30, celsius);
126  }
127 }
128 
130 {
131  if (self->_revision == BC_TAG_HUMIDITY_REVISION_R1)
132  {
133  return false;
134  }
135  else if (self->_revision == BC_TAG_HUMIDITY_REVISION_R2)
136  {
137  return bc_hdc2080_get_humidity_raw(&self->_sensor.hdc2080, raw);
138  }
139  else if (self->_revision == BC_TAG_HUMIDITY_REVISION_R3)
140  {
141  return bc_sht20_get_humidity_raw(&self->_sensor.sht20, raw);
142  }
143  else
144  {
145  return bc_sht30_get_humidity_raw(&self->_sensor.sht30, raw);
146  }
147 }
148 
150 {
151  if (self->_revision == BC_TAG_HUMIDITY_REVISION_R1)
152  {
153  return bc_hts221_get_humidity_percentage(&self->_sensor.hts221, percentage);
154  }
155  else if (self->_revision == BC_TAG_HUMIDITY_REVISION_R2)
156  {
157  return bc_hdc2080_get_humidity_percentage(&self->_sensor.hdc2080, percentage);
158  }
159  else if (self->_revision == BC_TAG_HUMIDITY_REVISION_R3)
160  {
161  return bc_sht20_get_humidity_percentage(&self->_sensor.sht20, percentage);
162  }
163  else
164  {
165  return bc_sht30_get_humidity_percentage(&self->_sensor.sht30, percentage);
166  }
167 }
168 
169 static void _bc_tag_humidity_event_handler_hts221(bc_hts221_t *child, bc_hts221_event_t event, void *event_param)
170 {
171  (void) child;
172 
173  bc_tag_humidity_t *self = event_param;
174 
175  if (self->_event_handler != NULL)
176  {
177  if (event == BC_HTS221_EVENT_UPDATE)
178  {
179  self->_event_handler(self, BC_TAG_HUMIDITY_EVENT_UPDATE, self->_event_param);
180  }
181  else if (event == BC_HTS221_EVENT_ERROR)
182  {
183  self->_event_handler(self, BC_TAG_HUMIDITY_EVENT_ERROR, self->_event_param);
184  }
185  }
186 }
187 
188 static void _bc_tag_humidity_event_handler_hdc2080(bc_hdc2080_t *child, bc_hdc2080_event_t event, void *event_param)
189 {
190  (void) child;
191 
192  bc_tag_humidity_t *self = event_param;
193 
194  if (self->_event_handler != NULL)
195  {
196  if (event == BC_HDC2080_EVENT_UPDATE)
197  {
198  self->_event_handler(self, BC_TAG_HUMIDITY_EVENT_UPDATE, self->_event_param);
199  }
200  else if (event == BC_HDC2080_EVENT_ERROR)
201  {
202  self->_event_handler(self, BC_TAG_HUMIDITY_EVENT_ERROR, self->_event_param);
203  }
204  }
205 }
206 
207 static void _bc_tag_humidity_event_handler_sht20(bc_sht20_t *child, bc_sht20_event_t event, void *event_param)
208 {
209  (void) child;
210 
211  bc_tag_humidity_t *self = event_param;
212 
213  if (self->_event_handler != NULL)
214  {
215  if (event == BC_SHT20_EVENT_UPDATE)
216  {
217  self->_event_handler(self, BC_TAG_HUMIDITY_EVENT_UPDATE, self->_event_param);
218  }
219  else if (event == BC_SHT20_EVENT_ERROR)
220  {
221  self->_event_handler(self, BC_TAG_HUMIDITY_EVENT_ERROR, self->_event_param);
222  }
223  }
224 }
225 
226 static void _bc_tag_humidity_event_handler_sht30(bc_sht30_t *child, bc_sht30_event_t event, void *event_param)
227 {
228  (void) child;
229 
230  bc_tag_humidity_t *self = event_param;
231 
232  if (self->_event_handler != NULL)
233  {
234  if (event == BC_SHT30_EVENT_UPDATE)
235  {
236  self->_event_handler(self, BC_TAG_HUMIDITY_EVENT_UPDATE, self->_event_param);
237  }
238  else if (event == BC_SHT30_EVENT_ERROR)
239  {
240  self->_event_handler(self, BC_TAG_HUMIDITY_EVENT_ERROR, self->_event_param);
241  }
242  }
243 }
bool bc_sht30_get_humidity_percentage(bc_sht30_t *self, float *percentage)
Get measured humidity as percentage.
Definition: bc_sht30.c:74
Error event.
Definition: bc_sht30.h:19
void bc_hdc2080_init(bc_hdc2080_t *self, bc_i2c_channel_t i2c_channel, uint8_t i2c_address)
Initialize HDC2080.
Definition: bc_hdc2080.c:12
struct bc_hdc2080_t bc_hdc2080_t
HDC2080 instance.
Definition: bc_hdc2080.h:25
uint64_t bc_tick_t
Timestamp data type.
Definition: bc_tick.h:16
Error event.
Definition: bc_sht20.h:16
bc_tag_humidity_event_t
Callback events.
bool bc_tag_humidity_measure(bc_tag_humidity_t *self)
Start measurement manually.
struct bc_sht30_t bc_sht30_t
SHT30 instance.
Definition: bc_sht30.h:28
void bc_tag_humidity_set_event_handler(bc_tag_humidity_t *self, void(*event_handler)(bc_tag_humidity_t *, bc_tag_humidity_event_t, void *), void *event_param)
Set callback function.
Update event.
Definition: bc_sht20.h:19
bc_hts221_event_t
Callback events.
Definition: bc_hts221.h:13
bool bc_sht30_get_temperature_raw(bc_sht30_t *self, uint16_t *raw)
Get measured temperature as raw value.
Definition: bc_sht30.c:97
struct bc_tag_humidity_t bc_tag_humidity_t
BigClown Humidity Tag instance.
bool bc_sht20_measure(bc_sht20_t *self)
Start measurement manually.
Definition: bc_sht20.c:51
bool bc_tag_humidity_get_humidity_percentage(bc_tag_humidity_t *self, float *percentage)
Get measured humidity as percentage.
Update event.
Definition: bc_sht30.h:22
Hardware revision R1.
void bc_tag_humidity_init(bc_tag_humidity_t *self, bc_tag_humidity_revision_t revision, bc_i2c_channel_t i2c_channel, bc_tag_humidity_i2c_address_t i2c_address)
Initialize BigClown Humidity Tag.
bc_sht30_event_t
Callback events.
Definition: bc_sht30.h:16
Update event.
Definition: bc_hts221.h:19
bc_sht20_event_t
Callback events.
Definition: bc_sht20.h:13
bc_hdc2080_event_t
Callback events.
Definition: bc_hdc2080.h:13
void bc_sht30_init(bc_sht30_t *self, bc_i2c_channel_t i2c_channel, uint8_t i2c_address)
Initialize SHT30.
Definition: bc_sht30.c:11
void bc_hts221_set_update_interval(bc_hts221_t *self, bc_tick_t interval)
Set measurement interval.
Definition: bc_hts221.c:77
void bc_sht30_set_update_interval(bc_sht30_t *self, bc_tick_t interval)
Set measurement interval.
Definition: bc_sht30.c:32
void bc_hdc2080_set_event_handler(bc_hdc2080_t *self, void(*event_handler)(bc_hdc2080_t *, bc_hdc2080_event_t, void *), void *event_param)
Set callback function.
Definition: bc_hdc2080.c:27
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_hts221_measure(bc_hts221_t *self)
Start measurement manually.
Definition: bc_hts221.c:93
bc_tag_humidity_i2c_address_t
I2C address.
void bc_sht30_set_event_handler(bc_sht30_t *self, void(*event_handler)(bc_sht30_t *, bc_sht30_event_t, void *), void *event_param)
Set callback function.
Definition: bc_sht30.c:26
bool bc_tag_humidity_get_temperature_raw(bc_tag_humidity_t *self, uint16_t *raw)
Get measured temperature as raw value.
Hardware revision R3.
void bc_hts221_init(bc_hts221_t *self, bc_i2c_channel_t i2c_channel, uint8_t i2c_address)
Initialize HTS221.
Definition: bc_hts221.c:53
bool bc_hts221_get_humidity_percentage(bc_hts221_t *self, float *percentage)
Get measured humidity as percentage.
Definition: bc_hts221.c:107
Error event.
Definition: bc_hdc2080.h:16
Error event.
Definition: bc_hts221.h:16
struct bc_hts221_t bc_hts221_t
HTS221 instance.
Definition: bc_hts221.h:25
bool bc_sht20_get_humidity_percentage(bc_sht20_t *self, float *percentage)
Get measured humidity as percentage.
Definition: bc_sht20.c:77
bool bc_hdc2080_get_humidity_raw(bc_hdc2080_t *self, uint16_t *raw)
Get measured humidity as raw value.
Definition: bc_hdc2080.c:63
bool bc_tag_humidity_get_humidity_raw(bc_tag_humidity_t *self, uint16_t *raw)
Get measured humidity as raw value.
bool bc_hdc2080_get_humidity_percentage(bc_hdc2080_t *self, float *percentage)
Get measured humidity as percentage.
Definition: bc_hdc2080.c:75
struct bc_sht20_t bc_sht20_t
SHT20 instance.
Definition: bc_sht20.h:25
bool bc_sht20_get_humidity_raw(bc_sht20_t *self, uint16_t *raw)
Get measured humidity as raw value.
Definition: bc_sht20.c:65
bool bc_hdc2080_measure(bc_hdc2080_t *self)
Start measurement manually.
Definition: bc_hdc2080.c:49
Update event.
Definition: bc_hdc2080.h:19
bc_i2c_channel_t
I2C channels.
Definition: bc_i2c.h:15
void bc_sht20_set_update_interval(bc_sht20_t *self, bc_tick_t interval)
Set measurement interval.
Definition: bc_sht20.c:35
bool bc_tag_humidity_get_temperature_celsius(bc_tag_humidity_t *self, float *celsius)
Get measured temperature in degrees of Celsius.
bool bc_sht30_get_humidity_raw(bc_sht30_t *self, uint16_t *raw)
Get measured humidity as raw value.
Definition: bc_sht30.c:62
bool bc_hdc2080_get_temperature_raw(bc_hdc2080_t *self, uint16_t *raw)
Get measured temperature as raw value.
Definition: bc_hdc2080.c:94
bool bc_sht30_measure(bc_sht30_t *self)
Start measurement manually.
Definition: bc_sht30.c:48
bool bc_hdc2080_get_temperature_celsius(bc_hdc2080_t *self, float *celsius)
Get measured temperature in degrees of Celsius.
Definition: bc_hdc2080.c:106
bool bc_sht20_get_temperature_raw(bc_sht20_t *self, uint16_t *raw)
Get measured temperature as raw value.
Definition: bc_sht20.c:100
bool bc_sht30_get_temperature_celsius(bc_sht30_t *self, float *celsius)
Get measured temperature in degrees of Celsius.
Definition: bc_sht30.c:109
bc_tag_humidity_revision_t
Humidity Tag hardware revision.
void bc_hdc2080_set_update_interval(bc_hdc2080_t *self, bc_tick_t interval)
Set measurement interval.
Definition: bc_hdc2080.c:33
bool bc_sht20_get_temperature_celsius(bc_sht20_t *self, float *celsius)
Get measured temperature in degrees of Celsius.
Definition: bc_sht20.c:112
void bc_tag_humidity_set_update_interval(bc_tag_humidity_t *self, bc_tick_t interval)
Set measurement interval.
void bc_hts221_set_event_handler(bc_hts221_t *self, void(*event_handler)(bc_hts221_t *, bc_hts221_event_t, void *), void *event_param)
Set callback function.
Definition: bc_hts221.c:71
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
Hardware revision R2.