4 #include <twr_scheduler.h>
59 bool (*charge_enable)(
bool state);
62 bool (*device_enable)(
bool state);
65 bool (*read_signal_rdy)(
int *value);
68 bool (*uart_enable)(
bool state);
71 size_t (*uart_write)(uint8_t *buffer,
size_t length);
74 size_t (*uart_read)(uint8_t *buffer,
size_t length);
82 TWR_LP8_STATE_ERROR = -1,
83 TWR_LP8_STATE_INITIALIZE = 0,
84 TWR_LP8_STATE_READY = 1,
85 TWR_LP8_STATE_PRECHARGE = 2,
86 TWR_LP8_STATE_CHARGE = 3,
87 TWR_LP8_STATE_BOOT = 4,
88 TWR_LP8_STATE_BOOT_READ = 5,
89 TWR_LP8_STATE_MEASURE = 6,
90 TWR_LP8_STATE_MEASURE_READ = 7
96 TWR_LP8_ERROR_INITIALIZE = 0,
97 TWR_LP8_ERROR_PRECHARGE = 1,
99 TWR_LP8_ERROR_CHARGE_CHARGE_ENABLE = 2,
100 TWR_LP8_ERROR_CHARGE_DEVICE_ENABLE = 3,
102 TWR_LP8_ERROR_BOOT_SIGNAL_READY = 4,
103 TWR_LP8_ERROR_BOOT_TIMEOUT = 5,
104 TWR_LP8_ERROR_BOOT_UART_ENABLE = 6,
105 TWR_LP8_ERROR_BOOT_UART_WRITE = 7,
107 TWR_LP8_ERROR_BOOT_READ_UART_ENABLE = 8,
108 TWR_LP8_ERROR_BOOT_READ_DEVICE_ADDRESS = 9,
109 TWR_LP8_ERROR_BOOT_READ_COMMAND = 10,
110 TWR_LP8_ERROR_BOOT_READ_CRC = 11,
111 TWR_LP8_ERROR_BOOT_READ_TIMEOUT = 12,
113 TWR_LP8_ERROR_MEASURE_SIGNAL_RDY = 13,
114 TWR_LP8_ERROR_MEASURE_SIGNAL_RDY_TIMEOUT = 14,
115 TWR_LP8_ERROR_MEASURE_UART_ENABLE = 15,
116 TWR_LP8_ERROR_MEASURE_UART_WRITE = 16,
118 TWR_LP8_ERROR_MEASURE_READ_UART_ENABLE = 17,
119 TWR_LP8_ERROR_MEASURE_READ_DEVICE_ENABLE = 18,
120 TWR_LP8_ERROR_MEASURE_READ_DEVICE_ADDRESS = 19,
121 TWR_LP8_ERROR_MEASURE_READ_COMMAND = 20,
122 TWR_LP8_ERROR_MEASURE_READ_CRC = 21,
123 TWR_LP8_ERROR_MEASURE_READ_CALIBRATION_RUN = 22,
124 TWR_LP8_ERROR_MEASURE_READ_STATUS1 = 23,
125 TWR_LP8_ERROR_MEASURE_READ_TIMEOUT = 24
137 twr_lp8_state_t _state;
138 bool _first_measurement_done;
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];
148 int16_t _concentration;
150 twr_lp8_error_t _error;
void twr_lp8_set_event_handler(twr_lp8_t *self, void(*event_handler)(twr_lp8_event_t, void *), void *event_param)
Set callback function.
bool twr_lp8_measure(twr_lp8_t *self)
Start measurement manually.
void twr_lp8_calibration(twr_lp8_t *self, twr_lp8_calibration_t calibration)
Request sensor calibration.
void twr_lp8_set_update_interval(twr_lp8_t *self, twr_tick_t interval)
Set measurement interval.
void twr_lp8_init(twr_lp8_t *self, const twr_lp8_driver_t *driver)
Initialize LP8.
bool twr_lp8_get_concentration_ppm(twr_lp8_t *self, float *ppm)
Get CO2 concentration in ppm (parts per million)
twr_lp8_event_t
Callback events.
bool twr_lp8_get_error(twr_lp8_t *self, twr_lp8_error_t *error)
Get last error code.
twr_lp8_calibration_t
Calibration.
struct twr_lp8_t twr_lp8_t
LP8 instance.
@ TWR_LP8_EVENT_UPDATE
Update event.
@ TWR_LP8_EVENT_ERROR
Error event.
@ TWR_LP8_CALIBRATION_BACKGROUND_UNFILTERED
Background calibration using unfiltered data.
@ TWR_LP8_CALIBRATION_BACKGROUND_FILTERED
Background calibration using filtered data.
@ TWR_LP8_CALIBRATION_ABC
ABC (based on filtered data)
@ TWR_LP8_CALIBRATION_ATWR_RF
ABC (based on filtered data) + reset filters.
@ TWR_LP8_CALIBRATION_BACKGROUND_FILTERED_RF
Background calibration using filtered data + reset filters.
@ TWR_LP8_CALIBRATION_BACKGROUND_UNFILTERED_RF
Background calibration using unfiltered data + reset filters.
size_t twr_scheduler_task_id_t
Task ID assigned by scheduler.
uint64_t twr_tick_t
Timestamp data type.