Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions DallasTemperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,15 @@ int32_t DallasTemperature::calculateTemperature(const uint8_t* deviceAddress, ui
| neg;
}

// detect POR and insufficient power conditions
if (deviceAddress[DSROM_FAMILY] == DS18B20MODEL) {
if (scratchPad[0] == 0x50 && scratchPad[1] == 0x05 && scratchPad[6] == 0x0C) {
return DEVICE_POWER_ON_RESET_RAW;
} else if (scratchPad[0] == 0xFF && scratchPad[1] == 0x07) {
return DEVICE_INSUFFICIENT_POWER_RAW;
}
}

/*
DS1820 and DS18S20 have a 9-bit temperature register.

Expand Down
8 changes: 8 additions & 0 deletions DallasTemperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
#define DEVICE_FAULT_SHORTVDD_F -421.599976
#define DEVICE_FAULT_SHORTVDD_RAW -32256

#define DEVICE_POWER_ON_RESET_C -251
#define DEVICE_POWER_ON_RESET_F -419.799988
#define DEVICE_POWER_ON_RESET_RAW -32128

#define DEVICE_INSUFFICIENT_POWER_C -250
#define DEVICE_INSUFFICIENT_POWER_F -418.0
#define DEVICE_INSUFFICIENT_POWER_RAW -32000

// Configuration Constants
#define MAX_CONVERSION_TIMEOUT 750
#define MAX_INITIALIZATION_RETRIES 3
Expand Down
6 changes: 6 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,9 @@ DEVICE_FAULT_SHORTGND_RAW LITERAL1
DEVICE_FAULT_SHORTVDD_C LITERAL1
DEVICE_FAULT_SHORTVDD_F LITERAL1
DEVICE_FAULT_SHORTVDD_RAW LITERAL1
DEVICE_POWER_ON_RESET_C LITERAL1
DEVICE_POWER_ON_RESET_F LITERAL1
DEVICE_POWER_ON_RESET_RAW LITERAL1
DEVICE_INSUFFICIENT_POWER_C LITERAL1
DEVICE_INSUFFICIENT_POWER_F LITERAL1
DEVICE_INSUFFICIENT_POWER_RAW LITERAL1
8 changes: 8 additions & 0 deletions test/unit_test_001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ unittest(test_error_code) {
assertEqual(DEVICE_FAULT_SHORTVDD_C, -252);
assertEqualFloat(DEVICE_FAULT_SHORTVDD_F, -421.6, 0.1);
assertEqual(DEVICE_FAULT_SHORTVDD_RAW, -32256);

assertEqual(DEVICE_POWER_ON_RESET_C, -251);
assertEqualFloat(DEVICE_POWER_ON_RESET_F, -419.8, 0.1);
assertEqual(DEVICE_POWER_ON_RESET_RAW, -32128);

assertEqual(DEVICE_INSUFFICIENT_POWER_C, -250);
assertEqualFloat(DEVICE_INSUFFICIENT_POWER_F, -418.0, 0.1);
assertEqual(DEVICE_INSUFFICIENT_POWER_RAW, -32000);
}

// Test basic initialization and functionality of the DallasTemperature library
Expand Down