Firmware SDK
twr_hdc2080.h
1 #ifndef _TWR_HDC2080_H
2 #define _TWR_HDC2080_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_hdc2080_t twr_hdc2080_t;
26 
28 
29 typedef enum
30 {
31  TWR_HDC2080_STATE_ERROR = -1,
32  TWR_HDC2080_STATE_INITIALIZE = 0,
33  TWR_HDC2080_STATE_MEASURE = 1,
34  TWR_HDC2080_STATE_READ = 2,
35  TWR_HDC2080_STATE_UPDATE = 3
36 
37 } twr_hdc2080_state_t;
38 
39 struct twr_hdc2080_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_hdc2080_t *, twr_hdc2080_event_t, void *);
46  void *_event_param;
47  bool _measurement_active;
48  twr_tick_t _update_interval;
49  twr_hdc2080_state_t _state;
50  twr_tick_t _tick_ready;
51  bool _humidity_valid;
52  bool _temperature_valid;
53  uint16_t _reg_humidity;
54  uint16_t _reg_temperature;
55 };
56 
58 
63 
64 void twr_hdc2080_init(twr_hdc2080_t *self, twr_i2c_channel_t i2c_channel, uint8_t i2c_address);
65 
68 
70 
75 
76 void twr_hdc2080_set_event_handler(twr_hdc2080_t *self, void (*event_handler)(twr_hdc2080_t *, twr_hdc2080_event_t, void *), void *event_param);
77 
81 
83 
88 
90 
96 
97 bool twr_hdc2080_get_humidity_raw(twr_hdc2080_t *self, uint16_t *raw);
98 
104 
105 bool twr_hdc2080_get_humidity_percentage(twr_hdc2080_t *self, float *percentage);
106 
112 
113 bool twr_hdc2080_get_temperature_raw(twr_hdc2080_t *self, uint16_t *raw);
114 
120 
121 bool twr_hdc2080_get_temperature_celsius(twr_hdc2080_t *self, float *celsius);
122 
124 
125 #endif // _TWR_HDC2080_H
twr_hdc2080_event_t
Callback events.
Definition: twr_hdc2080.h:14
struct twr_hdc2080_t twr_hdc2080_t
HDC2080 instance.
Definition: twr_hdc2080.h:25
void twr_hdc2080_init(twr_hdc2080_t *self, twr_i2c_channel_t i2c_channel, uint8_t i2c_address)
Initialize HDC2080.
Definition: twr_hdc2080.c:12
bool twr_hdc2080_get_temperature_celsius(twr_hdc2080_t *self, float *celsius)
Get measured temperature in degrees of Celsius.
Definition: twr_hdc2080.c:115
bool twr_hdc2080_get_temperature_raw(twr_hdc2080_t *self, uint16_t *raw)
Get measured temperature as raw value.
Definition: twr_hdc2080.c:103
void twr_hdc2080_deinit(twr_hdc2080_t *self)
Deinitialize HDC2080.
Definition: twr_hdc2080.c:27
bool twr_hdc2080_measure(twr_hdc2080_t *self)
Start measurement manually.
Definition: twr_hdc2080.c:58
bool twr_hdc2080_get_humidity_percentage(twr_hdc2080_t *self, float *percentage)
Get measured humidity as percentage.
Definition: twr_hdc2080.c:84
bool twr_hdc2080_get_humidity_raw(twr_hdc2080_t *self, uint16_t *raw)
Get measured humidity as raw value.
Definition: twr_hdc2080.c:72
void twr_hdc2080_set_update_interval(twr_hdc2080_t *self, twr_tick_t interval)
Set measurement interval.
Definition: twr_hdc2080.c:42
void twr_hdc2080_set_event_handler(twr_hdc2080_t *self, void(*event_handler)(twr_hdc2080_t *, twr_hdc2080_event_t, void *), void *event_param)
Set callback function.
Definition: twr_hdc2080.c:36
@ TWR_HDC2080_EVENT_UPDATE
Update event.
Definition: twr_hdc2080.h:19
@ TWR_HDC2080_EVENT_ERROR
Error event.
Definition: twr_hdc2080.h:16
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