Skip to content

Commit

Permalink
fix(api): optional build without global instances
Browse files Browse the repository at this point in the history
  • Loading branch information
malokhvii-eduard committed Jun 7, 2022
1 parent 4ab6ed1 commit e9681d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Bme280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,16 @@ Bme280TwoWire::Bme280TwoWire() : wire_(nullptr) {}

Bme280TwoWire::~Bme280TwoWire() {}

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_TWOWIRE)

void Bme280TwoWire::begin() { begin(Bme280TwoWireAddress::Primary); }

void Bme280TwoWire::begin(const Bme280TwoWireAddress address) {
begin(address, &Wire);
}

#endif

void Bme280TwoWire::begin(const Bme280TwoWireAddress address, TwoWire *wire) {
address_ = static_cast<uint8_t>(address);
wire_ = wire;
Expand Down Expand Up @@ -310,8 +314,12 @@ Bme280FourWire::~Bme280FourWire() {}
const SPISettings Bme280FourWire::spiSettings_ =
SPISettings(SPISettings(500000, MSBFIRST, SPI_MODE0));

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SPI)

void Bme280FourWire::begin(const uint8_t csPin) { begin(csPin, &SPI); }

#endif

void Bme280FourWire::begin(const uint8_t csPin, SPIClass *spi) {
spi_ = spi;
csPin_ = csPin;
Expand Down
4 changes: 4 additions & 0 deletions src/Bme280.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,10 @@ class Bme280TwoWire final : public ::internal::AbstractBme280 {
Bme280TwoWire();
virtual ~Bme280TwoWire();

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_TWOWIRE)
void begin();
void begin(const Bme280TwoWireAddress address);
#endif
void begin(const Bme280TwoWireAddress address, TwoWire *wire);

uint8_t getAddress() const;
Expand All @@ -293,7 +295,9 @@ class Bme280FourWire final : public ::internal::AbstractBme280 {
Bme280FourWire();
virtual ~Bme280FourWire();

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SPI)
void begin(const uint8_t csPin);
#endif
void begin(const uint8_t csPin, SPIClass *spi);

uint8_t getCsPin() const;
Expand Down

0 comments on commit e9681d0

Please sign in to comment.