Firmware SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
bc_lp8.h
1 #ifndef _BC_LP8_H
2 #define _BC_LP8_H
3 
4 #include <bc_scheduler.h>
5 #include <bc_tick.h>
6 
10 
12 
13 typedef enum
14 {
17 
20 
22 
24 
25 typedef enum
26 {
29 
32 
35 
38 
41 
44 
46 
48 
49 typedef struct bc_lp8_t bc_lp8_t;
50 
52 
53 typedef struct
54 {
56  bool (*init)(void);
57 
59  bool (*charge_enable)(bool state);
60 
62  bool (*device_enable)(bool state);
63 
65  bool (*read_signal_rdy)(int *value);
66 
68  bool (*uart_enable)(bool state);
69 
71  size_t (*uart_write)(uint8_t *buffer, size_t length);
72 
74  size_t (*uart_read)(uint8_t *buffer, size_t length);
75 
77 
79 
80 typedef enum
81 {
82  BC_LP8_STATE_ERROR = -1,
83  BC_LP8_STATE_INITIALIZE = 0,
84  BC_LP8_STATE_READY = 1,
85  BC_LP8_STATE_PRECHARGE = 2,
86  BC_LP8_STATE_CHARGE = 3,
87  BC_LP8_STATE_BOOT = 4,
88  BC_LP8_STATE_BOOT_READ = 5,
89  BC_LP8_STATE_MEASURE = 6,
90  BC_LP8_STATE_MEASURE_READ = 7
91 
92 } bc_lp8_state_t;
93 
94 typedef enum
95 {
96  BC_LP8_ERROR_INITIALIZE = 0,
97  BC_LP8_ERROR_PRECHARGE = 1,
98 
99  BC_LP8_ERROR_CHARGE_CHARGE_ENABLE = 2,
100  BC_LP8_ERROR_CHARGE_DEVICE_ENABLE = 3,
101 
102  BC_LP8_ERROR_BOOT_SIGNAL_READY = 4,
103  BC_LP8_ERROR_BOOT_TIMEOUT = 5,
104  BC_LP8_ERROR_BOOT_UART_ENABLE = 6,
105  BC_LP8_ERROR_BOOT_UART_WRITE = 7,
106 
107  BC_LP8_ERROR_BOOT_READ_UART_ENABLE = 8,
108  BC_LP8_ERROR_BOOT_READ_DEVICE_ADDRESS = 9,
109  BC_LP8_ERROR_BOOT_READ_COMMAND = 10,
110  BC_LP8_ERROR_BOOT_READ_CRC = 11,
111  BC_LP8_ERROR_BOOT_READ_TIMEOUT = 12,
112 
113  BC_LP8_ERROR_MEASURE_SIGNAL_RDY = 13,
114  BC_LP8_ERROR_MEASURE_SIGNAL_RDY_TIMEOUT = 14,
115  BC_LP8_ERROR_MEASURE_UART_ENABLE = 15,
116  BC_LP8_ERROR_MEASURE_UART_WRITE = 16,
117 
118  BC_LP8_ERROR_MEASURE_READ_UART_ENABLE = 17,
119  BC_LP8_ERROR_MEASURE_READ_DEVICE_ENABLE = 18,
120  BC_LP8_ERROR_MEASURE_READ_DEVICE_ADDRESS = 19,
121  BC_LP8_ERROR_MEASURE_READ_COMMAND = 20,
122  BC_LP8_ERROR_MEASURE_READ_CRC = 21,
123  BC_LP8_ERROR_MEASURE_READ_CALIBRATION_RUN = 22,
124  BC_LP8_ERROR_MEASURE_READ_STATUS1 = 23,
125  BC_LP8_ERROR_MEASURE_READ_TIMEOUT = 24
126 
127 } bc_lp8_error_t;
128 
129 struct bc_lp8_t
130 {
131  const bc_lp8_driver_t *_driver;
132  bc_scheduler_task_id_t _task_id_interval;
133  bc_scheduler_task_id_t _task_id_measure;
134  void (*_event_handler)(bc_lp8_event_t, void *);
135  void *_event_param;
136  bc_tick_t _update_interval;
137  bc_lp8_state_t _state;
138  bool _first_measurement_done;
139  bc_tick_t _tick_timeout;
140  bc_tick_t _tick_calibration;
141  bc_lp8_calibration_t _calibration;
142  bool _calibration_run;
143  uint8_t _rx_buffer[49];
144  size_t _rx_buffer_length;
145  uint8_t _tx_buffer[33];
146  uint8_t _sensor_state[23];
147  bool _valid;
148  int16_t _concentration;
149  uint16_t _pressure;
150  bc_lp8_error_t _error;
151 
152 };
153 
155 
157 
158 void bc_lp8_init(bc_lp8_t *self, const bc_lp8_driver_t *driver);
159 
164 
165 void bc_lp8_set_event_handler(bc_lp8_t *self, void (*event_handler)(bc_lp8_event_t, void *), void *event_param);
166 
170 
171 void bc_lp8_set_update_interval(bc_lp8_t *self, bc_tick_t interval);
172 
177 
178 bool bc_lp8_measure(bc_lp8_t *self);
179 
185 
186 bool bc_lp8_get_concentration_ppm(bc_lp8_t *self, float *ppm);
187 
193 
194 bool bc_lp8_get_error(bc_lp8_t *self, bc_lp8_error_t *error);
195 
199 
200 void bc_lp8_calibration(bc_lp8_t *self, bc_lp8_calibration_t calibration);
201 
203 
204 #endif // _BC_LP8_H
uint64_t bc_tick_t
Timestamp data type.
Definition: bc_tick.h:16
bool bc_lp8_get_error(bc_lp8_t *self, bc_lp8_error_t *error)
Get last error code.
Definition: bc_lp8.c:90
bc_lp8_event_t
Callback events.
Definition: bc_lp8.h:13
Error event.
Definition: bc_lp8.h:16
bool bc_lp8_get_concentration_ppm(bc_lp8_t *self, float *ppm)
Get CO2 concentration in ppm (parts per million)
Definition: bc_lp8.c:76
bc_lp8_calibration_t
Calibration.
Definition: bc_lp8.h:25
ABC (based on filtered data) + reset filters.
Definition: bc_lp8.h:43
void bc_lp8_set_event_handler(bc_lp8_t *self, void(*event_handler)(bc_lp8_event_t, void *), void *event_param)
Set callback function.
Definition: bc_lp8.c:36
Background calibration using filtered data.
Definition: bc_lp8.h:31
void bc_lp8_set_update_interval(bc_lp8_t *self, bc_tick_t interval)
Set measurement interval.
Definition: bc_lp8.c:42
void bc_lp8_init(bc_lp8_t *self, const bc_lp8_driver_t *driver)
Initialize LP8.
Definition: bc_lp8.c:20
ABC (based on filtered data)
Definition: bc_lp8.h:40
size_t bc_scheduler_task_id_t
Task ID assigned by scheduler.
Definition: bc_scheduler.h:18
bool bc_lp8_measure(bc_lp8_t *self)
Start measurement manually.
Definition: bc_lp8.c:58
Background calibration using filtered data + reset filters.
Definition: bc_lp8.h:37
Update event.
Definition: bc_lp8.h:19
LP8 driver.
Definition: bc_lp8.h:53
void bc_lp8_calibration(bc_lp8_t *self, bc_lp8_calibration_t calibration)
Request sensor calibration.
Definition: bc_lp8.c:97
struct bc_lp8_t bc_lp8_t
LP8 instance.
Definition: bc_lp8.h:49
Background calibration using unfiltered data.
Definition: bc_lp8.h:28
Background calibration using unfiltered data + reset filters.
Definition: bc_lp8.h:34