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

@@ -50,14 +50,21 @@ class UsermodVL53L0XGestures : public Usermod {
public:
void setup() {
PinManagerPinType pins[2] = { { i2c_scl, true }, { i2c_sda, true } };
if (!pinManager.allocateMultiplePins(pins, 2, PinOwner::HW_I2C)) { enabled = false; return; }
Wire.begin();
// WLEDMM join hardware I2C
if (!pinManager.joinWire()) { // WLEDMM - this allocates global I2C pins, then starts Wire - if not started previously
enabled = false;
return;
}
//PinManagerPinType pins[2] = { { i2c_scl, true }, { i2c_sda, true } };
//if (!pinManager.allocateMultiplePins(pins, 2, PinOwner::HW_I2C)) { enabled = false; return; }
//Wire.begin();
sensor.setTimeout(150);
if (!sensor.init())
{
DEBUG_PRINTLN(F("Failed to detect and initialize VL53L0X sensor!"));
enabled = false; // WLEDMM bugfix
} else {
sensor.setMeasurementTimingBudget(20000); // set high speed mode
}