Moving RTC time offset function to seperate function
Preparing for flexible redraw intervals, and DST
This commit is contained in:
		
							parent
							
								
									e6a8b33b37
								
							
						
					
					
						commit
						c49d17e482
					
				
					 2 changed files with 18 additions and 11 deletions
				
			
		| 
						 | 
					@ -22,7 +22,8 @@ void WatchyRTC::clearAlarm() {
 | 
				
			||||||
  rtc_pcf.setAlarm(nextAlarmMinute, 99, 99, 99);
 | 
					  rtc_pcf.setAlarm(nextAlarmMinute, 99, 99, 99);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void WatchyRTC::read(tmElements_t & tm, int offsetInSeconds) {
 | 
					void WatchyRTC::read(tmElements_t & tm, int offsetInSeconds)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
  rtc_pcf.getDate();
 | 
					  rtc_pcf.getDate();
 | 
				
			||||||
  tm.Year  = y2kYearToTm(rtc_pcf.getYear());
 | 
					  tm.Year  = y2kYearToTm(rtc_pcf.getYear());
 | 
				
			||||||
  tm.Month = rtc_pcf.getMonth();
 | 
					  tm.Month = rtc_pcf.getMonth();
 | 
				
			||||||
| 
						 | 
					@ -32,6 +33,20 @@ void WatchyRTC::read(tmElements_t & tm, int offsetInSeconds) {
 | 
				
			||||||
  tm.Minute = rtc_pcf.getMinute();
 | 
					  tm.Minute = rtc_pcf.getMinute();
 | 
				
			||||||
  tm.Second = rtc_pcf.getSecond();
 | 
					  tm.Second = rtc_pcf.getSecond();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  OffsetTime(tm, offsetInSeconds);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void WatchyRTC::set(tmElements_t tm) {
 | 
				
			||||||
 | 
					  time_t t = makeTime(tm); // make and break to calculate tm.Wday
 | 
				
			||||||
 | 
					  breakTime(t, tm);
 | 
				
			||||||
 | 
					  // day, weekday, month, century(1=1900, 0=2000), year(0-99)
 | 
				
			||||||
 | 
					  rtc_pcf.setDate(tm.Day, tm.Wday - 1, tm.Month, 0, tmYearToY2k(tm.Year));
 | 
				
			||||||
 | 
					  rtc_pcf.setTime(tm.Hour, tm.Minute, tm.Second);
 | 
				
			||||||
 | 
					  clearAlarm();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void WatchyRTC::OffsetTime(tmElements_t & tm, int offsetInSeconds)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
  int year = tm.Year;
 | 
					  int year = tm.Year;
 | 
				
			||||||
  int month = tm.Month;
 | 
					  int month = tm.Month;
 | 
				
			||||||
  int day = tm.Day;
 | 
					  int day = tm.Day;
 | 
				
			||||||
| 
						 | 
					@ -94,15 +109,6 @@ void WatchyRTC::read(tmElements_t & tm, int offsetInSeconds) {
 | 
				
			||||||
  tm.Second = second;
 | 
					  tm.Second = second;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void WatchyRTC::set(tmElements_t tm) {
 | 
					 | 
				
			||||||
  time_t t = makeTime(tm); // make and break to calculate tm.Wday
 | 
					 | 
				
			||||||
  breakTime(t, tm);
 | 
					 | 
				
			||||||
  // day, weekday, month, century(1=1900, 0=2000), year(0-99)
 | 
					 | 
				
			||||||
  rtc_pcf.setDate(tm.Day, tm.Wday - 1, tm.Month, 0, tmYearToY2k(tm.Year));
 | 
					 | 
				
			||||||
  rtc_pcf.setTime(tm.Hour, tm.Minute, tm.Second);
 | 
					 | 
				
			||||||
  clearAlarm();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void WatchyRTC::_PCFConfig(String datetime) { // String datetime is YYYY:MM:DD:HH:MM:SS
 | 
					void WatchyRTC::_PCFConfig(String datetime) { // String datetime is YYYY:MM:DD:HH:MM:SS
 | 
				
			||||||
  if (datetime != "") {
 | 
					  if (datetime != "") {
 | 
				
			||||||
    tmElements_t tm;
 | 
					    tmElements_t tm;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,9 +21,10 @@ public:
 | 
				
			||||||
  void read(tmElements_t & tm, int offsetInSeconds = 0);
 | 
					  void read(tmElements_t & tm, int offsetInSeconds = 0);
 | 
				
			||||||
  void set(tmElements_t tm);
 | 
					  void set(tmElements_t tm);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  static void OffsetTime(tmElements_t & tm, int offsetInSeconds);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
  void _PCFConfig(String datetime);
 | 
					  void _PCFConfig(String datetime);
 | 
				
			||||||
  int _getDayOfWeek(int d, int m, int y);
 | 
					 | 
				
			||||||
  String _getValue(String data, char separator, int index);
 | 
					  String _getValue(String data, char separator, int index);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue