Skip to content

Commit ffc7de9

Browse files
committed
refactor: added DEVICE_INSUFFICIENT_POWER_RAW for insufficient power error
1 parent 41eaac0 commit ffc7de9

4 files changed

Lines changed: 17 additions & 5 deletions

File tree

DallasTemperature.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,11 +558,12 @@ int32_t DallasTemperature::calculateTemperature(const uint8_t* deviceAddress, ui
558558
| neg;
559559
}
560560

561-
// detect fake data
562-
if (deviceAddress[DSROM_FAMILY] == DS18B20MODEL && scratchPad[6] == 0x0C) {
563-
if ((scratchPad[0] == 0x50 && scratchPad[1] == 0x05) ||
564-
(scratchPad[0] == 0xFF && scratchPad[1] == 0x07)) {
561+
// detect POR and insufficient power conditions
562+
if (deviceAddress[DSROM_FAMILY] == DS18B20MODEL) {
563+
if (scratchPad[0] == 0x50 && scratchPad[1] == 0x05 && scratchPad[6] == 0x0C) {
565564
return DEVICE_POWER_ON_RESET_RAW;
565+
} else if (scratchPad[0] == 0xFF && scratchPad[1] == 0x07) {
566+
return DEVICE_INSUFFICIENT_POWER_RAW;
566567
}
567568
}
568569

DallasTemperature.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
#define DEVICE_POWER_ON_RESET_F -419.799988
5151
#define DEVICE_POWER_ON_RESET_RAW -32128
5252

53+
#define DEVICE_INSUFFICIENT_POWER_C -250
54+
#define DEVICE_INSUFFICIENT_POWER_F -418.0
55+
#define DEVICE_INSUFFICIENT_POWER_RAW -32000
56+
5357
// Configuration Constants
5458
#define MAX_CONVERSION_TIMEOUT 750
5559
#define MAX_INITIALIZATION_RETRIES 3

keywords.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,7 @@ DEVICE_FAULT_SHORTVDD_F LITERAL1
8787
DEVICE_FAULT_SHORTVDD_RAW LITERAL1
8888
DEVICE_POWER_ON_RESET_C LITERAL1
8989
DEVICE_POWER_ON_RESET_F LITERAL1
90-
DEVICE_POWER_ON_RESET_RAW LITERAL1
90+
DEVICE_POWER_ON_RESET_RAW LITERAL1
91+
DEVICE_INSUFFICIENT_POWER_C LITERAL1
92+
DEVICE_INSUFFICIENT_POWER_F LITERAL1
93+
DEVICE_INSUFFICIENT_POWER_RAW LITERAL1

test/unit_test_001.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ unittest(test_error_code) {
5151
assertEqual(DEVICE_POWER_ON_RESET_C, -251);
5252
assertEqualFloat(DEVICE_POWER_ON_RESET_F, -419.8, 0.1);
5353
assertEqual(DEVICE_POWER_ON_RESET_RAW, -32128);
54+
55+
assertEqual(DEVICE_INSUFFICIENT_POWER_C, -250);
56+
assertEqualFloat(DEVICE_INSUFFICIENT_POWER_F, -418.0, 0.1);
57+
assertEqual(DEVICE_INSUFFICIENT_POWER_RAW, -32000);
5458
}
5559

5660
// Test basic initialization and functionality of the DallasTemperature library

0 commit comments

Comments
 (0)