Added NTP Update start and stop events.

This commit is contained in:
Staszek Salik 2018-10-20 12:16:28 +02:00
parent 020aaf868d
commit cf60c1d086

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <functional>
#include "Arduino.h" #include "Arduino.h"
#include <Udp.h> #include <Udp.h>
@ -9,6 +11,10 @@
#define NTP_DEFAULT_LOCAL_PORT 1337 #define NTP_DEFAULT_LOCAL_PORT 1337
class NTPClient { class NTPClient {
public:
typedef std::function<void(void)> HandlerFunction;
private: private:
UDP* _udp; UDP* _udp;
bool _udpSetup = false; bool _udpSetup = false;
@ -24,6 +30,9 @@ class NTPClient {
byte _packetBuffer[NTP_PACKET_SIZE]; byte _packetBuffer[NTP_PACKET_SIZE];
HandlerFunction _updateStartHandler;
HandlerFunction _updateEndHandler;
void sendNTPPacket(); void sendNTPPacket();
public: public:
@ -95,4 +104,24 @@ class NTPClient {
* Stops the underlying UDP client * Stops the underlying UDP client
*/ */
void end(); void end();
/**
*
*/
inline void onStartUpdate (HandlerFunction);
/**
*
*/
inline void onEndUpdate (HandlerFunction);
}; };
inline void
NTPClient::onStartUpdate (NTPClient::HandlerFunction handler) {
_updateStartHandler = handler;
}
inline void
NTPClient::onEndUpdate (NTPClient::HandlerFunction handler) {
_updateEndHandler = handler;
}