Fixed bugs in mag. field scaling math.
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit

This commit is contained in:
Leon Teichröb 2021-09-14 12:30:46 +02:00
parent aeb289b758
commit ca79f370b0
2 changed files with 10 additions and 10 deletions

View File

@ -346,24 +346,22 @@ ReturnValue_t MGMHandlerLIS3MDL::interpretDeviceReply(DeviceCommandId_t id,
}
uint8_t MGMHandlerLIS3MDL::getFullScale(uint8_t ctrlRegister2) {
bool FS0 = false;
bool FS1 = false;
if ((ctrlRegister2 >> 5) == 1)
FS0 = true;
if ((ctrlRegister2 >> 6) == 1)
FS1 = true;
if ((FS0 == true) && (FS1 == true))
uint8_t getFullScale(uint8_t ctrlRegister2) {
bool FS0_set = ctrlRegister2 & (1 << MGMLIS3MDL::FSO); // Checks if FS0 bit is set
bool FS1_set = ctrlRegister2 & (1 << MGMLIS3MDL::FS1); // Checks if FS1 bit is set
if (FS0_set && FS1_set)
return 16;
else if ((FS0 == false) && (FS1 == true))
else if (!FS0_set && FS1_set)
return 12;
else if ((FS0 == true) && (FS1 == false))
else if (FS0_set && !FS1_set)
return 8;
else
return 4;
}
float MGMHandlerLIS3MDL::getSensitivityFactor(uint8_t scale) {
return (float) scale / (INT16_MAX);
return (float)scale / (float)MGMLIS3MDL::FIELD_LSB_PER_GAUSS;
}

View File

@ -18,7 +18,9 @@ enum opMode {
/* Actually 15, we just round up a bit */
static constexpr size_t MAX_BUFFER_SIZE = 16;
/* Field data register scaling */
static constexpr uint8_t GAUSS_TO_MICROTESLA_FACTOR = 100;
static constexpr uint16_t FIELD_LSB_PER_GAUSS = 27368;
static const DeviceCommandId_t READ_CONFIG_AND_DATA = 0x00;
static const DeviceCommandId_t SETUP_MGM = 0x01;