-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathholidays.c
178 lines (161 loc) · 4.4 KB
/
holidays.c
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include "holidays.h"
#include "sys.h"
#include "rtc.h"
#include "display.h"
/*
ý = \xFD
*/
bit holiday = 0;
code char hd_01_01[] = "Ñ ÍÎÂÛÌ ÃÎÄÎÌ!!!";
code char hd_01_07[] = "Ðîæäåñòâî õðèñòîâî.";
code char hd_01_14[] = "Ñòàðûé Íîâûé ãîä.";
code char hd_01_19[] = "Êðåùåíèå Ãîñïîäíå.";
code char hd_01_25[] = "Òàòüÿíèí äåíü.";
code char hd_02_14[] = "Äåíü âñåõ âëþáë¸ííûõ.";
code char hd_02_23[] = "Äåíü çàùèòíèêà Îòå÷åñòâà.";
code char hd_03_08[] = "Ìåæäóíàðîäíûé æåíñêèé äåíü.";
code char hd_03_19[] = "Äåíü ìîðÿêà-ïîäâîäíèêà.";
code char hd_04_01[] = "Äåíü ñìåõà.";
code char hd_04_12[] = "Äåíü êîñìîíàâòèêè.";
code char hd_05_01[] = "Ïðàçäíèê Âåñíû è Òðóäà.";
code char hd_05_09[] = "Äåíü ïîáåäû!!!";
code char hd_05_19[] = "Äåíü ïèîíåðèè.";
code char hd_05_28[] = "Äåíü ïîãðàíè÷íèêà.";
code char hd_06_01[] = "Äåíü çàùèòû äåòåé.";
code char hd_06_12[] = "Äåíü ÐÎÑÑÈÈ.";
code char hd_06_27[] = "Äåíü ìîëîäåæè.";
code char hd_07_08[] = "Äåíü ñåìüè, ëþáâè è âåðíîñòè.";
code char hd_08_02[] = "Äåíü Âîçäóøíî-äåñàíòíûõ âîéñê.";
code char hd_08_12[] = "Äåíü Âîåííî-âîçäóøíûõ ñèë.";
code char hd_09_01[] = "Äåíü çíàíèé.";
code char hd_09_09[] = "Äåíü òåñòèðîâùèêà.";
code char hd_10_05[] = "Äåíü ó÷èòåëÿ.";
code char hd_11_18[] = "Äåíü ðîæäåíèÿ Äåäà Ìîðîçà.";
code char hd_12_22[] = "Äåíü \xFDíåðãåòèêà.";
code char hd_256_day[] = "Äåíü ïðîãðàììèñòà.";
code char hd_06_medicalday[] = "Äåíü ìåäèöèíñêîãî ðàáîòíèêà.";
code char hd_07_lastfriday[] = "Äåíü ñèñòåìíîãî àäìèíèñòðàòîðà.";
code char hd_07_lastsunday[] = "Äåíü Âîåííî-Ìîðñêîãî Ôëîòà.";
code char hd_08_beerday[] = "Ìåæäóíàðîäíûé äåíü ïèâà.";
code char hd_08_builderday[] = "Äåíü ñòðîèòåëÿ.";
code char hd_09_tankmanday[] = "Äåíü òàíêèñòà.";
code char hd_10_lastsunday[] = "Äåíü àâòîìîáèëèñòà.";
code char hd_11_lastsunday[] = "Äåíü ìàòåðè.";
HOLIDAY code holidays[] = {
hAN( 1, 1, hd_01_01 ),
hAN( 1, 7, hd_01_07 ),
hAN( 1, 14, hd_01_14 ),
hAN( 1, 19, hd_01_19 ),
hAN( 1, 25, hd_01_25 ),
hAN( 2, 14, hd_02_14 ),
hAN( 2, 23, hd_02_23 ),
hAN( 3, 8, hd_03_08 ),
hAN( 3, 19, hd_03_19 ),
hAN( 4, 1, hd_04_01 ),
hAN( 4, 12, hd_04_12 ),
hAN( 5, 1, hd_05_01 ),
hAN( 5, 9, hd_05_09 ),
hAN( 5, 19, hd_05_19 ),
hAN( 5, 28, hd_05_28 ),
hAN( 6, 1, hd_06_01 ),
hAN( 6, 12, hd_06_12 ),
hAN( 6, 27, hd_06_27 ),
hAN( 7, 8, hd_07_08 ),
hAN( 8, 2, hd_08_02 ),
hAN( 8, 12, hd_08_12 ),
hAN( 9, 1, hd_09_01 ),
hAN( 9, 9, hd_09_09 ),
hAN( 10, 5, hd_10_05 ),
hAN( 11, 18, hd_11_18 ),
hAN( 12, 22, hd_12_22 ),
hADN( 256, hd_256_day ),
hAWN( 6, W3, SUN, hd_06_medicalday ),
hAWL( 7, FRY, hd_07_lastfriday ),
hAWL( 7, SUN, hd_07_lastsunday ),
hAWN( 8, W1, FRY, hd_08_beerday ),
hAWN( 8, W2, SUN, hd_08_builderday ),
hAWN( 9, W2, SUN, hd_09_tankmanday ),
hAWL( 10, SUN, hd_10_lastsunday ),
hAWL( 11, SUN, hd_11_lastsunday ),
};
uint8_t wdays[5];
void checkWeekDays(void)
{
uint8_t i, t;
int8_t w = rtc.wday;
for( i = 0; i < 5; i++ ) {
wdays[i] = 0;
}
w = rtc.date;
while( w > 7 ) {
w -=7;
}
t = rtcDaysInMonth();
for( i = 0; (( i < 5 ) && ( w <= t )); i++, w+=7 ) {
wdays[i] = w;
}
return;
}
bit checkLastWeek(void)
{
if( wdays[W5] == 0 ) {
if( wdays[W4] == rtc.date )
return 1;
}
else {
if( wdays[W5] == rtc.date )
return 1;
}
return 0;
}
bit checkWeekDay(uint8_t weekly)
{
return wdays[weekly] == rtc.date;
}
void checkHolidays(void)
{
uint8_t i;
holiday = 0;
checkWeekDays();
for(i=0; (i < ELEMENTS(holidays)) && (holiday == 0); i++) {
switch(( holidays[i].month & 0xF0) >> 4) {
case 0: {
if((holidays[i].day == rtc.date) && ((holidays[i].month & 0x0F) == rtc.month)) {
holiday = 1;
setRenderString(holidays[i].length, holidays[i].ptr);
break;
}
break;
}
case 1:
case 2:
case 3:
case 4:
case 5: {
if(((holidays[i].month & 0x0F) == rtc.month)&&(rtc.wday == holidays[i].day)&&checkWeekDay((( holidays[i].month & 0x70) >> 4)-1)) {
holiday = 1;
setRenderString(holidays[i].length, holidays[i].ptr);
}
break;
}
case 6: {
if(rtcYearDay()==((((uint16_t)holidays[i].month & 0x01) << 8) | holidays[i].day)) {
holiday = 1;
setRenderString(holidays[i].length, holidays[i].ptr);
}
break;
}
case 7: {
if(((holidays[i].month & 0x0F) == rtc.month)&&(rtc.wday == holidays[i].day)&&checkLastWeek()) {
holiday = 1;
setRenderString(holidays[i].length, holidays[i].ptr);
}
break;
}
default: {
holiday = 0;
}
}
}
return;
}