diff --git a/src/bmp280.c b/src/bmp280.c index 66c1a2a..6de71e8 100644 --- a/src/bmp280.c +++ b/src/bmp280.c @@ -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; diff --git a/src/bmp280.h b/src/bmp280.h index 17abd92..b25a2a7 100644 --- a/src/bmp280.h +++ b/src/bmp280.h @@ -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);