2020-03-08 23:25:04 +01:00
|
|
|
#include<Wire.h>
|
|
|
|
#include<Arduino.h>
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
LP8_STATE_ERROR = -1,
|
|
|
|
LP8_STATE_INITIALIZE = 0,
|
|
|
|
LP8_STATE_READY = 1,
|
|
|
|
LP8_STATE_PRECHARGE = 2,
|
|
|
|
LP8_STATE_CHARGE = 3,
|
|
|
|
LP8_STATE_BOOT = 4,
|
|
|
|
LP8_STATE_BOOT_READ = 5,
|
|
|
|
LP8_STATE_MEASURE = 6,
|
|
|
|
LP8_STATE_MEASURE_READ = 7
|
|
|
|
|
|
|
|
} lp8_state_t;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
//Background calibration using unfiltered data
|
|
|
|
LP8_CALIBRATION_BACKGROUND_UNFILTERED = 0x50,
|
|
|
|
|
|
|
|
//Background calibration using filtered data
|
|
|
|
LP8_CALIBRATION_BACKGROUND_FILTERED = 0x51,
|
|
|
|
|
|
|
|
//Background calibration using unfiltered data + reset filters
|
|
|
|
LP8_CALIBRATION_BACKGROUND_UNFILTERED_RF = 0x52,
|
|
|
|
|
|
|
|
//Background calibration using filtered data + reset filters
|
|
|
|
LP8_CALIBRATION_BACKGROUND_FILTERED_RF = 0x53,
|
|
|
|
|
|
|
|
//ABC (based on filtered data)
|
|
|
|
LP8_CALIBRATION_ABC = 0x70,
|
|
|
|
|
|
|
|
//ABC (based on filtered data) + reset filters
|
|
|
|
LP8_CALIBRATION_ABC_RF = 0x72
|
|
|
|
|
|
|
|
} lp8_calibration_t;
|
|
|
|
|
|
|
|
struct lp8_t {
|
|
|
|
lp8_state_t state;
|
|
|
|
bool first_measurement_done;
|
|
|
|
lp8_calibration_t calibration;
|
|
|
|
bool calibration_run;
|
|
|
|
uint8_t rx_buffer[49];
|
|
|
|
uint8_t tx_buffer[33];
|
|
|
|
uint8_t sensor_state[23];
|
|
|
|
int16_t concentration;
|
|
|
|
bool valid;
|
|
|
|
uint16_t pressure;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool init_module();
|
2020-03-15 15:14:06 +01:00
|
|
|
bool reset_module();
|
2020-03-08 23:25:04 +01:00
|
|
|
uint8_t get_ready_state();
|
|
|
|
uint16_t calculate_crc16(uint8_t *buffer, uint8_t length);
|
|
|
|
bool tca_set_port(uint8_t port);
|
|
|
|
bool tca_set_direction(uint8_t dir);
|
2020-03-15 15:14:06 +01:00
|
|
|
int16_t get_concentration(uint16_t pressure = 10124);
|