Firmware SDK
twr_sht30.h
1 #ifndef _TWR_SHT30_H
2 #define _TWR_SHT30_H
3 
4 #include <twr_i2c.h>
5 #include <twr_scheduler.h>
6 
10 
11 #define TWR_SHT30_ADDRESS_DEFAULT 0x44
12 #define TWR_SHT30_ADDRESS_ALTERNATE 0x45
13 
15 
16 typedef enum
17 {
20 
23 
25 
27 
28 typedef struct twr_sht30_t twr_sht30_t;
29 
31 
32 typedef enum
33 {
34  TWR_SHT30_STATE_ERROR = -1,
35  TWR_SHT30_STATE_INITIALIZE = 0,
36  TWR_SHT30_STATE_MEASURE = 1,
37  TWR_SHT30_STATE_READ = 2,
38  TWR_SHT30_STATE_UPDATE = 3
39 
40 } twr_sht30_state_t;
41 
42 struct twr_sht30_t
43 {
44  twr_i2c_channel_t _i2c_channel;
45  uint8_t _i2c_address;
46  twr_scheduler_task_id_t _task_id_interval;
47  twr_scheduler_task_id_t _task_id_measure;
48  void (*_event_handler)(twr_sht30_t *, twr_sht30_event_t, void *);
49  void *_event_param;
50  bool _measurement_active;
51  twr_tick_t _update_interval;
52  twr_sht30_state_t _state;
53  twr_tick_t _tick_ready;
54  bool _humidity_valid;
55  bool _temperature_valid;
56  uint16_t _reg_humidity;
57  uint16_t _reg_temperature;
58 };
59 
61 
66 
67 void twr_sht30_init(twr_sht30_t *self, twr_i2c_channel_t i2c_channel, uint8_t i2c_address);
68 
71 
72 void twr_sht30_deinit(twr_sht30_t *self);
73 
78 
79 void twr_sht30_set_event_handler(twr_sht30_t *self, void (*event_handler)(twr_sht30_t *, twr_sht30_event_t, void *), void *event_param);
80 
84 
86 
91 
92 bool twr_sht30_measure(twr_sht30_t *self);
93 
99 
100 bool twr_sht30_get_humidity_raw(twr_sht30_t *self, uint16_t *raw);
101 
107 
108 bool twr_sht30_get_humidity_percentage(twr_sht30_t *self, float *percentage);
109 
115 
116 bool twr_sht30_get_temperature_raw(twr_sht30_t *self, uint16_t *raw);
117 
123 
124 bool twr_sht30_get_temperature_celsius(twr_sht30_t *self, float *celsius);
125 
131 
132 bool twr_sht30_get_temperature_fahrenheit(twr_sht30_t *self, float *fahrenheit);
133 
139 
140 bool twr_sht30_get_temperature_kelvin(twr_sht30_t *self, float *kelvin);
141 
143 
144 #endif // _TWR_SHT30_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
void twr_sht30_set_update_interval(twr_sht30_t *self, twr_tick_t interval)
Set measurement interval.
Definition: twr_sht30.c:43
bool twr_sht30_get_temperature_celsius(twr_sht30_t *self, float *celsius)
Get measured temperature in degrees of Celsius.
Definition: twr_sht30.c:120
bool twr_sht30_measure(twr_sht30_t *self)
Start measurement manually.
Definition: twr_sht30.c:59
struct twr_sht30_t twr_sht30_t
SHT30 instance.
Definition: twr_sht30.h:28
void twr_sht30_deinit(twr_sht30_t *self)
Deinitialize SHT30.
Definition: twr_sht30.c:30
bool twr_sht30_get_temperature_kelvin(twr_sht30_t *self, float *kelvin)
Get measured temperature in kelvin.
Definition: twr_sht30.c:148
bool twr_sht30_get_temperature_fahrenheit(twr_sht30_t *self, float *fahrenheit)
Get measured temperature in degrees of Fahrenheit.
Definition: twr_sht30.c:134
twr_sht30_event_t
Callback events.
Definition: twr_sht30.h:17
void twr_sht30_set_event_handler(twr_sht30_t *self, void(*event_handler)(twr_sht30_t *, twr_sht30_event_t, void *), void *event_param)
Set callback function.
Definition: twr_sht30.c:37
bool twr_sht30_get_humidity_percentage(twr_sht30_t *self, float *percentage)
Get measured humidity as percentage.
Definition: twr_sht30.c:85
void twr_sht30_init(twr_sht30_t *self, twr_i2c_channel_t i2c_channel, uint8_t i2c_address)
Initialize SHT30.
Definition: twr_sht30.c:15
bool twr_sht30_get_temperature_raw(twr_sht30_t *self, uint16_t *raw)
Get measured temperature as raw value.
Definition: twr_sht30.c:108
bool twr_sht30_get_humidity_raw(twr_sht30_t *self, uint16_t *raw)
Get measured humidity as raw value.
Definition: twr_sht30.c:73
@ TWR_SHT30_EVENT_ERROR
Error event.
Definition: twr_sht30.h:19
@ TWR_SHT30_EVENT_UPDATE
Update event.
Definition: twr_sht30.h:22
uint64_t twr_tick_t
Timestamp data type.
Definition: twr_tick.h:16