File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -151,7 +151,15 @@ bool SCD30::setForcedRecalibrationFactor(uint16_t concentration)
151151float SCD30::getTemperatureOffset (void )
152152{
153153 uint16_t response = readRegister (COMMAND_SET_TEMPERATURE_OFFSET);
154- return (((float )response) / 100.0 );
154+
155+ union
156+ {
157+ int16_t signed16;
158+ uint16_t unsigned16;
159+ } signedUnsigned; // Avoid any ambiguity casting int16_t to uint16_t
160+ signedUnsigned.signed16 = response;
161+
162+ return (((float )signedUnsigned.signed16 ) / 100.0 );
155163}
156164
157165// Set the temperature offset. See 1.3.8.
@@ -163,6 +171,7 @@ bool SCD30::setTemperatureOffset(float tempOffset)
163171 uint16_t unsigned16;
164172 } signedUnsigned; // Avoid any ambiguity casting int16_t to uint16_t
165173 signedUnsigned.signed16 = tempOffset * 100 ;
174+
166175 return sendCommand (COMMAND_SET_TEMPERATURE_OFFSET, signedUnsigned.unsigned16 );
167176}
168177
You can’t perform that action at this time.
0 commit comments