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 
70 void bc_sht20_deinit(bc_sht20_t *self);
71 
76 
77 void bc_sht20_set_event_handler(bc_sht20_t *self, void (*event_handler)(bc_sht20_t *, bc_sht20_event_t, void *), void *event_param);
78 
82 
84 
89 
90 bool bc_sht20_measure(bc_sht20_t *self);
91 
97 
98 bool bc_sht20_get_humidity_raw(bc_sht20_t *self, uint16_t *raw);
99 
105 
106 bool bc_sht20_get_humidity_percentage(bc_sht20_t *self, float *percentage);
107 
113 
114 bool bc_sht20_get_temperature_raw(bc_sht20_t *self, uint16_t *raw);
115 
121 
122 bool bc_sht20_get_temperature_celsius(bc_sht20_t *self, float *celsius);
123 
129 
130 bool bc_sht20_get_temperature_fahrenheit(bc_sht20_t *self, float *fahrenheit);
131 
137 
138 bool bc_sht20_get_temperature_kelvin(bc_sht20_t *self, float *kelvin);
139 
141 
142 #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:60
bool bc_sht20_get_temperature_fahrenheit(bc_sht20_t *self, float *fahrenheit)
Get measured temperature in degrees of Fahrenheit.
Definition: bc_sht20.c:135
bool bc_sht20_get_temperature_kelvin(bc_sht20_t *self, float *kelvin)
Get measured temperature in kelvin.
Definition: bc_sht20.c:149
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:16
bool bc_sht20_get_humidity_percentage(bc_sht20_t *self, float *percentage)
Get measured humidity as percentage.
Definition: bc_sht20.c:86
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:74
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:44
bool bc_sht20_get_temperature_raw(bc_sht20_t *self, uint16_t *raw)
Get measured temperature as raw value.
Definition: bc_sht20.c:109
bool bc_sht20_get_temperature_celsius(bc_sht20_t *self, float *celsius)
Get measured temperature in degrees of Celsius.
Definition: bc_sht20.c:121
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:38
void bc_sht20_deinit(bc_sht20_t *self)
Deinitialize SHT20.
Definition: bc_sht20.c:31