arduino-libraries / Arduino_BMI270_BMM150

GNU Lesser General Public License v2.1
19 stars 13 forks source link

Some Basic Code improvements #1

Open savejeff opened 1 year ago

savejeff commented 1 year ago

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:


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:

beginTransmission write endTransmission(false) <- this is important requestFrom(...) read endTransmission() <- only end transmission after interaction is done

aentinger commented 1 year ago

Hi @savejeff :coffee: :wave:

Sorry about getting back to you only at this time, but the library has escaped my notice.

Can you come up with a PR containing your proposed fixes?