From ebb17df2466cfdc5cdc526597bb3666d1c6fd455 Mon Sep 17 00:00:00 2001 From: James Whitlock Date: Tue, 12 Nov 2024 16:46:48 +0000 Subject: [PATCH 1/3] Add support for non-default I2C masters #30 --- src/F_AK09918.hpp | 32 ++++++++++++++++---------------- src/F_AK8963.hpp | 32 ++++++++++++++++---------------- src/F_AK8975.hpp | 32 ++++++++++++++++---------------- src/F_BMI055.hpp | 32 ++++++++++++++++---------------- src/F_BMI055_AK8975.hpp | 2 +- src/F_BMI055_HMC5883L.hpp | 2 +- src/F_BMI055_QMC5883L.hpp | 2 +- src/F_BMI160.hpp | 32 ++++++++++++++++---------------- src/F_BMI160_AK8975.hpp | 2 +- src/F_BMI160_HMC5883L.hpp | 2 +- src/F_BMI160_QMC5883L.hpp | 2 +- src/F_BMX055.hpp | 32 ++++++++++++++++---------------- src/F_HMC5883L.hpp | 32 ++++++++++++++++---------------- src/F_ICM20689.hpp | 32 ++++++++++++++++---------------- src/F_ICM20689_AK8975.hpp | 2 +- src/F_ICM20689_HMC5883L.hpp | 2 +- src/F_ICM20689_QMC5883L.hpp | 2 +- src/F_ICM20690.hpp | 32 ++++++++++++++++---------------- src/F_ICM20690_AK8975.hpp | 2 +- src/F_ICM20690_HMC5883L.hpp | 2 +- src/F_ICM20690_QMC5883L.hpp | 2 +- src/F_IMU_Generic.hpp | 32 ++++++++++++++++---------------- src/F_IMU_Generic_AK8975.hpp | 2 +- src/F_IMU_Generic_HMC5883L.hpp | 2 +- src/F_IMU_Generic_QMC5883L.hpp | 2 +- src/F_LSM6DS3.hpp | 32 ++++++++++++++++---------------- src/F_LSM6DS3_AK8975.hpp | 2 +- src/F_LSM6DS3_HMC5883L.hpp | 2 +- src/F_LSM6DS3_QMC5883L.hpp | 2 +- src/F_LSM6DSL.hpp | 32 ++++++++++++++++---------------- src/F_LSM6DSL_AK8975.hpp | 2 +- src/F_LSM6DSL_HMC5883L.hpp | 2 +- src/F_LSM6DSL_QMC5883L.hpp | 2 +- src/F_MPU6050.hpp | 32 ++++++++++++++++---------------- src/F_MPU6050_AK8975.hpp | 2 +- src/F_MPU6050_HMC5883L.hpp | 2 +- src/F_MPU6050_QMC5883L.hpp | 2 +- src/F_MPU6500.hpp | 32 ++++++++++++++++---------------- src/F_MPU6500_AK8975.hpp | 2 +- src/F_MPU6500_HMC5883L.hpp | 2 +- src/F_MPU6500_QMC5883L.hpp | 2 +- src/F_MPU6515.hpp | 32 ++++++++++++++++---------------- src/F_MPU6515_AK8975.hpp | 2 +- src/F_MPU6515_HMC5883L.hpp | 2 +- src/F_MPU6515_QMC5883L.hpp | 2 +- src/F_MPU6886.hpp | 32 ++++++++++++++++---------------- src/F_MPU9250.hpp | 32 ++++++++++++++++---------------- src/F_MPU9255.hpp | 32 ++++++++++++++++---------------- src/F_QMC5883L.hpp | 32 ++++++++++++++++---------------- src/F_QMI8658.hpp | 32 ++++++++++++++++---------------- src/F_QMI8658_AK09918.hpp | 2 +- src/F_QMI8658_AK8975.hpp | 2 +- src/F_QMI8658_HMC5883L.hpp | 2 +- src/F_QMI8658_QMC5883L.hpp | 2 +- src/IMUBase.hpp | 4 ++++ 55 files changed, 358 insertions(+), 354 deletions(-) diff --git a/src/F_AK09918.hpp b/src/F_AK09918.hpp index 366c37c..cf885bd 100644 --- a/src/F_AK09918.hpp +++ b/src/F_AK09918.hpp @@ -58,7 +58,7 @@ enum AK09918_err_type_t { class AK09918 : public IMUBase { public: - AK09918() {}; + explicit AK09918(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -112,32 +112,32 @@ class AK09918 : public IMUBase { void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.write(data); // Put data in Tx buffer - Wire.endTransmission(); // Send the Tx buffer + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.write(data); // Put data in Tx buffer + wire.endTransmission(); // Send the Tx buffer } uint8_t readByte(uint8_t address, uint8_t subAddress) { uint8_t data; // `data` will store the register data - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive - Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address - data = Wire.read(); // Fill Rx buffer with result + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address + data = wire.read(); // Fill Rx buffer with result return data; // Return data read from slave register } void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive uint8_t i = 0; - Wire.requestFrom(address, count); // Read bytes from slave register address - while (Wire.available()) { - dest[i++] = Wire.read(); + wire.requestFrom(address, count); // Read bytes from slave register address + while (wire.available()) { + dest[i++] = wire.read(); } // Put read results in the Rx buffer } diff --git a/src/F_AK8963.hpp b/src/F_AK8963.hpp index 2fa7d3f..6ec63cc 100644 --- a/src/F_AK8963.hpp +++ b/src/F_AK8963.hpp @@ -33,7 +33,7 @@ class AK8963 : public IMUBase { public: - AK8963() {}; + explicit AK8963(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -84,32 +84,32 @@ class AK8963 : public IMUBase { void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.write(data); // Put data in Tx buffer - Wire.endTransmission(); // Send the Tx buffer + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.write(data); // Put data in Tx buffer + wire.endTransmission(); // Send the Tx buffer } uint8_t readByte(uint8_t address, uint8_t subAddress) { uint8_t data; // `data` will store the register data - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive - Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address - data = Wire.read(); // Fill Rx buffer with result + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address + data = wire.read(); // Fill Rx buffer with result return data; // Return data read from slave register } void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive uint8_t i = 0; - Wire.requestFrom(address, count); // Read bytes from slave register address - while (Wire.available()) { - dest[i++] = Wire.read(); + wire.requestFrom(address, count); // Read bytes from slave register address + while (wire.available()) { + dest[i++] = wire.read(); } // Put read results in the Rx buffer } diff --git a/src/F_AK8975.hpp b/src/F_AK8975.hpp index 42b9b11..f41b43a 100644 --- a/src/F_AK8975.hpp +++ b/src/F_AK8975.hpp @@ -33,7 +33,7 @@ class AK8975 : public IMUBase { public: - AK8975() {}; + explicit AK8975(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -84,32 +84,32 @@ class AK8975 : public IMUBase { void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.write(data); // Put data in Tx buffer - Wire.endTransmission(); // Send the Tx buffer + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.write(data); // Put data in Tx buffer + wire.endTransmission(); // Send the Tx buffer } uint8_t readByte(uint8_t address, uint8_t subAddress) { uint8_t data; // `data` will store the register data - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive - Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address - data = Wire.read(); // Fill Rx buffer with result + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address + data = wire.read(); // Fill Rx buffer with result return data; // Return data read from slave register } void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive uint8_t i = 0; - Wire.requestFrom(address, count); // Read bytes from slave register address - while (Wire.available()) { - dest[i++] = Wire.read(); + wire.requestFrom(address, count); // Read bytes from slave register address + while (wire.available()) { + dest[i++] = wire.read(); } // Put read results in the Rx buffer } diff --git a/src/F_BMI055.hpp b/src/F_BMI055.hpp index 1906432..400828d 100644 --- a/src/F_BMI055.hpp +++ b/src/F_BMI055.hpp @@ -41,7 +41,7 @@ class BMI055 : public IMUBase { public: - BMI055() {}; + explicit BMI055(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -97,32 +97,32 @@ class BMI055 : public IMUBase { void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.write(data); // Put data in Tx buffer - Wire.endTransmission(); // Send the Tx buffer + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.write(data); // Put data in Tx buffer + wire.endTransmission(); // Send the Tx buffer } uint8_t readByte(uint8_t address, uint8_t subAddress) { uint8_t data; // `data` will store the register data - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive - Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address - data = Wire.read(); // Fill Rx buffer with result + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address + data = wire.read(); // Fill Rx buffer with result return data; // Return data read from slave register } void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive uint8_t i = 0; - Wire.requestFrom(address, count); // Read bytes from slave register address - while (Wire.available()) { - dest[i++] = Wire.read(); + wire.requestFrom(address, count); // Read bytes from slave register address + while (wire.available()) { + dest[i++] = wire.read(); } // Put read results in the Rx buffer } }; diff --git a/src/F_BMI055_AK8975.hpp b/src/F_BMI055_AK8975.hpp index 6b79eae..7fbc188 100644 --- a/src/F_BMI055_AK8975.hpp +++ b/src/F_BMI055_AK8975.hpp @@ -8,7 +8,7 @@ class BMI055_QMC5883L : public IMUBase { public: - BMI055_QMC5883L() {}; + explicit BMI055_QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_BMI055_HMC5883L.hpp b/src/F_BMI055_HMC5883L.hpp index 362d832..7d6075a 100644 --- a/src/F_BMI055_HMC5883L.hpp +++ b/src/F_BMI055_HMC5883L.hpp @@ -8,7 +8,7 @@ class BMI055_HMC5883L : public IMUBase { public: - BMI055_HMC5883L() {}; + explicit BMI055_HMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_BMI055_QMC5883L.hpp b/src/F_BMI055_QMC5883L.hpp index 6b79eae..7fbc188 100644 --- a/src/F_BMI055_QMC5883L.hpp +++ b/src/F_BMI055_QMC5883L.hpp @@ -8,7 +8,7 @@ class BMI055_QMC5883L : public IMUBase { public: - BMI055_QMC5883L() {}; + explicit BMI055_QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_BMI160.hpp b/src/F_BMI160.hpp index 5d58cc0..4b397f1 100644 --- a/src/F_BMI160.hpp +++ b/src/F_BMI160.hpp @@ -103,7 +103,7 @@ class BMI160 : public IMUBase { public: - BMI160() {}; + explicit BMI160(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -157,32 +157,32 @@ class BMI160 : public IMUBase { void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.write(data); // Put data in Tx buffer - Wire.endTransmission(); // Send the Tx buffer + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.write(data); // Put data in Tx buffer + wire.endTransmission(); // Send the Tx buffer } uint8_t readByte(uint8_t address, uint8_t subAddress) { uint8_t data; // `data` will store the register data - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive - Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address - data = Wire.read(); // Fill Rx buffer with result + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address + data = wire.read(); // Fill Rx buffer with result return data; // Return data read from slave register } void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive uint8_t i = 0; - Wire.requestFrom(address, count); // Read bytes from slave register address - while (Wire.available()) { - dest[i++] = Wire.read(); + wire.requestFrom(address, count); // Read bytes from slave register address + while (wire.available()) { + dest[i++] = wire.read(); } // Put read results in the Rx buffer } }; diff --git a/src/F_BMI160_AK8975.hpp b/src/F_BMI160_AK8975.hpp index 1de5c54..65c6414 100644 --- a/src/F_BMI160_AK8975.hpp +++ b/src/F_BMI160_AK8975.hpp @@ -8,7 +8,7 @@ class BMI160_AK8975 : public IMUBase { public: - BMI160_AK8975() {}; + explicit BMI160_AK8975(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_BMI160_HMC5883L.hpp b/src/F_BMI160_HMC5883L.hpp index ff59a9c..1e0ea2a 100644 --- a/src/F_BMI160_HMC5883L.hpp +++ b/src/F_BMI160_HMC5883L.hpp @@ -8,7 +8,7 @@ class BMI160_HMC5883L : public IMUBase { public: - BMI160_HMC5883L() {}; + explicit BMI160_HMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_BMI160_QMC5883L.hpp b/src/F_BMI160_QMC5883L.hpp index efc09f2..beece33 100644 --- a/src/F_BMI160_QMC5883L.hpp +++ b/src/F_BMI160_QMC5883L.hpp @@ -8,7 +8,7 @@ class BMI160_QMC5883L : public IMUBase { public: - BMI160_QMC5883L() {}; + explicit BMI160_QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_BMX055.hpp b/src/F_BMX055.hpp index cc4abb9..afd382f 100644 --- a/src/F_BMX055.hpp +++ b/src/F_BMX055.hpp @@ -61,7 +61,7 @@ class BMX055 : public IMUBase { public: - BMX055() {}; + explicit BMX055(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -121,32 +121,32 @@ class BMX055 : public IMUBase { void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.write(data); // Put data in Tx buffer - Wire.endTransmission(); // Send the Tx buffer + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.write(data); // Put data in Tx buffer + wire.endTransmission(); // Send the Tx buffer } uint8_t readByte(uint8_t address, uint8_t subAddress) { uint8_t data; // `data` will store the register data - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive - Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address - data = Wire.read(); // Fill Rx buffer with result + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address + data = wire.read(); // Fill Rx buffer with result return data; // Return data read from slave register } void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive uint8_t i = 0; - Wire.requestFrom(address, count); // Read bytes from slave register address - while (Wire.available()) { - dest[i++] = Wire.read(); + wire.requestFrom(address, count); // Read bytes from slave register address + while (wire.available()) { + dest[i++] = wire.read(); } // Put read results in the Rx buffer } }; diff --git a/src/F_HMC5883L.hpp b/src/F_HMC5883L.hpp index 7f0b6a3..4447122 100644 --- a/src/F_HMC5883L.hpp +++ b/src/F_HMC5883L.hpp @@ -28,7 +28,7 @@ class HMC5883L : public IMUBase { public: - HMC5883L() {}; + explicit HMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -76,32 +76,32 @@ class HMC5883L : public IMUBase { void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.write(data); // Put data in Tx buffer - Wire.endTransmission(); // Send the Tx buffer + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.write(data); // Put data in Tx buffer + wire.endTransmission(); // Send the Tx buffer } uint8_t readByte(uint8_t address, uint8_t subAddress) { uint8_t data; // `data` will store the register data - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive - Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address - data = Wire.read(); // Fill Rx buffer with result + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address + data = wire.read(); // Fill Rx buffer with result return data; // Return data read from slave register } void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive uint8_t i = 0; - Wire.requestFrom(address, count); // Read bytes from slave register address - while (Wire.available()) { - dest[i++] = Wire.read(); + wire.requestFrom(address, count); // Read bytes from slave register address + while (wire.available()) { + dest[i++] = wire.read(); } // Put read results in the Rx buffer } }; diff --git a/src/F_ICM20689.hpp b/src/F_ICM20689.hpp index 6ee2655..0277b91 100644 --- a/src/F_ICM20689.hpp +++ b/src/F_ICM20689.hpp @@ -84,7 +84,7 @@ class ICM20689 : public IMUBase { public: - ICM20689() {}; + explicit ICM20689(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -138,32 +138,32 @@ class ICM20689 : public IMUBase { void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.write(data); // Put data in Tx buffer - Wire.endTransmission(); // Send the Tx buffer + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.write(data); // Put data in Tx buffer + wire.endTransmission(); // Send the Tx buffer } uint8_t readByte(uint8_t address, uint8_t subAddress) { uint8_t data; // `data` will store the register data - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive - Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address - data = Wire.read(); // Fill Rx buffer with result + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address + data = wire.read(); // Fill Rx buffer with result return data; // Return data read from slave register } void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive uint8_t i = 0; - Wire.requestFrom(address, count); // Read bytes from slave register address - while (Wire.available()) { - dest[i++] = Wire.read(); + wire.requestFrom(address, count); // Read bytes from slave register address + while (wire.available()) { + dest[i++] = wire.read(); } // Put read results in the Rx buffer } diff --git a/src/F_ICM20689_AK8975.hpp b/src/F_ICM20689_AK8975.hpp index 423218b..3d51886 100644 --- a/src/F_ICM20689_AK8975.hpp +++ b/src/F_ICM20689_AK8975.hpp @@ -8,7 +8,7 @@ class ICM20689_AK8975 : public IMUBase { public: - ICM20689_AK8975() {}; + explicit ICM20689_AK8975(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_ICM20689_HMC5883L.hpp b/src/F_ICM20689_HMC5883L.hpp index 04a8088..2b89d5e 100644 --- a/src/F_ICM20689_HMC5883L.hpp +++ b/src/F_ICM20689_HMC5883L.hpp @@ -8,7 +8,7 @@ class ICM20689_HMC5883L : public IMUBase { public: - ICM20689_HMC5883L() {}; + explicit ICM20689_HMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_ICM20689_QMC5883L.hpp b/src/F_ICM20689_QMC5883L.hpp index c62dfc7..e5e73d7 100644 --- a/src/F_ICM20689_QMC5883L.hpp +++ b/src/F_ICM20689_QMC5883L.hpp @@ -8,7 +8,7 @@ class ICM20689_QMC5883L : public IMUBase { public: - ICM20689_QMC5883L() {}; + explicit ICM20689_QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_ICM20690.hpp b/src/F_ICM20690.hpp index 977f2d9..333a01f 100644 --- a/src/F_ICM20690.hpp +++ b/src/F_ICM20690.hpp @@ -84,7 +84,7 @@ class ICM20690 : public IMUBase { public: - ICM20690() {}; + explicit ICM20690(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -137,32 +137,32 @@ class ICM20690 : public IMUBase { void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.write(data); // Put data in Tx buffer - Wire.endTransmission(); // Send the Tx buffer + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.write(data); // Put data in Tx buffer + wire.endTransmission(); // Send the Tx buffer } uint8_t readByte(uint8_t address, uint8_t subAddress) { uint8_t data; // `data` will store the register data - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive - Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address - data = Wire.read(); // Fill Rx buffer with result + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address + data = wire.read(); // Fill Rx buffer with result return data; // Return data read from slave register } void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive uint8_t i = 0; - Wire.requestFrom(address, count); // Read bytes from slave register address - while (Wire.available()) { - dest[i++] = Wire.read(); + wire.requestFrom(address, count); // Read bytes from slave register address + while (wire.available()) { + dest[i++] = wire.read(); } // Put read results in the Rx buffer } diff --git a/src/F_ICM20690_AK8975.hpp b/src/F_ICM20690_AK8975.hpp index 31ca3d2..466a961 100644 --- a/src/F_ICM20690_AK8975.hpp +++ b/src/F_ICM20690_AK8975.hpp @@ -8,7 +8,7 @@ class ICM20690_AK8975 : public IMUBase { public: - ICM20690_AK8975() {}; + explicit ICM20690_AK8975(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_ICM20690_HMC5883L.hpp b/src/F_ICM20690_HMC5883L.hpp index 9722aa9..ac692a2 100644 --- a/src/F_ICM20690_HMC5883L.hpp +++ b/src/F_ICM20690_HMC5883L.hpp @@ -8,7 +8,7 @@ class ICM20690_HMC5883L : public IMUBase { public: - ICM20690_HMC5883L() {}; + explicit ICM20690_HMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_ICM20690_QMC5883L.hpp b/src/F_ICM20690_QMC5883L.hpp index 894a8f6..92c3570 100644 --- a/src/F_ICM20690_QMC5883L.hpp +++ b/src/F_ICM20690_QMC5883L.hpp @@ -8,7 +8,7 @@ class ICM20690_QMC5883L : public IMUBase { public: - ICM20690_QMC5883L() {}; + explicit ICM20690_QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_IMU_Generic.hpp b/src/F_IMU_Generic.hpp index ba5ed23..91698ac 100644 --- a/src/F_IMU_Generic.hpp +++ b/src/F_IMU_Generic.hpp @@ -161,7 +161,7 @@ class IMU_Generic : public IMUBase { public: - IMU_Generic() {}; + explicit IMU_Generic(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -217,32 +217,32 @@ class IMU_Generic : public IMUBase { void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.write(data); // Put data in Tx buffer - Wire.endTransmission(); // Send the Tx buffer + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.write(data); // Put data in Tx buffer + wire.endTransmission(); // Send the Tx buffer } uint8_t readByte(uint8_t address, uint8_t subAddress) { uint8_t data; // `data` will store the register data - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive - Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address - data = Wire.read(); // Fill Rx buffer with result + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address + data = wire.read(); // Fill Rx buffer with result return data; // Return data read from slave register } void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive uint8_t i = 0; - Wire.requestFrom(address, count); // Read bytes from slave register address - while (Wire.available()) { - dest[i++] = Wire.read(); + wire.requestFrom(address, count); // Read bytes from slave register address + while (wire.available()) { + dest[i++] = wire.read(); } // Put read results in the Rx buffer } diff --git a/src/F_IMU_Generic_AK8975.hpp b/src/F_IMU_Generic_AK8975.hpp index 532f213..03a6077 100644 --- a/src/F_IMU_Generic_AK8975.hpp +++ b/src/F_IMU_Generic_AK8975.hpp @@ -8,7 +8,7 @@ class IMU_Generic_AK8975 : public IMUBase { public: - IMU_Generic_AK8975() {}; + explicit IMU_Generic_AK8975(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_IMU_Generic_HMC5883L.hpp b/src/F_IMU_Generic_HMC5883L.hpp index 7f255d7..c8c3410 100644 --- a/src/F_IMU_Generic_HMC5883L.hpp +++ b/src/F_IMU_Generic_HMC5883L.hpp @@ -8,7 +8,7 @@ class IMU_Generic_HMC5883L : public IMUBase { public: - IMU_Generic_HMC5883L() {}; + explicit IMU_Generic_HMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_IMU_Generic_QMC5883L.hpp b/src/F_IMU_Generic_QMC5883L.hpp index e4a2685..c12adc0 100644 --- a/src/F_IMU_Generic_QMC5883L.hpp +++ b/src/F_IMU_Generic_QMC5883L.hpp @@ -8,7 +8,7 @@ class IMU_Generic_QMC5883L : public IMUBase { public: - IMU_Generic_QMC5883L() {}; + explicit IMU_Generic_QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_LSM6DS3.hpp b/src/F_LSM6DS3.hpp index ae0a59d..c3c3f28 100644 --- a/src/F_LSM6DS3.hpp +++ b/src/F_LSM6DS3.hpp @@ -54,7 +54,7 @@ class LSM6DS3 : public IMUBase { public: - LSM6DS3() {}; + explicit LSM6DS3(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -107,32 +107,32 @@ class LSM6DS3 : public IMUBase { void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.write(data); // Put data in Tx buffer - Wire.endTransmission(); // Send the Tx buffer + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.write(data); // Put data in Tx buffer + wire.endTransmission(); // Send the Tx buffer } uint8_t readByte(uint8_t address, uint8_t subAddress) { uint8_t data; // `data` will store the register data - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive - Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address - data = Wire.read(); // Fill Rx buffer with result + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address + data = wire.read(); // Fill Rx buffer with result return data; // Return data read from slave register } void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive uint8_t i = 0; - Wire.requestFrom(address, count); // Read bytes from slave register address - while (Wire.available()) { - dest[i++] = Wire.read(); + wire.requestFrom(address, count); // Read bytes from slave register address + while (wire.available()) { + dest[i++] = wire.read(); } // Put read results in the Rx buffer } }; diff --git a/src/F_LSM6DS3_AK8975.hpp b/src/F_LSM6DS3_AK8975.hpp index 1371c4a..4844fd1 100644 --- a/src/F_LSM6DS3_AK8975.hpp +++ b/src/F_LSM6DS3_AK8975.hpp @@ -8,7 +8,7 @@ class LSM6DS3_AK8975 : public IMUBase { public: - LSM6DS3_AK8975() {}; + explicit LSM6DS3_AK8975(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_LSM6DS3_HMC5883L.hpp b/src/F_LSM6DS3_HMC5883L.hpp index 9c61243..2057316 100644 --- a/src/F_LSM6DS3_HMC5883L.hpp +++ b/src/F_LSM6DS3_HMC5883L.hpp @@ -8,7 +8,7 @@ class LSM6DS3_HMC5883L : public IMUBase { public: - LSM6DS3_HMC5883L() {}; + explicit LSM6DS3_HMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_LSM6DS3_QMC5883L.hpp b/src/F_LSM6DS3_QMC5883L.hpp index 7ebfb48..7e00648 100644 --- a/src/F_LSM6DS3_QMC5883L.hpp +++ b/src/F_LSM6DS3_QMC5883L.hpp @@ -8,7 +8,7 @@ class LSM6DS3_QMC5883L : public IMUBase { public: - LSM6DS3_QMC5883L() {}; + explicit LSM6DS3_QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_LSM6DSL.hpp b/src/F_LSM6DSL.hpp index ad14fbd..f708a3b 100644 --- a/src/F_LSM6DSL.hpp +++ b/src/F_LSM6DSL.hpp @@ -55,7 +55,7 @@ class LSM6DSL : public IMUBase { public: - LSM6DSL() {}; + explicit LSM6DSL(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -108,32 +108,32 @@ class LSM6DSL : public IMUBase { void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.write(data); // Put data in Tx buffer - Wire.endTransmission(); // Send the Tx buffer + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.write(data); // Put data in Tx buffer + wire.endTransmission(); // Send the Tx buffer } uint8_t readByte(uint8_t address, uint8_t subAddress) { uint8_t data; // `data` will store the register data - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive - Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address - data = Wire.read(); // Fill Rx buffer with result + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address + data = wire.read(); // Fill Rx buffer with result return data; // Return data read from slave register } void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive uint8_t i = 0; - Wire.requestFrom(address, count); // Read bytes from slave register address - while (Wire.available()) { - dest[i++] = Wire.read(); + wire.requestFrom(address, count); // Read bytes from slave register address + while (wire.available()) { + dest[i++] = wire.read(); } // Put read results in the Rx buffer } }; diff --git a/src/F_LSM6DSL_AK8975.hpp b/src/F_LSM6DSL_AK8975.hpp index 94915f2..fb7cb40 100644 --- a/src/F_LSM6DSL_AK8975.hpp +++ b/src/F_LSM6DSL_AK8975.hpp @@ -8,7 +8,7 @@ class LSM6DSL_AK8975 : public IMUBase { public: - LSM6DSL_AK8975() {}; + explicit LSM6DSL_AK8975(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_LSM6DSL_HMC5883L.hpp b/src/F_LSM6DSL_HMC5883L.hpp index 556d8ee..35713b9 100644 --- a/src/F_LSM6DSL_HMC5883L.hpp +++ b/src/F_LSM6DSL_HMC5883L.hpp @@ -8,7 +8,7 @@ class LSM6DSL_HMC5883L : public IMUBase { public: - LSM6DSL_HMC5883L() {}; + explicit LSM6DSL_HMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_LSM6DSL_QMC5883L.hpp b/src/F_LSM6DSL_QMC5883L.hpp index 40f908c..bacdb3b 100644 --- a/src/F_LSM6DSL_QMC5883L.hpp +++ b/src/F_LSM6DSL_QMC5883L.hpp @@ -8,7 +8,7 @@ class LSM6DSL_QMC5883L : public IMUBase { public: - LSM6DSL_QMC5883L() {}; + explicit LSM6DSL_QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_MPU6050.hpp b/src/F_MPU6050.hpp index c62266e..998c0ae 100644 --- a/src/F_MPU6050.hpp +++ b/src/F_MPU6050.hpp @@ -70,7 +70,7 @@ class MPU6050 : public IMUBase { public: - MPU6050() {}; + explicit MPU6050(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -123,32 +123,32 @@ class MPU6050 : public IMUBase { void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.write(data); // Put data in Tx buffer - Wire.endTransmission(); // Send the Tx buffer + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.write(data); // Put data in Tx buffer + wire.endTransmission(); // Send the Tx buffer } uint8_t readByte(uint8_t address, uint8_t subAddress) { uint8_t data; // `data` will store the register data - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive - Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address - data = Wire.read(); // Fill Rx buffer with result + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address + data = wire.read(); // Fill Rx buffer with result return data; // Return data read from slave register } void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive uint8_t i = 0; - Wire.requestFrom(address, count); // Read bytes from slave register address - while (Wire.available()) { - dest[i++] = Wire.read(); + wire.requestFrom(address, count); // Read bytes from slave register address + while (wire.available()) { + dest[i++] = wire.read(); } // Put read results in the Rx buffer } diff --git a/src/F_MPU6050_AK8975.hpp b/src/F_MPU6050_AK8975.hpp index ce21d23..f560d1c 100644 --- a/src/F_MPU6050_AK8975.hpp +++ b/src/F_MPU6050_AK8975.hpp @@ -8,7 +8,7 @@ class MPU6050_AK8975 : public IMUBase { public: - MPU6050_AK8975() {}; + explicit MPU6050_AK8975(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_MPU6050_HMC5883L.hpp b/src/F_MPU6050_HMC5883L.hpp index 49b47c6..13ce176 100644 --- a/src/F_MPU6050_HMC5883L.hpp +++ b/src/F_MPU6050_HMC5883L.hpp @@ -8,7 +8,7 @@ class MPU6050_HMC5883L : public IMUBase { public: - MPU6050_HMC5883L() {}; + explicit MPU6050_HMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_MPU6050_QMC5883L.hpp b/src/F_MPU6050_QMC5883L.hpp index 811a82d..5516041 100644 --- a/src/F_MPU6050_QMC5883L.hpp +++ b/src/F_MPU6050_QMC5883L.hpp @@ -8,7 +8,7 @@ class MPU6050_QMC5883L : public IMUBase { public: - MPU6050_QMC5883L() {}; + explicit MPU6050_QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_MPU6500.hpp b/src/F_MPU6500.hpp index 7756d3c..4c3e0ed 100644 --- a/src/F_MPU6500.hpp +++ b/src/F_MPU6500.hpp @@ -140,7 +140,7 @@ class MPU6500 : public IMUBase { public: - MPU6500() {}; + explicit MPU6500(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -193,32 +193,32 @@ class MPU6500 : public IMUBase { void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.write(data); // Put data in Tx buffer - Wire.endTransmission(); // Send the Tx buffer + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.write(data); // Put data in Tx buffer + wire.endTransmission(); // Send the Tx buffer } uint8_t readByte(uint8_t address, uint8_t subAddress) { uint8_t data; // `data` will store the register data - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive - Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address - data = Wire.read(); // Fill Rx buffer with result + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address + data = wire.read(); // Fill Rx buffer with result return data; // Return data read from slave register } void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive uint8_t i = 0; - Wire.requestFrom(address, count); // Read bytes from slave register address - while (Wire.available()) { - dest[i++] = Wire.read(); + wire.requestFrom(address, count); // Read bytes from slave register address + while (wire.available()) { + dest[i++] = wire.read(); } // Put read results in the Rx buffer } diff --git a/src/F_MPU6500_AK8975.hpp b/src/F_MPU6500_AK8975.hpp index 7eec836..ee07b11 100644 --- a/src/F_MPU6500_AK8975.hpp +++ b/src/F_MPU6500_AK8975.hpp @@ -8,7 +8,7 @@ class MPU6500_AK8975 : public IMUBase { public: - MPU6500_AK8975() {}; + explicit MPU6500_AK8975(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_MPU6500_HMC5883L.hpp b/src/F_MPU6500_HMC5883L.hpp index 0f315f8..24a689b 100644 --- a/src/F_MPU6500_HMC5883L.hpp +++ b/src/F_MPU6500_HMC5883L.hpp @@ -8,7 +8,7 @@ class MPU6500_HMC5883L : public IMUBase { public: - MPU6500_HMC5883L() {}; + explicit MPU6500_HMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_MPU6500_QMC5883L.hpp b/src/F_MPU6500_QMC5883L.hpp index 7b629b3..b6641da 100644 --- a/src/F_MPU6500_QMC5883L.hpp +++ b/src/F_MPU6500_QMC5883L.hpp @@ -8,7 +8,7 @@ class MPU6500_QMC5883L : public IMUBase { public: - MPU6500_QMC5883L() {}; + explicit MPU6500_QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_MPU6515.hpp b/src/F_MPU6515.hpp index 63e5484..f01893b 100644 --- a/src/F_MPU6515.hpp +++ b/src/F_MPU6515.hpp @@ -140,7 +140,7 @@ class MPU6515 : public IMUBase { public: - MPU6515() {}; + explicit MPU6515(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -193,32 +193,32 @@ class MPU6515 : public IMUBase { void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.write(data); // Put data in Tx buffer - Wire.endTransmission(); // Send the Tx buffer + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.write(data); // Put data in Tx buffer + wire.endTransmission(); // Send the Tx buffer } uint8_t readByte(uint8_t address, uint8_t subAddress) { uint8_t data; // `data` will store the register data - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive - Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address - data = Wire.read(); // Fill Rx buffer with result + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address + data = wire.read(); // Fill Rx buffer with result return data; // Return data read from slave register } void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive uint8_t i = 0; - Wire.requestFrom(address, count); // Read bytes from slave register address - while (Wire.available()) { - dest[i++] = Wire.read(); + wire.requestFrom(address, count); // Read bytes from slave register address + while (wire.available()) { + dest[i++] = wire.read(); } // Put read results in the Rx buffer } diff --git a/src/F_MPU6515_AK8975.hpp b/src/F_MPU6515_AK8975.hpp index 88dcb8b..f17abcb 100644 --- a/src/F_MPU6515_AK8975.hpp +++ b/src/F_MPU6515_AK8975.hpp @@ -8,7 +8,7 @@ class MPU6515_AK8975 : public IMUBase { public: - MPU6515_AK8975() {}; + explicit MPU6515_AK8975(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_MPU6515_HMC5883L.hpp b/src/F_MPU6515_HMC5883L.hpp index aaad875..6102c18 100644 --- a/src/F_MPU6515_HMC5883L.hpp +++ b/src/F_MPU6515_HMC5883L.hpp @@ -8,7 +8,7 @@ class MPU6515_HMC5883L : public IMUBase { public: - MPU6515_HMC5883L() {}; + explicit MPU6515_HMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_MPU6515_QMC5883L.hpp b/src/F_MPU6515_QMC5883L.hpp index e8a68f7..d5659ee 100644 --- a/src/F_MPU6515_QMC5883L.hpp +++ b/src/F_MPU6515_QMC5883L.hpp @@ -8,7 +8,7 @@ class MPU6515_QMC5883L : public IMUBase { public: - MPU6515_QMC5883L() {}; + explicit MPU6515_QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_MPU6886.hpp b/src/F_MPU6886.hpp index 05c95d7..95d4452 100644 --- a/src/F_MPU6886.hpp +++ b/src/F_MPU6886.hpp @@ -140,7 +140,7 @@ class MPU6886 : public IMUBase { public: - MPU6886() {}; + explicit MPU6886(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -193,32 +193,32 @@ class MPU6886 : public IMUBase { void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.write(data); // Put data in Tx buffer - Wire.endTransmission(); // Send the Tx buffer + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.write(data); // Put data in Tx buffer + wire.endTransmission(); // Send the Tx buffer } uint8_t readByte(uint8_t address, uint8_t subAddress) { uint8_t data; // `data` will store the register data - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive - Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address - data = Wire.read(); // Fill Rx buffer with result + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address + data = wire.read(); // Fill Rx buffer with result return data; // Return data read from slave register } void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive uint8_t i = 0; - Wire.requestFrom(address, count); // Read bytes from slave register address - while (Wire.available()) { - dest[i++] = Wire.read(); + wire.requestFrom(address, count); // Read bytes from slave register address + while (wire.available()) { + dest[i++] = wire.read(); } // Put read results in the Rx buffer } diff --git a/src/F_MPU9250.hpp b/src/F_MPU9250.hpp index 709fa45..e485ec8 100644 --- a/src/F_MPU9250.hpp +++ b/src/F_MPU9250.hpp @@ -142,7 +142,7 @@ class MPU9250 : public IMUBase { public: - MPU9250() {}; + explicit MPU9250(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -202,32 +202,32 @@ class MPU9250 : public IMUBase { void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.write(data); // Put data in Tx buffer - Wire.endTransmission(); // Send the Tx buffer + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.write(data); // Put data in Tx buffer + wire.endTransmission(); // Send the Tx buffer } uint8_t readByte(uint8_t address, uint8_t subAddress) { uint8_t data; // `data` will store the register data - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive - Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address - data = Wire.read(); // Fill Rx buffer with result + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address + data = wire.read(); // Fill Rx buffer with result return data; // Return data read from slave register } void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive uint8_t i = 0; - Wire.requestFrom(address, count); // Read bytes from slave register address - while (Wire.available()) { - dest[i++] = Wire.read(); + wire.requestFrom(address, count); // Read bytes from slave register address + while (wire.available()) { + dest[i++] = wire.read(); } // Put read results in the Rx buffer } diff --git a/src/F_MPU9255.hpp b/src/F_MPU9255.hpp index 9701bb9..85f31bd 100644 --- a/src/F_MPU9255.hpp +++ b/src/F_MPU9255.hpp @@ -142,7 +142,7 @@ class MPU9255 : public IMUBase { public: - MPU9255() {}; + explicit MPU9255(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -202,32 +202,32 @@ class MPU9255 : public IMUBase { void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.write(data); // Put data in Tx buffer - Wire.endTransmission(); // Send the Tx buffer + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.write(data); // Put data in Tx buffer + wire.endTransmission(); // Send the Tx buffer } uint8_t readByte(uint8_t address, uint8_t subAddress) { uint8_t data; // `data` will store the register data - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive - Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address - data = Wire.read(); // Fill Rx buffer with result + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address + data = wire.read(); // Fill Rx buffer with result return data; // Return data read from slave register } void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive uint8_t i = 0; - Wire.requestFrom(address, count); // Read bytes from slave register address - while (Wire.available()) { - dest[i++] = Wire.read(); + wire.requestFrom(address, count); // Read bytes from slave register address + while (wire.available()) { + dest[i++] = wire.read(); } // Put read results in the Rx buffer } diff --git a/src/F_QMC5883L.hpp b/src/F_QMC5883L.hpp index 528d818..7a5beed 100644 --- a/src/F_QMC5883L.hpp +++ b/src/F_QMC5883L.hpp @@ -28,7 +28,7 @@ class QMC5883L : public IMUBase { public: - QMC5883L() {}; + explicit QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -81,32 +81,32 @@ class QMC5883L : public IMUBase { void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.write(data); // Put data in Tx buffer - Wire.endTransmission(); // Send the Tx buffer + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.write(data); // Put data in Tx buffer + wire.endTransmission(); // Send the Tx buffer } uint8_t readByte(uint8_t address, uint8_t subAddress) { uint8_t data; // `data` will store the register data - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive - Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address - data = Wire.read(); // Fill Rx buffer with result + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address + data = wire.read(); // Fill Rx buffer with result return data; // Return data read from slave register } void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive uint8_t i = 0; - Wire.requestFrom(address, count); // Read bytes from slave register address - while (Wire.available()) { - dest[i++] = Wire.read(); + wire.requestFrom(address, count); // Read bytes from slave register address + while (wire.available()) { + dest[i++] = wire.read(); } // Put read results in the Rx buffer } }; diff --git a/src/F_QMI8658.hpp b/src/F_QMI8658.hpp index aa1c768..5c917de 100644 --- a/src/F_QMI8658.hpp +++ b/src/F_QMI8658.hpp @@ -59,7 +59,7 @@ class QMI8658 : public IMUBase { public: - QMI8658() {}; + explicit QMI8658(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -114,32 +114,32 @@ class QMI8658 : public IMUBase { void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.write(data); // Put data in Tx buffer - Wire.endTransmission(); // Send the Tx buffer + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.write(data); // Put data in Tx buffer + wire.endTransmission(); // Send the Tx buffer } uint8_t readByte(uint8_t address, uint8_t subAddress) { uint8_t data; // `data` will store the register data - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive - Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address - data = Wire.read(); // Fill Rx buffer with result + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address + data = wire.read(); // Fill Rx buffer with result return data; // Return data read from slave register } void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest) { - Wire.beginTransmission(address); // Initialize the Tx buffer - Wire.write(subAddress); // Put slave register address in Tx buffer - Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive + wire.beginTransmission(address); // Initialize the Tx buffer + wire.write(subAddress); // Put slave register address in Tx buffer + wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive uint8_t i = 0; - Wire.requestFrom(address, count); // Read bytes from slave register address - while (Wire.available()) { - dest[i++] = Wire.read(); + wire.requestFrom(address, count); // Read bytes from slave register address + while (wire.available()) { + dest[i++] = wire.read(); } // Put read results in the Rx buffer } }; diff --git a/src/F_QMI8658_AK09918.hpp b/src/F_QMI8658_AK09918.hpp index a4c7ed0..38ae393 100644 --- a/src/F_QMI8658_AK09918.hpp +++ b/src/F_QMI8658_AK09918.hpp @@ -8,7 +8,7 @@ class QMI8658_AK09918 : public IMUBase { public: - QMI8658_AK09918() {}; + explicit QMI8658_AK09918(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_QMI8658_AK8975.hpp b/src/F_QMI8658_AK8975.hpp index 7ba084a..7f12f70 100644 --- a/src/F_QMI8658_AK8975.hpp +++ b/src/F_QMI8658_AK8975.hpp @@ -8,7 +8,7 @@ class QMI8658_AK8975 : public IMUBase { public: - QMI8658_AK8975() {}; + explicit QMI8658_AK8975(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_QMI8658_HMC5883L.hpp b/src/F_QMI8658_HMC5883L.hpp index 9e253ef..705b460 100644 --- a/src/F_QMI8658_HMC5883L.hpp +++ b/src/F_QMI8658_HMC5883L.hpp @@ -8,7 +8,7 @@ class QMI8658_HMC5883L : public IMUBase { public: - QMI8658_HMC5883L() {}; + explicit QMI8658_HMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_QMI8658_QMC5883L.hpp b/src/F_QMI8658_QMC5883L.hpp index b202020..e1cac47 100644 --- a/src/F_QMI8658_QMC5883L.hpp +++ b/src/F_QMI8658_QMC5883L.hpp @@ -8,7 +8,7 @@ class QMI8658_QMC5883L : public IMUBase { public: - QMI8658_QMC5883L() {}; + explicit QMI8658_QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/IMUBase.hpp b/src/IMUBase.hpp index 26089ea..aa1e76a 100644 --- a/src/IMUBase.hpp +++ b/src/IMUBase.hpp @@ -76,6 +76,10 @@ class IMUBase { virtual String IMUManufacturer(){ return "Unknown"; } + +protected: + IMUBase(TwoWire& wire) : wire(wire) {} + TwoWire& wire; }; #endif /* _F_IMUBase_H_ */ \ No newline at end of file From 983194055b9fbda8927bd8577d54961f5bb8e969 Mon Sep 17 00:00:00 2001 From: James Whitlock Date: Fri, 15 Nov 2024 20:37:04 +0000 Subject: [PATCH 2/3] Move TwoWire reference into individual drivers. --- src/F_AK09918.hpp | 3 ++- src/F_AK8963.hpp | 3 ++- src/F_AK8975.hpp | 3 ++- src/F_BMI055.hpp | 3 ++- src/F_BMI055_AK8975.hpp | 2 +- src/F_BMI055_HMC5883L.hpp | 2 +- src/F_BMI055_QMC5883L.hpp | 2 +- src/F_BMI160.hpp | 3 ++- src/F_BMI160_AK8975.hpp | 2 +- src/F_BMI160_HMC5883L.hpp | 2 +- src/F_BMI160_QMC5883L.hpp | 2 +- src/F_BMX055.hpp | 3 ++- src/F_HMC5883L.hpp | 4 +++- src/F_ICM20689.hpp | 3 ++- src/F_ICM20689_AK8975.hpp | 2 +- src/F_ICM20689_HMC5883L.hpp | 2 +- src/F_ICM20689_QMC5883L.hpp | 2 +- src/F_ICM20690.hpp | 3 ++- src/F_ICM20690_AK8975.hpp | 2 +- src/F_ICM20690_HMC5883L.hpp | 2 +- src/F_ICM20690_QMC5883L.hpp | 2 +- src/F_IMU_Generic.hpp | 3 ++- src/F_IMU_Generic_AK8975.hpp | 2 +- src/F_IMU_Generic_HMC5883L.hpp | 2 +- src/F_IMU_Generic_QMC5883L.hpp | 2 +- src/F_LSM6DS3.hpp | 3 ++- src/F_LSM6DS3_AK8975.hpp | 2 +- src/F_LSM6DS3_HMC5883L.hpp | 2 +- src/F_LSM6DS3_QMC5883L.hpp | 2 +- src/F_LSM6DSL.hpp | 3 ++- src/F_LSM6DSL_AK8975.hpp | 2 +- src/F_LSM6DSL_HMC5883L.hpp | 2 +- src/F_LSM6DSL_QMC5883L.hpp | 2 +- src/F_MPU6050.hpp | 3 ++- src/F_MPU6050_AK8975.hpp | 2 +- src/F_MPU6050_HMC5883L.hpp | 2 +- src/F_MPU6050_QMC5883L.hpp | 2 +- src/F_MPU6500.hpp | 3 ++- src/F_MPU6500_AK8975.hpp | 2 +- src/F_MPU6500_HMC5883L.hpp | 2 +- src/F_MPU6500_QMC5883L.hpp | 2 +- src/F_MPU6515.hpp | 3 ++- src/F_MPU6515_AK8975.hpp | 2 +- src/F_MPU6515_HMC5883L.hpp | 2 +- src/F_MPU6515_QMC5883L.hpp | 2 +- src/F_MPU6886.hpp | 3 ++- src/F_MPU9250.hpp | 3 ++- src/F_MPU9255.hpp | 3 ++- src/F_QMC5883L.hpp | 4 +++- src/F_QMI8658.hpp | 4 +++- src/F_QMI8658_AK09918.hpp | 2 +- src/F_QMI8658_AK8975.hpp | 2 +- src/F_QMI8658_HMC5883L.hpp | 2 +- src/F_QMI8658_QMC5883L.hpp | 2 +- 54 files changed, 77 insertions(+), 54 deletions(-) diff --git a/src/F_AK09918.hpp b/src/F_AK09918.hpp index cf885bd..12d63d3 100644 --- a/src/F_AK09918.hpp +++ b/src/F_AK09918.hpp @@ -58,7 +58,7 @@ enum AK09918_err_type_t { class AK09918 : public IMUBase { public: - explicit AK09918(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit AK09918(TwoWire& wire = Wire) : wire(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -109,6 +109,7 @@ class AK09918 : public IMUBase { calData calibration; uint8_t IMUAddress; + TwoWire& wire; void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { diff --git a/src/F_AK8963.hpp b/src/F_AK8963.hpp index 6ec63cc..29b156c 100644 --- a/src/F_AK8963.hpp +++ b/src/F_AK8963.hpp @@ -33,7 +33,7 @@ class AK8963 : public IMUBase { public: - explicit AK8963(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit AK8963(TwoWire& wire = Wire) : wire(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -81,6 +81,7 @@ class AK8963 : public IMUBase { calData calibration; uint8_t IMUAddress; + TwoWire& wire; void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { diff --git a/src/F_AK8975.hpp b/src/F_AK8975.hpp index f41b43a..4f382a8 100644 --- a/src/F_AK8975.hpp +++ b/src/F_AK8975.hpp @@ -33,7 +33,7 @@ class AK8975 : public IMUBase { public: - explicit AK8975(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit AK8975(TwoWire& wire = Wire) : wire(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -81,6 +81,7 @@ class AK8975 : public IMUBase { calData calibration; uint8_t IMUAddress; + TwoWire& wire; void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { diff --git a/src/F_BMI055.hpp b/src/F_BMI055.hpp index 400828d..93dfc56 100644 --- a/src/F_BMI055.hpp +++ b/src/F_BMI055.hpp @@ -41,7 +41,7 @@ class BMI055 : public IMUBase { public: - explicit BMI055(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit BMI055(TwoWire& wire = Wire) : wire(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -94,6 +94,7 @@ class BMI055 : public IMUBase { uint8_t AccelAddress; uint8_t GyroAddress; + TwoWire& wire; void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { diff --git a/src/F_BMI055_AK8975.hpp b/src/F_BMI055_AK8975.hpp index 7fbc188..e3426d0 100644 --- a/src/F_BMI055_AK8975.hpp +++ b/src/F_BMI055_AK8975.hpp @@ -8,7 +8,7 @@ class BMI055_QMC5883L : public IMUBase { public: - explicit BMI055_QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit BMI055_QMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_BMI055_HMC5883L.hpp b/src/F_BMI055_HMC5883L.hpp index 7d6075a..5dc7b6b 100644 --- a/src/F_BMI055_HMC5883L.hpp +++ b/src/F_BMI055_HMC5883L.hpp @@ -8,7 +8,7 @@ class BMI055_HMC5883L : public IMUBase { public: - explicit BMI055_HMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit BMI055_HMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_BMI055_QMC5883L.hpp b/src/F_BMI055_QMC5883L.hpp index 7fbc188..e3426d0 100644 --- a/src/F_BMI055_QMC5883L.hpp +++ b/src/F_BMI055_QMC5883L.hpp @@ -8,7 +8,7 @@ class BMI055_QMC5883L : public IMUBase { public: - explicit BMI055_QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit BMI055_QMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_BMI160.hpp b/src/F_BMI160.hpp index 4b397f1..6dc506a 100644 --- a/src/F_BMI160.hpp +++ b/src/F_BMI160.hpp @@ -103,7 +103,7 @@ class BMI160 : public IMUBase { public: - explicit BMI160(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit BMI160(TwoWire& wire = Wire) : wire(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -154,6 +154,7 @@ class BMI160 : public IMUBase { calData calibration; uint8_t IMUAddress; + TwoWire& wire; void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { diff --git a/src/F_BMI160_AK8975.hpp b/src/F_BMI160_AK8975.hpp index 65c6414..d77c362 100644 --- a/src/F_BMI160_AK8975.hpp +++ b/src/F_BMI160_AK8975.hpp @@ -8,7 +8,7 @@ class BMI160_AK8975 : public IMUBase { public: - explicit BMI160_AK8975(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit BMI160_AK8975(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_BMI160_HMC5883L.hpp b/src/F_BMI160_HMC5883L.hpp index 1e0ea2a..90149e7 100644 --- a/src/F_BMI160_HMC5883L.hpp +++ b/src/F_BMI160_HMC5883L.hpp @@ -8,7 +8,7 @@ class BMI160_HMC5883L : public IMUBase { public: - explicit BMI160_HMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit BMI160_HMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_BMI160_QMC5883L.hpp b/src/F_BMI160_QMC5883L.hpp index beece33..2354d5b 100644 --- a/src/F_BMI160_QMC5883L.hpp +++ b/src/F_BMI160_QMC5883L.hpp @@ -8,7 +8,7 @@ class BMI160_QMC5883L : public IMUBase { public: - explicit BMI160_QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit BMI160_QMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_BMX055.hpp b/src/F_BMX055.hpp index afd382f..19d5ff2 100644 --- a/src/F_BMX055.hpp +++ b/src/F_BMX055.hpp @@ -61,7 +61,7 @@ class BMX055 : public IMUBase { public: - explicit BMX055(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit BMX055(TwoWire& wire = Wire) : wire(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -118,6 +118,7 @@ class BMX055 : public IMUBase { uint8_t GyroAddress; uint8_t MagAddress; + TwoWire& wire; void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { diff --git a/src/F_HMC5883L.hpp b/src/F_HMC5883L.hpp index 4447122..23f52b1 100644 --- a/src/F_HMC5883L.hpp +++ b/src/F_HMC5883L.hpp @@ -28,7 +28,7 @@ class HMC5883L : public IMUBase { public: - explicit HMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit HMC5883L(TwoWire& wire = Wire) : wire(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -74,6 +74,8 @@ class HMC5883L : public IMUBase { calData calibration; uint8_t IMUAddress; + TwoWire& wire; + void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { wire.beginTransmission(address); // Initialize the Tx buffer diff --git a/src/F_ICM20689.hpp b/src/F_ICM20689.hpp index 0277b91..fecc011 100644 --- a/src/F_ICM20689.hpp +++ b/src/F_ICM20689.hpp @@ -84,7 +84,7 @@ class ICM20689 : public IMUBase { public: - explicit ICM20689(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit ICM20689(TwoWire& wire = Wire) : wire(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -135,6 +135,7 @@ class ICM20689 : public IMUBase { calData calibration; uint8_t IMUAddress; + TwoWire& wire; void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { diff --git a/src/F_ICM20689_AK8975.hpp b/src/F_ICM20689_AK8975.hpp index 3d51886..9984ec2 100644 --- a/src/F_ICM20689_AK8975.hpp +++ b/src/F_ICM20689_AK8975.hpp @@ -8,7 +8,7 @@ class ICM20689_AK8975 : public IMUBase { public: - explicit ICM20689_AK8975(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit ICM20689_AK8975(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_ICM20689_HMC5883L.hpp b/src/F_ICM20689_HMC5883L.hpp index 2b89d5e..8a73b84 100644 --- a/src/F_ICM20689_HMC5883L.hpp +++ b/src/F_ICM20689_HMC5883L.hpp @@ -8,7 +8,7 @@ class ICM20689_HMC5883L : public IMUBase { public: - explicit ICM20689_HMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit ICM20689_HMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_ICM20689_QMC5883L.hpp b/src/F_ICM20689_QMC5883L.hpp index e5e73d7..12698b8 100644 --- a/src/F_ICM20689_QMC5883L.hpp +++ b/src/F_ICM20689_QMC5883L.hpp @@ -8,7 +8,7 @@ class ICM20689_QMC5883L : public IMUBase { public: - explicit ICM20689_QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit ICM20689_QMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_ICM20690.hpp b/src/F_ICM20690.hpp index 333a01f..e01b9b9 100644 --- a/src/F_ICM20690.hpp +++ b/src/F_ICM20690.hpp @@ -84,7 +84,7 @@ class ICM20690 : public IMUBase { public: - explicit ICM20690(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit ICM20690(TwoWire& wire = Wire) : wire(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -134,6 +134,7 @@ class ICM20690 : public IMUBase { calData calibration; uint8_t IMUAddress; + TwoWire& wire; void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { diff --git a/src/F_ICM20690_AK8975.hpp b/src/F_ICM20690_AK8975.hpp index 466a961..5965946 100644 --- a/src/F_ICM20690_AK8975.hpp +++ b/src/F_ICM20690_AK8975.hpp @@ -8,7 +8,7 @@ class ICM20690_AK8975 : public IMUBase { public: - explicit ICM20690_AK8975(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit ICM20690_AK8975(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_ICM20690_HMC5883L.hpp b/src/F_ICM20690_HMC5883L.hpp index ac692a2..4e6412b 100644 --- a/src/F_ICM20690_HMC5883L.hpp +++ b/src/F_ICM20690_HMC5883L.hpp @@ -8,7 +8,7 @@ class ICM20690_HMC5883L : public IMUBase { public: - explicit ICM20690_HMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit ICM20690_HMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_ICM20690_QMC5883L.hpp b/src/F_ICM20690_QMC5883L.hpp index 92c3570..f96aea2 100644 --- a/src/F_ICM20690_QMC5883L.hpp +++ b/src/F_ICM20690_QMC5883L.hpp @@ -8,7 +8,7 @@ class ICM20690_QMC5883L : public IMUBase { public: - explicit ICM20690_QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit ICM20690_QMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_IMU_Generic.hpp b/src/F_IMU_Generic.hpp index 91698ac..bb7d5c4 100644 --- a/src/F_IMU_Generic.hpp +++ b/src/F_IMU_Generic.hpp @@ -161,7 +161,7 @@ class IMU_Generic : public IMUBase { public: - explicit IMU_Generic(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit IMU_Generic(TwoWire& wire = Wire) : wire(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -214,6 +214,7 @@ class IMU_Generic : public IMUBase { calData calibration; uint8_t IMUAddress; + TwoWire& wire; void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { diff --git a/src/F_IMU_Generic_AK8975.hpp b/src/F_IMU_Generic_AK8975.hpp index 03a6077..565ea5c 100644 --- a/src/F_IMU_Generic_AK8975.hpp +++ b/src/F_IMU_Generic_AK8975.hpp @@ -8,7 +8,7 @@ class IMU_Generic_AK8975 : public IMUBase { public: - explicit IMU_Generic_AK8975(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit IMU_Generic_AK8975(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_IMU_Generic_HMC5883L.hpp b/src/F_IMU_Generic_HMC5883L.hpp index c8c3410..31643a9 100644 --- a/src/F_IMU_Generic_HMC5883L.hpp +++ b/src/F_IMU_Generic_HMC5883L.hpp @@ -8,7 +8,7 @@ class IMU_Generic_HMC5883L : public IMUBase { public: - explicit IMU_Generic_HMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit IMU_Generic_HMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_IMU_Generic_QMC5883L.hpp b/src/F_IMU_Generic_QMC5883L.hpp index c12adc0..2814cc6 100644 --- a/src/F_IMU_Generic_QMC5883L.hpp +++ b/src/F_IMU_Generic_QMC5883L.hpp @@ -8,7 +8,7 @@ class IMU_Generic_QMC5883L : public IMUBase { public: - explicit IMU_Generic_QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit IMU_Generic_QMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_LSM6DS3.hpp b/src/F_LSM6DS3.hpp index c3c3f28..4a93f78 100644 --- a/src/F_LSM6DS3.hpp +++ b/src/F_LSM6DS3.hpp @@ -54,7 +54,7 @@ class LSM6DS3 : public IMUBase { public: - explicit LSM6DS3(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit LSM6DS3(TwoWire& wire = Wire) : wire(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -104,6 +104,7 @@ class LSM6DS3 : public IMUBase { calData calibration; uint8_t IMUAddress; + TwoWire& wire; void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { diff --git a/src/F_LSM6DS3_AK8975.hpp b/src/F_LSM6DS3_AK8975.hpp index 4844fd1..3cf13b6 100644 --- a/src/F_LSM6DS3_AK8975.hpp +++ b/src/F_LSM6DS3_AK8975.hpp @@ -8,7 +8,7 @@ class LSM6DS3_AK8975 : public IMUBase { public: - explicit LSM6DS3_AK8975(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit LSM6DS3_AK8975(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_LSM6DS3_HMC5883L.hpp b/src/F_LSM6DS3_HMC5883L.hpp index 2057316..5d47137 100644 --- a/src/F_LSM6DS3_HMC5883L.hpp +++ b/src/F_LSM6DS3_HMC5883L.hpp @@ -8,7 +8,7 @@ class LSM6DS3_HMC5883L : public IMUBase { public: - explicit LSM6DS3_HMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit LSM6DS3_HMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_LSM6DS3_QMC5883L.hpp b/src/F_LSM6DS3_QMC5883L.hpp index 7e00648..7c7e1d8 100644 --- a/src/F_LSM6DS3_QMC5883L.hpp +++ b/src/F_LSM6DS3_QMC5883L.hpp @@ -8,7 +8,7 @@ class LSM6DS3_QMC5883L : public IMUBase { public: - explicit LSM6DS3_QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit LSM6DS3_QMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_LSM6DSL.hpp b/src/F_LSM6DSL.hpp index f708a3b..2b52681 100644 --- a/src/F_LSM6DSL.hpp +++ b/src/F_LSM6DSL.hpp @@ -55,7 +55,7 @@ class LSM6DSL : public IMUBase { public: - explicit LSM6DSL(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit LSM6DSL(TwoWire& wire = Wire) : wire(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -105,6 +105,7 @@ class LSM6DSL : public IMUBase { calData calibration; uint8_t IMUAddress; + TwoWire& wire; void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { diff --git a/src/F_LSM6DSL_AK8975.hpp b/src/F_LSM6DSL_AK8975.hpp index fb7cb40..e6d09a2 100644 --- a/src/F_LSM6DSL_AK8975.hpp +++ b/src/F_LSM6DSL_AK8975.hpp @@ -8,7 +8,7 @@ class LSM6DSL_AK8975 : public IMUBase { public: - explicit LSM6DSL_AK8975(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit LSM6DSL_AK8975(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_LSM6DSL_HMC5883L.hpp b/src/F_LSM6DSL_HMC5883L.hpp index 35713b9..b2842a6 100644 --- a/src/F_LSM6DSL_HMC5883L.hpp +++ b/src/F_LSM6DSL_HMC5883L.hpp @@ -8,7 +8,7 @@ class LSM6DSL_HMC5883L : public IMUBase { public: - explicit LSM6DSL_HMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit LSM6DSL_HMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_LSM6DSL_QMC5883L.hpp b/src/F_LSM6DSL_QMC5883L.hpp index bacdb3b..202087d 100644 --- a/src/F_LSM6DSL_QMC5883L.hpp +++ b/src/F_LSM6DSL_QMC5883L.hpp @@ -8,7 +8,7 @@ class LSM6DSL_QMC5883L : public IMUBase { public: - explicit LSM6DSL_QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit LSM6DSL_QMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_MPU6050.hpp b/src/F_MPU6050.hpp index 998c0ae..da0e586 100644 --- a/src/F_MPU6050.hpp +++ b/src/F_MPU6050.hpp @@ -70,7 +70,7 @@ class MPU6050 : public IMUBase { public: - explicit MPU6050(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit MPU6050(TwoWire& wire = Wire) : wire(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -120,6 +120,7 @@ class MPU6050 : public IMUBase { calData calibration; uint8_t IMUAddress; + TwoWire& wire; void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { diff --git a/src/F_MPU6050_AK8975.hpp b/src/F_MPU6050_AK8975.hpp index f560d1c..8a449b0 100644 --- a/src/F_MPU6050_AK8975.hpp +++ b/src/F_MPU6050_AK8975.hpp @@ -8,7 +8,7 @@ class MPU6050_AK8975 : public IMUBase { public: - explicit MPU6050_AK8975(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit MPU6050_AK8975(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_MPU6050_HMC5883L.hpp b/src/F_MPU6050_HMC5883L.hpp index 13ce176..36a5cdd 100644 --- a/src/F_MPU6050_HMC5883L.hpp +++ b/src/F_MPU6050_HMC5883L.hpp @@ -8,7 +8,7 @@ class MPU6050_HMC5883L : public IMUBase { public: - explicit MPU6050_HMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit MPU6050_HMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_MPU6050_QMC5883L.hpp b/src/F_MPU6050_QMC5883L.hpp index 5516041..831b536 100644 --- a/src/F_MPU6050_QMC5883L.hpp +++ b/src/F_MPU6050_QMC5883L.hpp @@ -8,7 +8,7 @@ class MPU6050_QMC5883L : public IMUBase { public: - explicit MPU6050_QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit MPU6050_QMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_MPU6500.hpp b/src/F_MPU6500.hpp index 4c3e0ed..d83bfcc 100644 --- a/src/F_MPU6500.hpp +++ b/src/F_MPU6500.hpp @@ -140,7 +140,7 @@ class MPU6500 : public IMUBase { public: - explicit MPU6500(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit MPU6500(TwoWire& wire = Wire) : wire(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -190,6 +190,7 @@ class MPU6500 : public IMUBase { calData calibration; uint8_t IMUAddress; + TwoWire& wire; void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { diff --git a/src/F_MPU6500_AK8975.hpp b/src/F_MPU6500_AK8975.hpp index ee07b11..75d43a1 100644 --- a/src/F_MPU6500_AK8975.hpp +++ b/src/F_MPU6500_AK8975.hpp @@ -8,7 +8,7 @@ class MPU6500_AK8975 : public IMUBase { public: - explicit MPU6500_AK8975(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit MPU6500_AK8975(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_MPU6500_HMC5883L.hpp b/src/F_MPU6500_HMC5883L.hpp index 24a689b..27fad8b 100644 --- a/src/F_MPU6500_HMC5883L.hpp +++ b/src/F_MPU6500_HMC5883L.hpp @@ -8,7 +8,7 @@ class MPU6500_HMC5883L : public IMUBase { public: - explicit MPU6500_HMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit MPU6500_HMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_MPU6500_QMC5883L.hpp b/src/F_MPU6500_QMC5883L.hpp index b6641da..e00c287 100644 --- a/src/F_MPU6500_QMC5883L.hpp +++ b/src/F_MPU6500_QMC5883L.hpp @@ -8,7 +8,7 @@ class MPU6500_QMC5883L : public IMUBase { public: - explicit MPU6500_QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit MPU6500_QMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_MPU6515.hpp b/src/F_MPU6515.hpp index f01893b..8af263b 100644 --- a/src/F_MPU6515.hpp +++ b/src/F_MPU6515.hpp @@ -140,7 +140,7 @@ class MPU6515 : public IMUBase { public: - explicit MPU6515(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit MPU6515(TwoWire& wire = Wire) : wire(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -190,6 +190,7 @@ class MPU6515 : public IMUBase { calData calibration; uint8_t IMUAddress; + TwoWire& wire; void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { diff --git a/src/F_MPU6515_AK8975.hpp b/src/F_MPU6515_AK8975.hpp index f17abcb..9d66a66 100644 --- a/src/F_MPU6515_AK8975.hpp +++ b/src/F_MPU6515_AK8975.hpp @@ -8,7 +8,7 @@ class MPU6515_AK8975 : public IMUBase { public: - explicit MPU6515_AK8975(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit MPU6515_AK8975(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_MPU6515_HMC5883L.hpp b/src/F_MPU6515_HMC5883L.hpp index 6102c18..c72ca09 100644 --- a/src/F_MPU6515_HMC5883L.hpp +++ b/src/F_MPU6515_HMC5883L.hpp @@ -8,7 +8,7 @@ class MPU6515_HMC5883L : public IMUBase { public: - explicit MPU6515_HMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit MPU6515_HMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_MPU6515_QMC5883L.hpp b/src/F_MPU6515_QMC5883L.hpp index d5659ee..a321eff 100644 --- a/src/F_MPU6515_QMC5883L.hpp +++ b/src/F_MPU6515_QMC5883L.hpp @@ -8,7 +8,7 @@ class MPU6515_QMC5883L : public IMUBase { public: - explicit MPU6515_QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit MPU6515_QMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_MPU6886.hpp b/src/F_MPU6886.hpp index 95d4452..e950515 100644 --- a/src/F_MPU6886.hpp +++ b/src/F_MPU6886.hpp @@ -140,7 +140,7 @@ class MPU6886 : public IMUBase { public: - explicit MPU6886(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit MPU6886(TwoWire& wire = Wire) : wire(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -190,6 +190,7 @@ class MPU6886 : public IMUBase { calData calibration; uint8_t IMUAddress; + TwoWire& wire; void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { diff --git a/src/F_MPU9250.hpp b/src/F_MPU9250.hpp index e485ec8..e9c5e6b 100644 --- a/src/F_MPU9250.hpp +++ b/src/F_MPU9250.hpp @@ -142,7 +142,7 @@ class MPU9250 : public IMUBase { public: - explicit MPU9250(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit MPU9250(TwoWire& wire = Wire) : wire(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -199,6 +199,7 @@ class MPU9250 : public IMUBase { calData calibration; uint8_t IMUAddress; + TwoWire& wire; void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { diff --git a/src/F_MPU9255.hpp b/src/F_MPU9255.hpp index 85f31bd..1375480 100644 --- a/src/F_MPU9255.hpp +++ b/src/F_MPU9255.hpp @@ -142,7 +142,7 @@ class MPU9255 : public IMUBase { public: - explicit MPU9255(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit MPU9255(TwoWire& wire = Wire) : wire(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -199,6 +199,7 @@ class MPU9255 : public IMUBase { calData calibration; uint8_t IMUAddress; + TwoWire& wire; void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { diff --git a/src/F_QMC5883L.hpp b/src/F_QMC5883L.hpp index 7a5beed..0facf08 100644 --- a/src/F_QMC5883L.hpp +++ b/src/F_QMC5883L.hpp @@ -28,7 +28,7 @@ class QMC5883L : public IMUBase { public: - explicit QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit QMC5883L(TwoWire& wire = Wire) : wire(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -79,6 +79,8 @@ class QMC5883L : public IMUBase { calData calibration; uint8_t IMUAddress; + TwoWire& wire; + void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { wire.beginTransmission(address); // Initialize the Tx buffer diff --git a/src/F_QMI8658.hpp b/src/F_QMI8658.hpp index 5c917de..ea4c0b1 100644 --- a/src/F_QMI8658.hpp +++ b/src/F_QMI8658.hpp @@ -59,7 +59,7 @@ class QMI8658 : public IMUBase { public: - explicit QMI8658(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit QMI8658(TwoWire& wire = Wire) : wire(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override; @@ -110,6 +110,8 @@ class QMI8658 : public IMUBase { calData calibration; uint8_t IMUAddress; + TwoWire& wire; + bool dataAvailable(){ return (readByte(IMUAddress, QMI8658_STATUS0) & 0x03);} void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) diff --git a/src/F_QMI8658_AK09918.hpp b/src/F_QMI8658_AK09918.hpp index 38ae393..66a4544 100644 --- a/src/F_QMI8658_AK09918.hpp +++ b/src/F_QMI8658_AK09918.hpp @@ -8,7 +8,7 @@ class QMI8658_AK09918 : public IMUBase { public: - explicit QMI8658_AK09918(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit QMI8658_AK09918(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_QMI8658_AK8975.hpp b/src/F_QMI8658_AK8975.hpp index 7f12f70..36e16c6 100644 --- a/src/F_QMI8658_AK8975.hpp +++ b/src/F_QMI8658_AK8975.hpp @@ -8,7 +8,7 @@ class QMI8658_AK8975 : public IMUBase { public: - explicit QMI8658_AK8975(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit QMI8658_AK8975(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_QMI8658_HMC5883L.hpp b/src/F_QMI8658_HMC5883L.hpp index 705b460..3eac5be 100644 --- a/src/F_QMI8658_HMC5883L.hpp +++ b/src/F_QMI8658_HMC5883L.hpp @@ -8,7 +8,7 @@ class QMI8658_HMC5883L : public IMUBase { public: - explicit QMI8658_HMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit QMI8658_HMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { diff --git a/src/F_QMI8658_QMC5883L.hpp b/src/F_QMI8658_QMC5883L.hpp index e1cac47..8346cd5 100644 --- a/src/F_QMI8658_QMC5883L.hpp +++ b/src/F_QMI8658_QMC5883L.hpp @@ -8,7 +8,7 @@ class QMI8658_QMC5883L : public IMUBase { public: - explicit QMI8658_QMC5883L(TwoWire& wire = Wire) : IMUBase(wire) {}; + explicit QMI8658_QMC5883L(TwoWire& wire = Wire) : IMU(wire), MAG(wire) {}; // Inherited via IMUBase int init(calData cal, uint8_t address) override { From 09267317b985cf0e672983ddb7c547da3de91020 Mon Sep 17 00:00:00 2001 From: James Whitlock Date: Sun, 17 Nov 2024 23:13:29 +0000 Subject: [PATCH 3/3] Fix compilation --- src/IMUBase.hpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/IMUBase.hpp b/src/IMUBase.hpp index aa1e76a..26089ea 100644 --- a/src/IMUBase.hpp +++ b/src/IMUBase.hpp @@ -76,10 +76,6 @@ class IMUBase { virtual String IMUManufacturer(){ return "Unknown"; } - -protected: - IMUBase(TwoWire& wire) : wire(wire) {} - TwoWire& wire; }; #endif /* _F_IMUBase_H_ */ \ No newline at end of file