Skip to content

Instantly share code, notes, and snippets.

@reefwing
Last active April 5, 2023 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reefwing/6e0b270437ce34c3821b29d1d48c4dc3 to your computer and use it in GitHub Desktop.
Save reefwing/6e0b270437ce34c3821b29d1d48c4dc3 to your computer and use it in GitHub Desktop.
float ReefwingLSM9DS1::readTemp(TempScale scale) {
uint8_t OUT_TEMP_L = readByte(LSM9DS1AG_ADDRESS, LSM9DS1AG_OUT_TEMP_L);
uint8_t OUT_TEMP_H = readByte(LSM9DS1AG_ADDRESS, LSM9DS1AG_OUT_TEMP_H);
uint16_t count = (OUT_TEMP_H << 8) | (OUT_TEMP_L & 0xff);
int16_t val = (int16_t)count;
float result = ((float)val)/16.0f + _config.temp.offset; // In Celsius
switch(scale) {
case TempScale::KELVIN:
result += 273.15f;
break;
case TempScale::FAHRENHEIT:
result = result * 1.8f + 32.0f;
break;
default: // Default scale is CELSIUS
break;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment