Adjust some usermods to use global I2C

* usermods only need to to `if (!pinManager.joinWire()) return;`

* joinWire will
* * check if global I2C are defined - return false if not defined
* * aloocate HW_I2C pins - return false on error
* * call Wire.begin() if needed.
This commit is contained in:
Frank
2023-01-08 21:11:50 +01:00
parent edb6bfc2f9
commit 39ad4955b7
6 changed files with 65 additions and 30 deletions

View File

@@ -80,6 +80,7 @@ private:
void UpdateBME280Data(int SensorType)
{
float _temperature, _humidity, _pressure;
if (!enabled || (sensorType == 0)) return; // WLEDMM bugfix
if (UseCelsius) {
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
@@ -183,12 +184,13 @@ public:
void setup()
{
bool HW_Pins_Used = (ioPin[0]==i2c_scl && ioPin[1]==i2c_sda); // note whether architecture-based hardware SCL/SDA pins used
PinOwner po = PinOwner::UM_BME280; // defaults to being pinowner for SCL/SDA pins
//PinOwner po = PinOwner::UM_BME280; // defaults to being pinowner for SCL/SDA pins // WLEDMM not needed
PinManagerPinType pins[2] = { { ioPin[0], true }, { ioPin[1], true } }; // allocate pins
if (HW_Pins_Used) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins
if (!pinManager.allocateMultiplePins(pins, 2, po)) { sensorType=0; return; }
Wire.begin(ioPin[1], ioPin[0]);
//if (HW_Pins_Used) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins // WLEDMM not needed
// WLEDMM join I2C HW wire
if (!pinManager.joinWire()) { sensorType=0; enabled = false; return; }
//if (!pinManager.allocateMultiplePins(pins, 2, po)) { sensorType=0; return; }
//Wire.begin(ioPin[1], ioPin[0]);
if (!bme.begin())
{