Skip to content

Commit af1cce6

Browse files
committed
src/corelibs: Refactor.
Signed-off-by: IFX-Anusha <[email protected]>
1 parent 10e66cd commit af1cce6

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/corelibs/onewire/test_onewire_DS18x20.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,20 @@ TEST(onewire_DS18x20, test_data_returned) {
6969
}
7070

7171
// Verify that data was returned (non-zero values in the scratchpad)
72-
bool dataReturned = false;
72+
bool allDataNonZero = true;
7373
for (uint8_t i = 0; i < 9; i++) {
74-
if (data[i] != 0) {
75-
dataReturned = true;
74+
if (data[i] == 0) {
75+
allDataNonZero = false;
7676
break;
7777
}
78-
dataReturned = false;
7978
}
8079

81-
TEST_ASSERT_TRUE_MESSAGE(dataReturned, " - No data returned from the OneWire device");
80+
TEST_ASSERT_TRUE_MESSAGE(allDataNonZero, " - Not all data bytes are non-zero in the OneWire device scratchpad");
8281

8382
TEST_ASSERT_TRUE_MESSAGE(OneWire::crc8(data, 8) == data[8], " - CRC check failed");
8483

8584
// Decode temperature
8685
int16_t raw = (data[1] << 8) | data[0];
87-
float celsius = (float)raw / 16.0;
8886
if(addr[0] == 0x10) {
8987
raw = raw << 3; // 9 bit resolution
9088
if (data[7] == 0x10) {
@@ -98,6 +96,7 @@ TEST(onewire_DS18x20, test_data_returned) {
9896
else if (cfg == 0x40) raw = raw & ~1; // 11 bit
9997
}
10098

99+
float celsius = (float)raw / 16.0;
101100
// Assert temperature is within expected range
102101
TEST_ASSERT_TRUE_MESSAGE(
103102
celsius > -50.0 && celsius < 50.0,

0 commit comments

Comments
 (0)