|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include "baro_interface.h" |
| 4 | +#include "../common/MF_I2C.h" |
| 5 | +#include "BMP280/BMP280.h" |
| 6 | + |
| 7 | +class BaroSensorBMP280: public BaroSensor { |
| 8 | +protected: |
| 9 | + Adafruit_BMP280 baro_BMP280; |
| 10 | +public: |
| 11 | + int setup(MF_I2C *i2c, int8_t i2c_adr, uint32_t sampleRate) override { |
| 12 | + (void) sampleRate; //TODO use sampleRate |
| 13 | + unsigned status; |
| 14 | + status = baro_BMP280.begin(i2c, i2c_adr, BMP280_CHIPID); |
| 15 | + Serial.printf("BARO: BARO_USE_BMP280 BARO_I2C_ADR=0x%02X SensorID=0x%02X\n", i2c_adr, baro_BMP280.sensorID()); |
| 16 | + |
| 17 | + if (!status) { |
| 18 | + Serial.println(F("Could not find a valid BMP280 sensor, check wiring or try a different address!")); |
| 19 | + Serial.print("SensorID was: 0x"); |
| 20 | + Serial.println(baro_BMP280.sensorID(),16); |
| 21 | + Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n"); |
| 22 | + Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n"); |
| 23 | + Serial.print(" ID of 0x60 represents a BME 280.\n"); |
| 24 | + Serial.print(" ID of 0x61 represents a BME 680.\n"); |
| 25 | + } |
| 26 | + |
| 27 | + baro_BMP280.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */ |
| 28 | + Adafruit_BMP280::SAMPLING_X1, /* Temp. oversampling */ |
| 29 | + Adafruit_BMP280::SAMPLING_X1, /* Pressure oversampling */ |
| 30 | + Adafruit_BMP280::FILTER_OFF, /* Filtering. */ |
| 31 | + Adafruit_BMP280::STANDBY_MS_1); /* Standby time. */ |
| 32 | + return status; |
| 33 | + } |
| 34 | + |
| 35 | + bool update(float *press, float *temp) override { |
| 36 | + //driver does not return whether data is fresh, return true if pressure changed |
| 37 | + float press_new = baro_BMP280.readPressure(); |
| 38 | + bool rv = (press_new != *press); |
| 39 | + *press = press_new; |
| 40 | + *temp = baro_BMP280.readTemperature(); |
| 41 | + return rv; |
| 42 | + } |
| 43 | +}; |
0 commit comments