Firmware SDK
twr_hts221.h
1 #ifndef _TWR_HTS221_H
2 #define _TWR_HTS221_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_hts221_t twr_hts221_t;
26 
28 
29 typedef enum
30 {
31  TWR_HTS221_STATE_ERROR = -1,
32  TWR_HTS221_STATE_INITIALIZE = 0,
33  TWR_HTS221_STATE_MEASURE = 1,
34  TWR_HTS221_STATE_READ = 2,
35  TWR_HTS221_STATE_UPDATE = 3
36 
37 } twr_hts221_state_t;
38 
39 struct twr_hts221_t
40 {
41  twr_i2c_channel_t _i2c_channel;
42  uint8_t _i2c_address;
43  twr_scheduler_task_id_t _task_id_interval;
44  twr_scheduler_task_id_t _task_id_measure;
45  void (*_event_handler)(twr_hts221_t *, twr_hts221_event_t, void *);
46  void *_event_param;
47  bool _measurement_active;
48  twr_tick_t _update_interval;
49  twr_hts221_state_t _state;
50  twr_tick_t _tick_ready;
51  bool _humidity_valid;
52  int16_t _reg_humidity;
53  int16_t _h0_rh;
54  int16_t _h0_t0_out;
55  float _h_grad;
56 };
57 
59 
64 
65 void twr_hts221_init(twr_hts221_t *self, twr_i2c_channel_t i2c_channel, uint8_t i2c_address);
66 
69 
71 
76 
77 void twr_hts221_set_event_handler(twr_hts221_t *self, void (*event_handler)(twr_hts221_t *, twr_hts221_event_t, void *), void *event_param);
78 
82 
84 
89 
91 
97 
98 bool twr_hts221_get_humidity_percentage(twr_hts221_t *self, float *percentage);
99 
101 
102 #endif // _TWR_HTS221_H
void twr_hts221_deinit(twr_hts221_t *self)
Deinitialize HTS221.
Definition: twr_hts221.c:71
void twr_hts221_set_update_interval(twr_hts221_t *self, twr_tick_t interval)
Set measurement interval.
Definition: twr_hts221.c:90
bool twr_hts221_measure(twr_hts221_t *self)
Start measurement manually.
Definition: twr_hts221.c:106
struct twr_hts221_t twr_hts221_t
HTS221 instance.
Definition: twr_hts221.h:25
bool twr_hts221_get_humidity_percentage(twr_hts221_t *self, float *percentage)
Get measured humidity as percentage.
Definition: twr_hts221.c:120
void twr_hts221_set_event_handler(twr_hts221_t *self, void(*event_handler)(twr_hts221_t *, twr_hts221_event_t, void *), void *event_param)
Set callback function.
Definition: twr_hts221.c:84
void twr_hts221_init(twr_hts221_t *self, twr_i2c_channel_t i2c_channel, uint8_t i2c_address)
Initialize HTS221.
Definition: twr_hts221.c:53
twr_hts221_event_t
Callback events.
Definition: twr_hts221.h:14
@ TWR_HTS221_EVENT_ERROR
Error event.
Definition: twr_hts221.h:16
@ TWR_HTS221_EVENT_UPDATE
Update event.
Definition: twr_hts221.h:19
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
uint64_t twr_tick_t
Timestamp data type.
Definition: twr_tick.h:16