Skip to content

Commit 5e8ee70

Browse files
Added validFamily function
This checks if a given device address belongs to the device families that the library supports. This is useful for when you have other types of 1-wire sensors in a network, and don't want to send DS18xx specific commands to those.
1 parent 2b7a7eb commit 5e8ee70

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

DallasTemperature.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ DallasTemperature::DallasTemperature(OneWire* _oneWire)
2828
setOneWire(_oneWire);
2929
}
3030

31+
bool DallasTemperature::validFamily(const uint8_t* deviceAddress){
32+
switch (deviceAddress[0]){
33+
case DS18S20MODEL:
34+
case DS18B20MODEL:
35+
case DS1822MODEL:
36+
case DS1825MODEL:
37+
return true;
38+
default:
39+
return false;
40+
}
41+
}
42+
3143
void DallasTemperature::setOneWire(OneWire* _oneWire){
3244

3345
_wire = _oneWire;

DallasTemperature.h

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ class DallasTemperature
7878
// returns true if address is valid
7979
bool validAddress(const uint8_t*);
8080

81+
// returns true if address is of the family of sensors the lib supports.
82+
bool validFamily(const uint8_t* deviceAddress);
83+
8184
// finds an address at a given index on the bus
8285
bool getAddress(uint8_t*, uint8_t);
8386

0 commit comments

Comments
 (0)