@@ -486,7 +486,6 @@ int16_t DallasTemperature::calculateTemperature(const uint8_t* deviceAddress, ui
486486 return fpTemperature;
487487}
488488
489-
490489// returns temperature in 1/128 degrees C or DEVICE_DISCONNECTED_RAW if the
491490// device's scratch pad cannot be read successfully.
492491// the numeric value of DEVICE_DISCONNECTED_RAW is defined in
@@ -846,3 +845,85 @@ void DallasTemperature::operator delete(void* p){
846845}
847846
848847#endif
848+
849+
850+ // SINGLE-DROP STUFF
851+
852+ bool DallasTemperature::singleReadScratchPad (uint8_t * scratchPad){
853+
854+ // send the reset command and fail fast
855+ int b = _wire->reset ();
856+ if (b == 0 ) return false ;
857+
858+ // _wire->select(deviceAddress);
859+ _wire->skip ();
860+ _wire->write (READSCRATCH );
861+
862+ // Read all registers in a simple loop
863+ // byte 0: temperature LSB
864+ // byte 1: temperature MSB
865+ // byte 2: high alarm temp
866+ // byte 3: low alarm temp
867+ // byte 4: DS18S20: store for crc
868+ // DS18B20 & DS1822: configuration register
869+ // byte 5: internal use & crc
870+ // byte 6: DS18S20: COUNT_REMAIN
871+ // DS18B20 & DS1822: store for crc
872+ // byte 7: DS18S20: COUNT_PER_C
873+ // DS18B20 & DS1822: store for crc
874+ // byte 8: SCRATCHPAD_CRC
875+ for (uint8_t i = 0 ; i < 9 ; i++){
876+ scratchPad[i] = _wire->read ();
877+ }
878+
879+ b = _wire->reset ();
880+ return (b == 1 );
881+ }
882+
883+ bool DallasTemperature::singleConnected (uint8_t * scratchPad)
884+ {
885+ bool b = singleReadScratchPad (scratchPad);
886+ return b && (_wire->crc8 (scratchPad, 8 ) == scratchPad[SCRATCHPAD_CRC ]);
887+ }
888+
889+ // reads scratchpad and returns fixed-point temperature, scaling factor 2^-7
890+ int16_t DallasTemperature::singleCalculateTemperature (uint8_t * scratchPad){
891+
892+ int16_t fpTemperature =
893+ (((int16_t ) scratchPad[TEMP_MSB ]) << 11 ) |
894+ (((int16_t ) scratchPad[TEMP_LSB ]) << 3 );
895+
896+ // NO SUPPORT FOR DS1820 and DS18S20 ("DS18SMODEL")
897+
898+ return fpTemperature;
899+ }
900+
901+ // returns temperature in 1/128 degrees C or DEVICE_DISCONNECTED_RAW if the
902+ // device's scratch pad cannot be read successfully.
903+ // the numeric value of DEVICE_DISCONNECTED_RAW is defined in
904+ // DallasTemperature.h. It is a large negative number outside the
905+ // operating range of the device
906+ int16_t DallasTemperature::singleGetTemp (void ){
907+
908+ ScratchPad scratchPad;
909+ if (singleConnected (scratchPad)) return singleCalculateTemperature (scratchPad);
910+ return DEVICE_DISCONNECTED_RAW ;
911+ }
912+
913+ // returns temperature in degrees C or DEVICE_DISCONNECTED_C if the
914+ // device's scratch pad cannot be read successfully.
915+ // the numeric value of DEVICE_DISCONNECTED_C is defined in
916+ // DallasTemperature.h. It is a large negative number outside the
917+ // operating range of the device
918+ float DallasTemperature::singleGetTempC (void ){
919+ return rawToCelsius (singleGetTemp ());
920+ }
921+
922+ // returns temperature in degrees F or DEVICE_DISCONNECTED_F if the
923+ // device's scratch pad cannot be read successfully.
924+ // the numeric value of DEVICE_DISCONNECTED_F is defined in
925+ // DallasTemperature.h. It is a large negative number outside the
926+ // operating range of the device
927+ float DallasTemperature::singleGetTempF (void ){
928+ return rawToFahrenheit (singleGetTemp ());
929+ }
0 commit comments