in the header arduino::Stream& is used. some arduino cores do not have stream under the arduino namespace (teensy for example)
Stream is usually used directly:
void debug(Stream&);
Some functions do not return a value but should:
int BoschSensorClass::readAcceleration(float& x, float& y, float& z) {
struct bmi2_sens_data sensor_data;
bmi2_get_sensor_data(&sensor_data, &bmi2);
x = sensor_data.acc.x;
y = sensor_data.acc.y;
z = sensor_data.acc.z;
return 1;//<- this is missing
}
int BoschSensorClass::readGyroscope(float& x, float& y, float& z) {
struct bmi2_sens_data sensor_data;
bmi2_get_sensor_data(&sensor_data, &bmi2);
x = sensor_data.gyr.x;
y = sensor_data.gyr.y;
z = sensor_data.gyr.z;
return 1; //<- this is missing
}
// Magnetometer
int BoschSensorClass::readMagneticField(float& x, float& y, float& z) {
struct bmm150_mag_data mag_data;
bmm150_read_mag_data(&mag_data, &bmm1);
x = mag_data.x;
y = mag_data.y;
z = mag_data.z;
return 1;//<- this is missing
}
also:
there is no need to declare all functions virtual if no class inheritance is used
the end() and getTemperature() function are declared in the .h file but is missing in the .cpp
the same is true for interrupt_handler if mbed is not defined as it is only removed in the .cpp by ifdef but is always defined in the .h
in begin, there is no (working) check for chip id. so begin can not fail. it would be good to check the chip id reg (0x00) for value 0x24 to make sure an imu is actually connected to I2c. same goes for the mag device id
the debug print result only uses the bmi270 result codes but is also called for results of the BMM150. there should be a second print results for bmi result codes like BMM150_E_NULL_PTR, BMM150_E_DEV_NOT_FOUND etc
i2c reads should have the following structure:
beginTransmission
write
endTransmission(false) <- this is important
requestFrom(...)
read
endTransmission() <- only end transmission after interaction is done
I found some code improvements:
in the header arduino::Stream& is used. some arduino cores do not have stream under the arduino namespace (teensy for example) Stream is usually used directly:
void debug(Stream&);
Some functions do not return a value but should:
also:
beginTransmission write endTransmission(false) <- this is important requestFrom(...) read endTransmission() <- only end transmission after interaction is done