Cleaned up event handler declarations.

This commit is contained in:
stash-s 2020-11-01 16:28:05 +01:00
parent 3277e48bcf
commit c337e5128b
2 changed files with 5 additions and 20 deletions

View File

@ -22,31 +22,23 @@
#include "NTPClient.h" #include "NTPClient.h"
NTPClient::NTPClient(UDP& udp) NTPClient::NTPClient(UDP& udp)
:_updateStartHandler(NULL),
_updateEndHandler(NULL)
{ {
this->_udp = &udp; this->_udp = &udp;
} }
NTPClient::NTPClient(UDP& udp, long timeOffset) NTPClient::NTPClient(UDP& udp, long timeOffset)
:_updateStartHandler(NULL),
_updateEndHandler(NULL)
{ {
this->_udp = &udp; this->_udp = &udp;
this->_timeOffset = timeOffset; this->_timeOffset = timeOffset;
} }
NTPClient::NTPClient(UDP& udp, const char* poolServerName) NTPClient::NTPClient(UDP& udp, const char* poolServerName)
:_updateStartHandler(NULL),
_updateEndHandler(NULL)
{ {
this->_udp = &udp; this->_udp = &udp;
this->_poolServerName = poolServerName; this->_poolServerName = poolServerName;
} }
NTPClient::NTPClient(UDP& udp, IPAddress poolServerIP) NTPClient::NTPClient(UDP& udp, IPAddress poolServerIP)
:_updateStartHandler(NULL),
_updateEndHandler(NULL)
{ {
this->_udp = &udp; this->_udp = &udp;
this->_poolServerIP = poolServerIP; this->_poolServerIP = poolServerIP;
@ -54,8 +46,6 @@ NTPClient::NTPClient(UDP& udp, IPAddress poolServerIP)
} }
NTPClient::NTPClient(UDP& udp, const char* poolServerName, long timeOffset) NTPClient::NTPClient(UDP& udp, const char* poolServerName, long timeOffset)
:_updateStartHandler(NULL),
_updateEndHandler(NULL)
{ {
this->_udp = &udp; this->_udp = &udp;
this->_timeOffset = timeOffset; this->_timeOffset = timeOffset;
@ -63,8 +53,6 @@ NTPClient::NTPClient(UDP& udp, const char* poolServerName, long timeOffset)
} }
NTPClient::NTPClient(UDP& udp, IPAddress poolServerIP, long timeOffset) NTPClient::NTPClient(UDP& udp, IPAddress poolServerIP, long timeOffset)
:_updateStartHandler(NULL),
_updateEndHandler(NULL)
{ {
this->_udp = &udp; this->_udp = &udp;
this->_timeOffset = timeOffset; this->_timeOffset = timeOffset;
@ -73,8 +61,6 @@ NTPClient::NTPClient(UDP& udp, IPAddress poolServerIP, long timeOffset)
} }
NTPClient::NTPClient(UDP& udp, const char* poolServerName, long timeOffset, unsigned long updateInterval) NTPClient::NTPClient(UDP& udp, const char* poolServerName, long timeOffset, unsigned long updateInterval)
:_updateStartHandler(NULL),
_updateEndHandler(NULL)
{ {
this->_udp = &udp; this->_udp = &udp;
this->_timeOffset = timeOffset; this->_timeOffset = timeOffset;
@ -83,8 +69,6 @@ NTPClient::NTPClient(UDP& udp, const char* poolServerName, long timeOffset, unsi
} }
NTPClient::NTPClient(UDP& udp, IPAddress poolServerIP, long timeOffset, unsigned long updateInterval) NTPClient::NTPClient(UDP& udp, IPAddress poolServerIP, long timeOffset, unsigned long updateInterval)
:_updateStartHandler(NULL),
_updateEndHandler(NULL)
{ {
this->_udp = &udp; this->_udp = &udp;
this->_timeOffset = timeOffset; this->_timeOffset = timeOffset;
@ -115,8 +99,9 @@ bool NTPClient::forceUpdate() {
} }
// flush any existing packets // flush any existing packets
while(this->_udp->parsePacket() != 0) while(this->_udp->parsePacket() != 0) {
this->_udp->flush(); this->_udp->flush();
}
this->sendNTPPacket(); this->sendNTPPacket();
@ -155,7 +140,7 @@ bool NTPClient::update() {
if (!this->_udpSetup || this->_port != NTP_DEFAULT_LOCAL_PORT) this->begin(this->_port); // setup the UDP client if needed if (!this->_udpSetup || this->_port != NTP_DEFAULT_LOCAL_PORT) this->begin(this->_port); // setup the UDP client if needed
return this->forceUpdate(); return this->forceUpdate();
} }
return false; // return false if update does not occur return true; // return false if update does not occur
} }
unsigned long NTPClient::getEpochTime() const { unsigned long NTPClient::getEpochTime() const {

View File

@ -31,8 +31,8 @@ class NTPClient {
byte _packetBuffer[NTP_PACKET_SIZE]; byte _packetBuffer[NTP_PACKET_SIZE];
HandlerFunction _updateStartHandler; HandlerFunction _updateStartHandler = NULL;
HandlerFunction _updateEndHandler; HandlerFunction _updateEndHandler = NULL;
void sendNTPPacket(); void sendNTPPacket();