Last active
April 5, 2023 07:31
-
-
Save reefwing/6e0b270437ce34c3821b29d1d48c4dc3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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