This commit is contained in:
2020-06-11 11:25:19 +02:00
parent 5cb02880b3
commit 5177cd5cbd
15 changed files with 1090 additions and 411 deletions

View File

@@ -1,9 +1,10 @@
#ifndef SENS_BME280
#define SENS_BME280
#include "../../io/SoftI2C.h"
#include "../../Platforms.h"
#include "../../Debug.h"
class BME280 {
template <typename I2C> class BME280 {
static constexpr const char* NAME = "BME280";
@@ -53,11 +54,15 @@ public:
} cal;
I2C& i2c;
BME280(I2C& i2c) : i2c(i2c) {
}
bool isPresent() {
return i2c::query(ADDR7);
return i2c.query(ADDR7);
}
private:
@@ -178,20 +183,20 @@ public:
bool ok;
// address the slave in write mode and select the first register to read
ok = i2c::startWrite(ADDR7);
ok = i2c.startWrite(ADDR7);
if (!ok) {os_printf("failed start write\n"); return false;}
ok = i2c::writeByteAndCheck(addr);
ok = i2c.writeByteAndCheck(addr);
if (!ok) {os_printf("failed to select register %d\n", addr); return false;}
//i2c::stop();
// address the slave in read mode and read [len] registers
ok = i2c::startRead(ADDR7);
ok = i2c.startRead(ADDR7);
if (!ok) {os_printf("failed start read\n"); return 0;}
i2c::readBytes(dst, len);
i2c.readBytes(dst, len);
// done
i2c::stop();
i2c.stop();
return true;
}
@@ -201,15 +206,15 @@ public:
bool ok;
// address the slave in write mode and select the first register to read
ok = i2c::startWrite(ADDR7);
ok = i2c.startWrite(ADDR7);
if (!ok) {os_printf("failed start write\n"); return false;}
ok = i2c::writeByteAndCheck(addr);
ok = i2c.writeByteAndCheck(addr);
if (!ok) {os_printf("failed to select register %d\n", addr); return false;}
ok = i2c::writeBytesAndCheck(src, len);
ok = i2c.writeBytesAndCheck(src, len);
if (!ok) {os_printf("failed to write register contents \n"); return false;}
// done
i2c::stop();
i2c.stop();
return true;
}