Skip to content

Commit 19f39dc

Browse files
use TwoWire
1 parent 1d65317 commit 19f39dc

File tree

6 files changed

+24
-16
lines changed

6 files changed

+24
-16
lines changed

BH1750_LightSensor_Mux/BH1750_LightSensor_Mux.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2020-2021, Collab
1+
/* Copyright (c) 2020-2023, Collab
22
* All rights reserved
33
*/
44
/*
@@ -8,6 +8,7 @@
88

99
BH1750_LightSensor_Mux::BH1750_LightSensor_Mux(
1010
MultiPlexer_TCA9548A* expander,
11+
TwoWire* wire,
1112
uint8_t expander_channel,
1213
int address,
1314
BH1750Mode modus
@@ -17,7 +18,7 @@ BH1750_LightSensor_Mux::BH1750_LightSensor_Mux(
1718
_modus = modus;
1819
_address = address;
1920

20-
_lightMeter = new BH1750_WE(&Wire1, _address);
21+
_lightMeter = new BH1750_WE(wire, _address);
2122
}
2223

2324
void BH1750_LightSensor_Mux::begin() {

BH1750_LightSensor_Mux/BH1750_LightSensor_Mux.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2020-2021, Collab
1+
/* Copyright (c) 2020-2023, Collab
22
* All rights reserved
33
*/
44
/*
@@ -16,6 +16,7 @@ class BH1750_LightSensor_Mux {
1616
public:
1717
BH1750_LightSensor_Mux(
1818
MultiPlexer_TCA9548A* expander,
19+
TwoWire* wire,
1920
uint8_t expander_channel,
2021
int address = 0x23,
2122
BH1750Mode modus = BH1750Mode::CHM

BME280_BarometerSensor/BME280_BarometerSensor.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2020-2021, Collab
1+
/* Copyright (c) 2020-2023, Collab
22
* All rights reserved
33
*/
44
/*
@@ -23,14 +23,16 @@ BME280_BarometerSensor::BME280_BarometerSensor(
2323
_sensor = new Adafruit_BME280();
2424
}
2525

26-
void BME280_BarometerSensor::begin() {
26+
bool BME280_BarometerSensor::begin() {
2727
_i2c->begin(_sdaPin, _sclPin, _clockSpeed);
2828

2929
bool status;
3030
status = _sensor->begin(_address, _i2c);
3131
if (!status) {
3232
Log.warning(F("Could not find a valid BME280 sensor, check wiring!" CR));
3333
}
34+
35+
return status;
3436
}
3537

3638
void BME280_BarometerSensor::loop() {

BME280_BarometerSensor/BME280_BarometerSensor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2020-2021, Collab
1+
/* Copyright (c) 2020-2023, Collab
22
* All rights reserved
33
*/
44
/*
@@ -30,7 +30,7 @@ class BME280_BarometerSensor
3030
float sea_level_pressure = 1013,
3131
long clock_speed = 100000
3232
);
33-
void begin();
33+
bool begin();
3434
void loop();
3535
float getTemperature();
3636
float getPressure();

BME280_BarometerSensor_Mux/BME280_BarometerSensor_Mux.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2020-2021, Collab
1+
/* Copyright (c) 2020-2023, Collab
22
* All rights reserved
33
*/
44
/*
@@ -8,12 +8,14 @@
88

99
BME280_BarometerSensor_Mux::BME280_BarometerSensor_Mux(
1010
MultiPlexer_TCA9548A* expander,
11+
TwoWire* wire,
1112
uint8_t expander_channel,
1213
int address,
1314
float sea_level_pressure,
1415
int clock_speed
1516
) {
1617
_expander = expander;
18+
_wire = wire;
1719
_expanderChannel = expander_channel;
1820
_address = address;
1921
_clockSpeed = clock_speed;
@@ -22,15 +24,14 @@ BME280_BarometerSensor_Mux::BME280_BarometerSensor_Mux(
2224
_sensor = new Adafruit_BME280();
2325
}
2426

25-
void BME280_BarometerSensor_Mux::begin() {
27+
bool BME280_BarometerSensor_Mux::begin() {
2628
_expander->openChannel(_expanderChannel);
2729

28-
bool status = _sensor->begin(_address, &Wire1);
29-
if (!status) {
30-
Log.warning(F("Error initialising BME280 sensor" CR));
31-
}
30+
working = _sensor->begin(_address, _wire);
3231

3332
_expander->closeChannel(_expanderChannel);
33+
34+
return working;
3435
}
3536

3637
float BME280_BarometerSensor_Mux::getTemperature() {

BME280_BarometerSensor_Mux/BME280_BarometerSensor_Mux.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2020-2021, Collab
1+
/* Copyright (c) 2020-2023, Collab
22
* All rights reserved
33
*/
44
/*
@@ -10,7 +10,6 @@
1010
#include <Arduino.h>
1111
#include <Wire.h>
1212
#include <SPI.h>
13-
#include <ArduinoLog.h>
1413
#include <Adafruit_Sensor.h>
1514
#include <Adafruit_BME280.h>
1615
#include <MultiPlexer_TCA9548A.h>
@@ -26,24 +25,28 @@ class BME280_BarometerSensor_Mux {
2625
public:
2726
BME280_BarometerSensor_Mux(
2827
MultiPlexer_TCA9548A* expander,
28+
TwoWire* wire,
2929
uint8_t expander_channel = 0,
3030
int address = 0x76,
3131
float sea_level_pressure = 1013,
3232
int clock_speed = 100000
3333
);
34-
void begin();
34+
bool begin();
3535
float getTemperature();
3636
float getPressure();
3737
float getAltitude();
3838
float getHumidity();
3939
BME280_Result readAll();
4040

41+
bool working = false;
42+
4143
private:
4244
uint8_t _expanderChannel;
4345
int _address;
4446
int _clockSpeed;
4547
float _seaLevelPressure;
4648

49+
TwoWire* _wire;
4750
Adafruit_BME280* _sensor;
4851
MultiPlexer_TCA9548A* _expander;
4952
};

0 commit comments

Comments
 (0)