Firmware SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
bc_sht20.h
1 #ifndef _BC_SHT20_H
2 #define _BC_SHT20_H
3 
4 #include <bc_i2c.h>
5 #include <bc_scheduler.h>
6 
10 
12 
13 typedef enum
14 {
17 
20 
22 
24 
25 typedef struct bc_sht20_t bc_sht20_t;
26 
28 
29 typedef enum
30 {
31  BC_SHT20_STATE_ERROR = -1,
32  BC_SHT20_STATE_INITIALIZE = 0,
33  BC_SHT20_STATE_MEASURE_RH = 1,
34  BC_SHT20_STATE_READ_RH = 2,
35  BC_SHT20_STATE_MEASURE_T = 3,
36  BC_SHT20_STATE_READ_T = 4,
37  BC_SHT20_STATE_UPDATE = 5
38 
39 } bc_sht20_state_t;
40 
41 struct bc_sht20_t
42 {
43  bc_i2c_channel_t _i2c_channel;
44  uint8_t _i2c_address;
45  bc_scheduler_task_id_t _task_id_interval;
46  bc_scheduler_task_id_t _task_id_measure;
47  void (*_event_handler)(bc_sht20_t *, bc_sht20_event_t, void *);
48  void *_event_param;
49  bool _measurement_active;
50  bc_tick_t _update_interval;
51  bc_sht20_state_t _state;
52  bc_tick_t _tick_ready;
53  bool _humidity_valid;
54  bool _temperature_valid;
55  uint16_t _reg_humidity;
56  uint16_t _reg_temperature;
57 };
58 
60 
65 
66 void bc_sht20_init(bc_sht20_t *self, bc_i2c_channel_t i2c_channel, uint8_t i2c_address);
67 
72 
73 void bc_sht20_set_event_handler(bc_sht20_t *self, void (*event_handler)(bc_sht20_t *, bc_sht20_event_t, void *), void *event_param);
74 
78 
80 
85 
86 bool bc_sht20_measure(bc_sht20_t *self);
87 
93 
94 bool bc_sht20_get_humidity_raw(bc_sht20_t *self, uint16_t *raw);
95 
101 
102 bool bc_sht20_get_humidity_percentage(bc_sht20_t *self, float *percentage);
103 
109 
110 bool bc_sht20_get_temperature_raw(bc_sht20_t *self, uint16_t *raw);
111 
117 
118 bool bc_sht20_get_temperature_celsius(bc_sht20_t *self, float *celsius);
119 
121 
122 #endif // _BC_SHT20_H
uint64_t bc_tick_t
Timestamp data type.
Definition: bc_tick.h:16
Error event.
Definition: bc_sht20.h:16
Update event.
Definition: bc_sht20.h:19
bool bc_sht20_measure(bc_sht20_t *self)
Start measurement manually.
Definition: bc_sht20.c:51
bc_sht20_event_t
Callback events.
Definition: bc_sht20.h:13
size_t bc_scheduler_task_id_t
Task ID assigned by scheduler.
Definition: bc_scheduler.h:18
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_sht20_get_humidity_percentage(bc_sht20_t *self, float *percentage)
Get measured humidity as percentage.
Definition: bc_sht20.c:77
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
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_sht20_get_temperature_raw(bc_sht20_t *self, uint16_t *raw)
Get measured temperature as raw value.
Definition: bc_sht20.c:100
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_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