Skip to content

Commit

Permalink
Add checkConnect flag to getTempC() (#19)
Browse files Browse the repository at this point in the history
- add connectCheck parameter to getTempC()
- update readme.md
- minor edits
  • Loading branch information
RobTillaart authored Jun 28, 2024
1 parent 64c606a commit 3bd72c0
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 12 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.3.3] - 2024-06-27
- add connectCheck parameter to getTempC()
- update readme.md
- minor edits

## [0.3.2] - 2024-01-03
- fix examples
- minor edits


## [0.3.1] - 2023-10-19
- update readme.md

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ There will be a number of retries to connect, default 3.
There will be a number of retries to connect, default 3.
- **void requestTemperatures()** trigger temperature conversion.
- **bool isConversionComplete()** check if conversion is complete.
- **int16_t getTempC()** returns temperature in whole degrees only. -55..125
or -127 = DEVICE_DISCONNECTED
- **int16_t getTempC(bool connectCheck = true)** returns temperature in whole degrees only.
-55..125 or -127 = DEVICE_DISCONNECTED
Is faster when connectCheck is set to false. Default true = backwards compatible.
- **bool getAddress()** returns true if the sensor is configured (available).


Expand Down
10 changes: 10 additions & 0 deletions examples/DS18B20_performance/DS18B20_performance.ino
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ void setup()
Serial.println(stop - start);
delay(10);


start = micros();
temp = sensor.getTempC(false);
stop = micros();
Serial.print("\ngetTempC(false): \t");
Serial.println(temp);
Serial.print("Time: \t");
Serial.println(stop - start);
delay(10);

}


Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"version": "^2.3.5"
}
],
"version": "0.3.2",
"version": "0.3.3",
"license": "MIT",
"frameworks": "*",
"platforms": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=DS18B20_int
version=0.3.2
version=0.3.3
author=Rob Tillaart <[email protected]>
maintainer=Rob Tillaart <[email protected]>
sentence=Library for DS18B20 restricted to a single sensor per pin.
Expand Down
11 changes: 7 additions & 4 deletions src/DS18B20_INT.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// FILE: DS18B20_INT.cpp
// AUTHOR: Rob.Tillaart
// VERSION: 0.3.2
// VERSION: 0.3.3
// DATE: 2017-07-25
// PURPOSE: library for DS18B20 temperature sensor - integer only.
// URL: https://github.com/RobTillaart/DS18B20_INT
Expand Down Expand Up @@ -72,11 +72,14 @@ bool DS18B20_INT::isConversionComplete(void)
}


int16_t DS18B20_INT::getTempC(void)
int16_t DS18B20_INT::getTempC(bool connectCheck)
{
if (isConnected(3) == false)
if (connectCheck)
{
return DEVICE_DISCONNECTED;
if (isConnected(3) == false)
{
return DEVICE_DISCONNECTED;
}
}
int16_t rawTemperature = _readRaw();
rawTemperature >>= 4;
Expand Down
6 changes: 3 additions & 3 deletions src/DS18B20_INT.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// FILE: DS18B20_INT.h
// AUTHOR: Rob.Tillaart
// VERSION: 0.3.2
// VERSION: 0.3.3
// DATE: 2017-07-25
// PURPOSE: Minimalistic library for DS18B20 temperature sensor
// uses only integer math (no float to minimize footprint)
Expand All @@ -25,7 +25,7 @@
#include "OneWire.h"


#define DS18B20_INT_LIB_VERSION (F("0.3.2"))
#define DS18B20_INT_LIB_VERSION (F("0.3.3"))

// Error Code
#define DEVICE_DISCONNECTED -127
Expand All @@ -42,7 +42,7 @@ class DS18B20_INT
bool isConnected(uint8_t retries = 3);

void requestTemperatures(void);
int16_t getTempC(void);
int16_t getTempC(bool connectCheck = true);
bool isConversionComplete(void);
bool getAddress(uint8_t* buf);

Expand Down

0 comments on commit 3bd72c0

Please sign in to comment.