-
Notifications
You must be signed in to change notification settings - Fork 0
/
v_rtc.hpp
80 lines (67 loc) · 1.92 KB
/
v_rtc.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
v_rtc.hpp
---------
01.09.2019 - [email protected]
*/
#ifndef V_RTC_HPP
#define V_RTC_HPP
#include <time.h>
#include <RTClib.h>
#include <EEPROM.h>
#include "v_cmd.hpp"
#ifdef MAIN
#define CLASS
#else
#define CLASS extern
#endif
// time given by Unix cmd 1 2
// 012345678901234567890
// asci format, as "2019-08-29 22:10:42"
#define LN_LCD_LENGHT 20
CLASS char dateTimeStr[LN_LCD_LENGHT+1];
class TimeCommute
{
private:
u8 hh; // hour
u8 mm; // minute
u8 wd; // day of week (0 = all)
public:
TimeCommute()
{
hh = 22; // by default
mm = 00;
// -LMMJVSD
wd = 4; // 0 mean all days, Monday=1
}
bool chk_time();
inline void inc_hh(){hh++; if (hh>23) hh=0;} // roll down
inline void inc_mm(){mm++; if (mm>59) mm=0;}
inline void dec_hh(){hh--; if (hh>23) hh=23;} // goes to 255...
inline void dec_mm(){mm--; if (mm>59) mm=59;}
inline void inc_wd(){wd++; if (wd >7) wd=0;}
inline void dec_wd(){wd--; if (wd==255) wd=0;}
inline int get_hh(){return hh;}
inline int get_mm(){return mm;}
inline int get_wd(){return wd;}
void read_EEPROM(u16 n);
void save_EEPROM(u16 n);
void display();
};
CLASS const char *swd[] // String for day of week
#ifdef MAIN //Mon Tue Wed Thu Fri Sat Sun
= {"LMMJVSD", "L", "M", "M", "J", "V", "S", "D" };
#else
;
#endif
// 4 tables for commutation, static storage
#define NB_TABLES 6
CLASS TimeCommute timeCommute1, timeCommute2, timeCommute3, timeCommute4, timeCommute5, timeCommute6;
CLASS TimeCommute pTimeCommute[NB_TABLES] // useful in an array
#ifdef MAIN // init static array -- CAUTION: must be populed with NB_TABLES defined!!
= { timeCommute1, timeCommute2, timeCommute3, timeCommute4, timeCommute5, timeCommute6 };
#else
;
#endif
CLASS RTC_DS3231 rtc;
CLASS DateTime myTime;
#endif // V_RTC_HPP