File tree Expand file tree Collapse file tree 1 file changed +3
-4
lines changed
Expand file tree Collapse file tree 1 file changed +3
-4
lines changed Original file line number Diff line number Diff line change @@ -114,10 +114,9 @@ void RTC_DS3232::writeSqwPinMode(Ds3232SqwPinMode mode) {
114114float RTC_DS3232::getTemperature () {
115115 uint8_t buffer[2 ] = {DS3232_TEMPERATUREREG, 0 };
116116 i2c_dev->write_then_read (buffer, 1 , buffer, 2 );
117- // First we convert the full 10 bits into a signed integer, then multiply by 0.25 to get
118- // a signed float of the number of degrees.
119- int16_t signedVal = ((int8_t )buffer[0 ] << 2 ) + (buffer[1 ] >> 6 );
120- return signedVal * 0.25 ;
117+ // Fix for negative temperatures https://github.com/adafruit/RTClib/pull/303
118+ int16_t temp = uint16_t (buffer[0 ]) << 8 | buffer[1 ];
119+ return temp * (1 / 256.0 );
121120}
122121
123122/* *************************************************************************/
You can’t perform that action at this time.
0 commit comments