Firmware SDK
twr_tmp112.h
1 #ifndef _TWR_TMP112_H
2 #define _TWR_TMP112_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_tmp112_t twr_tmp112_t;
26 
28 
29 typedef enum
30 {
31  TWR_TMP112_STATE_ERROR = -1,
32  TWR_TMP112_STATE_INITIALIZE = 0,
33  TWR_TMP112_STATE_MEASURE = 1,
34  TWR_TMP112_STATE_READ = 2,
35  TWR_TMP112_STATE_UPDATE = 3
36 
37 } twr_tmp112_state_t;
38 
39 struct twr_tmp112_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_tmp112_t *, twr_tmp112_event_t, void *);
46  void *_event_param;
47  bool _measurement_active;
48  twr_tick_t _update_interval;
49  twr_tmp112_state_t _state;
50  twr_tick_t _tick_ready;
51  bool _temperature_valid;
52  uint16_t _reg_temperature;
53 };
54 
56 
61 
62 void twr_tmp112_init(twr_tmp112_t *self, twr_i2c_channel_t i2c_channel, uint8_t i2c_address);
63 
64 
67 
69 
74 
75 void twr_tmp112_set_event_handler(twr_tmp112_t *self, void (*event_handler)(twr_tmp112_t *, twr_tmp112_event_t, void *), void *event_param);
76 
80 
82 
87 
89 
95 
96 bool twr_tmp112_get_temperature_raw(twr_tmp112_t *self, int16_t *raw);
97 
103 
104 bool twr_tmp112_get_temperature_celsius(twr_tmp112_t *self, float *celsius);
105 
111 
112 bool twr_tmp112_get_temperature_fahrenheit(twr_tmp112_t *self, float *fahrenheit);
113 
119 
120 bool twr_tmp112_get_temperature_kelvin(twr_tmp112_t *self, float *kelvin);
121 
123 
124 #endif // _TWR_TMP112_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
uint64_t twr_tick_t
Timestamp data type.
Definition: twr_tick.h:16
bool twr_tmp112_get_temperature_kelvin(twr_tmp112_t *self, float *kelvin)
Get measured temperature in kelvin.
Definition: twr_tmp112.c:111
twr_tmp112_event_t
Callback events.
Definition: twr_tmp112.h:14
void twr_tmp112_set_update_interval(twr_tmp112_t *self, twr_tick_t interval)
Set measurement interval.
Definition: twr_tmp112.c:41
bool twr_tmp112_get_temperature_raw(twr_tmp112_t *self, int16_t *raw)
Get measured temperature as raw value.
Definition: twr_tmp112.c:71
void twr_tmp112_set_event_handler(twr_tmp112_t *self, void(*event_handler)(twr_tmp112_t *, twr_tmp112_event_t, void *), void *event_param)
Set callback function.
Definition: twr_tmp112.c:35
bool twr_tmp112_measure(twr_tmp112_t *self)
Start measurement manually.
Definition: twr_tmp112.c:57
struct twr_tmp112_t twr_tmp112_t
TMP112 instance.
Definition: twr_tmp112.h:25
void twr_tmp112_deinit(twr_tmp112_t *self)
Deinitialize TMP112.
Definition: twr_tmp112.c:26
bool twr_tmp112_get_temperature_celsius(twr_tmp112_t *self, float *celsius)
Get measured temperature in degrees of Celsius.
Definition: twr_tmp112.c:83
bool twr_tmp112_get_temperature_fahrenheit(twr_tmp112_t *self, float *fahrenheit)
Get measured temperature in degrees of Fahrenheit.
Definition: twr_tmp112.c:97
void twr_tmp112_init(twr_tmp112_t *self, twr_i2c_channel_t i2c_channel, uint8_t i2c_address)
Initialize TMP112.
Definition: twr_tmp112.c:11
@ TWR_TMP112_EVENT_ERROR
Error event.
Definition: twr_tmp112.h:16
@ TWR_TMP112_EVENT_UPDATE
Update event.
Definition: twr_tmp112.h:19