Skip to content

Commit d3b74d6

Browse files
authored
Merge pull request #100 from RobTillaart/master
issue #57 - removed defaultAlarmHandler();
2 parents 8744d4b + a79a44a commit d3b74d6

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

DallasTemperature.cpp

+19-10
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,20 @@ extern "C" {
3939
#define TEMP_11_BIT 0x5F // 11 bit
4040
#define TEMP_12_BIT 0x7F // 12 bit
4141

42-
DallasTemperature::DallasTemperature() {
43-
}
44-
DallasTemperature::DallasTemperature(OneWire* _oneWire)
42+
#define NO_ALARM_HANDLER ((AlarmHandler *)0)
4543

44+
DallasTemperature::DallasTemperature()
45+
{
4646
#if REQUIRESALARMS
47-
:
48-
_AlarmHandler(&defaultAlarmHandler)
47+
setAlarmHandler(NO_ALARM_HANDLER);
4948
#endif
49+
}
50+
DallasTemperature::DallasTemperature(OneWire* _oneWire)
5051
{
5152
setOneWire(_oneWire);
53+
#if REQUIRESALARMS
54+
setAlarmHandler(NO_ALARM_HANDLER);
55+
#endif
5256
}
5357

5458
bool DallasTemperature::validFamily(const uint8_t* deviceAddress) {
@@ -822,21 +826,24 @@ bool DallasTemperature::hasAlarm(void) {
822826
DeviceAddress deviceAddress;
823827
resetAlarmSearch();
824828
return alarmSearch(deviceAddress);
825-
826829
}
827830

828831
// runs the alarm handler for all devices returned by alarmSearch()
832+
// unless there no _AlarmHandler exist.
829833
void DallasTemperature::processAlarms(void) {
830834

835+
if (!hasAlarmHandler())
836+
{
837+
return;
838+
}
839+
831840
resetAlarmSearch();
832841
DeviceAddress alarmAddr;
833842

834843
while (alarmSearch(alarmAddr)) {
835-
836844
if (validAddress(alarmAddr)) {
837845
_AlarmHandler(alarmAddr);
838846
}
839-
840847
}
841848
}
842849

@@ -845,8 +852,10 @@ void DallasTemperature::setAlarmHandler(const AlarmHandler *handler) {
845852
_AlarmHandler = handler;
846853
}
847854

848-
// The default alarm handler
849-
void DallasTemperature::defaultAlarmHandler(const uint8_t* deviceAddress) {
855+
// checks if AlarmHandler has been set.
856+
bool DallasTemperature::hasAlarmHandler()
857+
{
858+
return _AlarmHandler != NO_ALARM_HANDLER;
850859
}
851860

852861
#endif

DallasTemperature.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef DallasTemperature_h
22
#define DallasTemperature_h
33

4-
#define DALLASTEMPLIBVERSION "3.7.8" // To be deprecated
4+
#define DALLASTEMPLIBVERSION "3.7.9" // To be deprecated
55

66
// This library is free software; you can redistribute it and/or
77
// modify it under the terms of the GNU Lesser General Public
@@ -168,8 +168,8 @@ class DallasTemperature {
168168
// sets the alarm handler
169169
void setAlarmHandler(const AlarmHandler *);
170170

171-
// The default alarm handler
172-
static void defaultAlarmHandler(const uint8_t*);
171+
// returns true if an AlarmHandler has been set
172+
bool hasAlarmHandler();
173173

174174
#endif
175175

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=DallasTemperature
2-
version=3.7.8
2+
version=3.7.9
33
author=Miles Burton <[email protected]>, Tim Newsome <[email protected]>, Guil Barros <[email protected]>, Rob Tillaart <[email protected]>
44
maintainer=Miles Burton <[email protected]>
55
sentence=Arduino Library for Dallas Temperature ICs

0 commit comments

Comments
 (0)