Skip to content

Commit

Permalink
Fix for part of issue 27 - getTemperatureOffset now correctly returns…
Browse files Browse the repository at this point in the history
… negative numbers
  • Loading branch information
nseidle committed Nov 16, 2021
1 parent 7fd4d73 commit bbe3e43
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/SparkFun_SCD30_Arduino_Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,15 @@ bool SCD30::setForcedRecalibrationFactor(uint16_t concentration)
float SCD30::getTemperatureOffset(void)
{
uint16_t response = readRegister(COMMAND_SET_TEMPERATURE_OFFSET);
return (((float)response) / 100.0);

union
{
int16_t signed16;
uint16_t unsigned16;
} signedUnsigned; // Avoid any ambiguity casting int16_t to uint16_t
signedUnsigned.signed16 = response;

return (((float)signedUnsigned.signed16) / 100.0);
}

//Set the temperature offset. See 1.3.8.
Expand All @@ -163,6 +171,7 @@ bool SCD30::setTemperatureOffset(float tempOffset)
uint16_t unsigned16;
} signedUnsigned; // Avoid any ambiguity casting int16_t to uint16_t
signedUnsigned.signed16 = tempOffset * 100;

return sendCommand(COMMAND_SET_TEMPERATURE_OFFSET, signedUnsigned.unsigned16);
}

Expand Down

0 comments on commit bbe3e43

Please sign in to comment.