Firmware SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
bc_analog_sensor.h
1 #ifndef _BC_ANALOG_SENSOR_H
2 #define _BC_ANALOG_SENSOR_H
3 
4 #include <bc_adc.h>
5 #include <bc_scheduler.h>
6 
10 
12 
13 typedef enum
14 {
17 
20 
22 
24 
26 
28 
29 typedef struct
30 {
32  void (*init)(bc_analog_sensor_t *self);
33 
35  void (*enable)(bc_analog_sensor_t *self);
36 
38  void (*disable)(bc_analog_sensor_t *self);
39 
41  bc_tick_t (*get_settling_interval)(bc_analog_sensor_t *self);
42 
44 
46 
47 typedef enum
48 {
49  BC_ANALOG_SENSOR_STATE_ERROR = -1,
50  BC_ANALOG_SENSOR_STATE_ENABLE = 0,
51  BC_ANALOG_SENSOR_STATE_MEASURE = 1,
52  BC_ANALOG_SENSOR_STATE_DISABLE = 2,
53  BC_ANALOG_SENSOR_STATE_UPDATE = 3
54 
55 } bc_analog_sensor_state_t;
56 
57 struct bc_analog_sensor_t
58 {
59  bc_adc_channel_t _adc_channel;
60  const bc_analog_sensor_driver_t *_driver;
61  bc_scheduler_task_id_t _task_id_interval;
62  bc_scheduler_task_id_t _task_id_measure;
63  void (*_event_handler)(bc_analog_sensor_t *, bc_analog_sensor_event_t, void *);
64  void *_event_param;
65  bool _measurement_active;
66  bc_tick_t _update_interval;
67  bc_analog_sensor_state_t _state;
68  uint16_t _value;
69 };
70 
72 
78 
80 
85 
86 void bc_analog_sensor_set_event_handler(bc_analog_sensor_t *self, void (*event_handler)(bc_analog_sensor_t *, bc_analog_sensor_event_t, void *), void *event_param);
87 
91 
93 
98 
100 
106 
107 bool bc_analog_sensor_get_result(bc_analog_sensor_t *self, void *result);
108 
110 
111 #endif // _BC_ANALOG_SENSOR_H
Analog sensor driver interface.
uint64_t bc_tick_t
Timestamp data type.
Definition: bc_tick.h:16
void bc_analog_sensor_set_event_handler(bc_analog_sensor_t *self, void(*event_handler)(bc_analog_sensor_t *, bc_analog_sensor_event_t, void *), void *event_param)
Set callback function.
void bc_analog_sensor_set_update_interval(bc_analog_sensor_t *self, bc_tick_t interval)
Set measurement interval.
bool bc_analog_sensor_get_result(bc_analog_sensor_t *self, void *result)
Get measurement result.
size_t bc_scheduler_task_id_t
Task ID assigned by scheduler.
Definition: bc_scheduler.h:18
struct bc_analog_sensor_t bc_analog_sensor_t
Analog sensor instance.
bc_analog_sensor_event_t
Callback events.
bool bc_analog_sensor_measure(bc_analog_sensor_t *self)
Start measurement manually.
void bc_analog_sensor_init(bc_analog_sensor_t *self, bc_adc_channel_t adc_channel, const bc_analog_sensor_driver_t *driver)
Initialize generic analog sensor.
bc_adc_channel_t
ADC channel.
Definition: bc_adc.h:13