Firmware SDK
twr_analog_sensor.h
1 #ifndef _TWR_ANALOG_SENSOR_H
2 #define _TWR_ANALOG_SENSOR_H
3 
4 #include <twr_adc.h>
5 #include <twr_scheduler.h>
6 
10 
12 
13 typedef enum
14 {
17 
20 
22 
24 
26 
28 
29 typedef struct
30 {
32  void (*init)(twr_analog_sensor_t *self);
33 
35  void (*enable)(twr_analog_sensor_t *self);
36 
38  void (*disable)(twr_analog_sensor_t *self);
39 
41  twr_tick_t (*get_settling_interval)(twr_analog_sensor_t *self);
42 
44 
46 
47 typedef enum
48 {
49  TWR_ANALOG_SENSOR_STATE_ERROR = -1,
50  TWR_ANALOG_SENSOR_STATE_ENABLE = 0,
51  TWR_ANALOG_SENSOR_STATE_MEASURE = 1,
52  TWR_ANALOG_SENSOR_STATE_DISABLE = 2,
53  TWR_ANALOG_SENSOR_STATE_UPDATE = 3
54 
55 } twr_analog_sensor_state_t;
56 
58 {
59  twr_adc_channel_t _adc_channel;
60  const twr_analog_sensor_driver_t *_driver;
61  twr_scheduler_task_id_t _task_id_interval;
62  twr_scheduler_task_id_t _task_id_measure;
63  void (*_event_handler)(twr_analog_sensor_t *, twr_analog_sensor_event_t, void *);
64  void *_event_param;
65  bool _measurement_active;
66  twr_tick_t _update_interval;
67  twr_analog_sensor_state_t _state;
68  uint16_t _value;
69 };
70 
72 
78 
80 
85 
86 void twr_analog_sensor_set_event_handler(twr_analog_sensor_t *self, void (*event_handler)(twr_analog_sensor_t *, twr_analog_sensor_event_t, void *), void *event_param);
87 
91 
93 
98 
100 
106 
107 bool twr_analog_sensor_get_result(twr_analog_sensor_t *self, void *result);
108 
110 
111 #endif // _TWR_ANALOG_SENSOR_H
bool twr_analog_sensor_measure(twr_analog_sensor_t *self)
Start measurement manually.
struct twr_analog_sensor_t twr_analog_sensor_t
Analog sensor instance.
void twr_analog_sensor_set_update_interval(twr_analog_sensor_t *self, twr_tick_t interval)
Set measurement interval.
void twr_analog_sensor_init(twr_analog_sensor_t *self, twr_adc_channel_t adc_channel, const twr_analog_sensor_driver_t *driver)
Initialize generic analog sensor.
twr_analog_sensor_event_t
Callback events.
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
Analog sensor driver interface.
void twr_analog_sensor_set_event_handler(twr_analog_sensor_t *self, void(*event_handler)(twr_analog_sensor_t *, twr_analog_sensor_event_t, void *), void *event_param)
Set callback function.
twr_adc_channel_t
ADC channel.
Definition: twr_adc.h:13
bool twr_analog_sensor_get_result(twr_analog_sensor_t *self, void *result)
Get measurement result.