Firmware SDK
twr_sht20.h
1 #ifndef _TWR_SHT20_H
2 #define _TWR_SHT20_H
3 
4 #include <twr_i2c.h>
5 #include <twr_scheduler.h>
6 
10 
12 
13 typedef enum
14 {
17 
20 
22 
24 
25 typedef struct twr_sht20_t twr_sht20_t;
26 
28 
29 typedef enum
30 {
31  TWR_SHT20_STATE_ERROR = -1,
32  TWR_SHT20_STATE_INITIALIZE = 0,
33  TWR_SHT20_STATE_MEASURE_RH = 1,
34  TWR_SHT20_STATE_READ_RH = 2,
35  TWR_SHT20_STATE_MEASURE_T = 3,
36  TWR_SHT20_STATE_READ_T = 4,
37  TWR_SHT20_STATE_UPDATE = 5
38 
39 } twr_sht20_state_t;
40 
41 struct twr_sht20_t
42 {
43  twr_i2c_channel_t _i2c_channel;
44  uint8_t _i2c_address;
45  twr_scheduler_task_id_t _task_id_interval;
46  twr_scheduler_task_id_t _task_id_measure;
47  void (*_event_handler)(twr_sht20_t *, twr_sht20_event_t, void *);
48  void *_event_param;
49  bool _measurement_active;
50  twr_tick_t _update_interval;
51  twr_sht20_state_t _state;
52  twr_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 twr_sht20_init(twr_sht20_t *self, twr_i2c_channel_t i2c_channel, uint8_t i2c_address);
67 
70 void twr_sht20_deinit(twr_sht20_t *self);
71 
76 
77 void twr_sht20_set_event_handler(twr_sht20_t *self, void (*event_handler)(twr_sht20_t *, twr_sht20_event_t, void *), void *event_param);
78 
82 
84 
89 
90 bool twr_sht20_measure(twr_sht20_t *self);
91 
97 
98 bool twr_sht20_get_humidity_raw(twr_sht20_t *self, uint16_t *raw);
99 
105 
106 bool twr_sht20_get_humidity_percentage(twr_sht20_t *self, float *percentage);
107 
113 
114 bool twr_sht20_get_temperature_raw(twr_sht20_t *self, uint16_t *raw);
115 
121 
122 bool twr_sht20_get_temperature_celsius(twr_sht20_t *self, float *celsius);
123 
129 
130 bool twr_sht20_get_temperature_fahrenheit(twr_sht20_t *self, float *fahrenheit);
131 
137 
138 bool twr_sht20_get_temperature_kelvin(twr_sht20_t *self, float *kelvin);
139 
141 
142 #endif // _TWR_SHT20_H
twr_i2c_channel_t
I2C channels.
Definition: twr_i2c.h:16
size_t twr_scheduler_task_id_t
Task ID assigned by scheduler.
Definition: twr_scheduler.h:22
bool twr_sht20_get_temperature_celsius(twr_sht20_t *self, float *celsius)
Get measured temperature in degrees of Celsius.
Definition: twr_sht20.c:121
struct twr_sht20_t twr_sht20_t
SHT20 instance.
Definition: twr_sht20.h:25
void twr_sht20_init(twr_sht20_t *self, twr_i2c_channel_t i2c_channel, uint8_t i2c_address)
Initialize SHT20.
Definition: twr_sht20.c:16
bool twr_sht20_measure(twr_sht20_t *self)
Start measurement manually.
Definition: twr_sht20.c:60
void twr_sht20_set_update_interval(twr_sht20_t *self, twr_tick_t interval)
Set measurement interval.
Definition: twr_sht20.c:44
bool twr_sht20_get_temperature_raw(twr_sht20_t *self, uint16_t *raw)
Get measured temperature as raw value.
Definition: twr_sht20.c:109
bool twr_sht20_get_humidity_raw(twr_sht20_t *self, uint16_t *raw)
Get measured humidity as raw value.
Definition: twr_sht20.c:74
bool twr_sht20_get_temperature_kelvin(twr_sht20_t *self, float *kelvin)
Get measured temperature in kelvin.
Definition: twr_sht20.c:149
void twr_sht20_deinit(twr_sht20_t *self)
Deinitialize SHT20.
Definition: twr_sht20.c:31
bool twr_sht20_get_humidity_percentage(twr_sht20_t *self, float *percentage)
Get measured humidity as percentage.
Definition: twr_sht20.c:86
void twr_sht20_set_event_handler(twr_sht20_t *self, void(*event_handler)(twr_sht20_t *, twr_sht20_event_t, void *), void *event_param)
Set callback function.
Definition: twr_sht20.c:38
twr_sht20_event_t
Callback events.
Definition: twr_sht20.h:14
bool twr_sht20_get_temperature_fahrenheit(twr_sht20_t *self, float *fahrenheit)
Get measured temperature in degrees of Fahrenheit.
Definition: twr_sht20.c:135
@ TWR_SHT20_EVENT_UPDATE
Update event.
Definition: twr_sht20.h:19
@ TWR_SHT20_EVENT_ERROR
Error event.
Definition: twr_sht20.h:16
uint64_t twr_tick_t
Timestamp data type.
Definition: twr_tick.h:16