-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
145 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#ifndef NTP_CLIENT_HPP_ | ||
#define NTP_CLIENT_HPP_ | ||
|
||
#include <NTPClient.h> | ||
#include <WiFiUdp.h> | ||
|
||
WiFiUDP ntpUDP; | ||
NTPClient timeClient(ntpUDP,"0.pool.ntp.org"); | ||
|
||
int alarmHours = 7; | ||
int alarmMinutes = 0; | ||
bool alarmSwitch = false; | ||
|
||
byte timer=0; | ||
|
||
void timeInit(int timeZone){ | ||
timeClient.setTimeOffset(timeZone * 3600); | ||
timeClient.begin(); | ||
} | ||
|
||
void setAlarmHours(int hours){ | ||
alarmHours = hours; | ||
alarmSwitch=true; | ||
} | ||
|
||
void setAlarmMinutes(int minutes){ | ||
alarmMinutes = minutes; | ||
alarmSwitch=true; | ||
} | ||
|
||
void setAlarm(int value){ | ||
if(value) | ||
alarmSwitch = true; | ||
else | ||
alarmSwitch = false; | ||
} | ||
|
||
int getAlarm(){ | ||
return alarmHours * 24 + alarmMinutes; | ||
} | ||
int getTime(){ | ||
return timeClient.getHours() * 24 + timeClient.getMinutes(); | ||
} | ||
|
||
int isAlarm(byte interval){ | ||
|
||
if(timer == 255){ | ||
timer = 0; | ||
if(alarmSwitch){ | ||
timeClient.update(); | ||
int alarmMin=getAlarm() - getTime(); | ||
if(abs(alarmMin)<=interval) | ||
return abs(alarmMin); | ||
else if(alarmMin == -interval) | ||
alarmSwitch = false; | ||
} | ||
} | ||
timer++; | ||
return -1; | ||
} | ||
|
||
|
||
|
||
|
||
#endif // NTP_CLIENT_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters