bmp280: add function to check for valid measurements

This commit is contained in:
Thomas Kolb 2022-10-15 21:41:50 +02:00
parent 07dd91ecc2
commit c807acec11
2 changed files with 11 additions and 0 deletions

View file

@ -39,6 +39,7 @@ extern int16_t dig_P9;
static fxp_t m_last_temperature = 0;
static fxp_t m_last_pressure = 0;
static bool m_measurements_valid = false;
static int32_t m_temp_raw;
static int32_t m_press_raw;
@ -49,6 +50,8 @@ static void cb_i2c_dma(const uint8_t *rdata, size_t rlen);
bool bmp280_init(void)
{
m_measurements_valid = false;
// configure pins for I2C1
gpio_set_af(BMP280_I2C_PORT, GPIO_AF4, BMP280_I2C_SCL | BMP280_I2C_SDA);
gpio_mode_setup(BMP280_I2C_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, BMP280_I2C_SCL | BMP280_I2C_SDA);
@ -214,6 +217,7 @@ bool bmp280_loop(void)
case COMPENSATE_PRESSURE:
m_last_pressure = bmp280_comp_pressure(m_press_raw);
m_readout_state = READY;
m_measurements_valid = true;
retval = true;
break;
}
@ -246,6 +250,12 @@ bool bmp280_start_measurement(void)
}
bool bmp280_are_measurements_valid(void)
{
return m_measurements_valid;
}
fxp_t bmp280_get_temperature(void)
{
return m_last_temperature;

View file

@ -11,6 +11,7 @@ bool bmp280_loop(void); // returns true if measurements have been updated
bool bmp280_start_measurement(void);
bool bmp280_are_measurements_valid(void);
fxp_t bmp280_get_temperature(void);
fxp_t bmp280_get_pressure(void);