-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWS_CalculateTime.ino
232 lines (190 loc) · 5.96 KB
/
WS_CalculateTime.ino
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
//------------------------------------------
// Function calculate Pray Time
//------------------------------------------
/*Macro Function */
#define d2r(x) x*M_PI/180
#define r2d(x) x*180/M_PI
//Constanta
const float lunarY = 354.367068f;
// Main Function
void sholatCal()
{
float EJD = E_Julian_date(now.year(),now.month(),now.day(),Prm.L_LO);
float Decl=Dql(EJD);
float EqOfTime=EqT(EJD);
Pray_Time(Prm.L_TZ, Prm.L_LA, Prm.L_LO,Prm.L_AL,Decl, EqOfTime );
}
//Julian Date at GMT mid day
float E_Julian_date(int Year,int Month,int Days,float Longitude) // juliant date - 2451545
{
if (Month <= 2)
{
Year -= 1;
Month += 12;
}
float A = floor(((float)Year/100.0));
float B = 2 - A + floor(A/4.0);
float CLong = Longitude/(float)(15 * 24);
float JD = floor(365.25 *(float)(Year+ 4716))
- 2451545
+ floor(30.6001 * (float)(Month + 1))
+ (float)Days + B
- 1524.5
-CLong;
return JD;
}
//Sun Declination
float EqT(const float EJD)
{
float g = fix_angle(357.529f + 0.98560028f* EJD);
float q = fix_angle(280.459f + 0.98564736f* EJD);
float L = fix_angle(q + 1.915* sin(d2r(g)) + 0.020* sin(d2r(2*g)));
float e = (23.439f - 0.00000036f* EJD);
float RA = r2d(atan2(cos(d2r(e))* sin(d2r(L)), cos(d2r(L))))/ 15;
float Eq =(q/15-fix_hour(RA));
return Eq;
// Ds = r2d(asin(sin(d2r(e))* sin(d2r(L)))); // declination of the Sun
}
float Dql(float EJD)
{
float g = fix_angle((357.529f + 0.98560028f* EJD));
float q = fix_angle((280.459f + 0.98564736f* EJD));
float L = fix_angle((q + 1.915f* sin(d2r(g)) + 0.020f* sin(d2r(2*g))));
float e = (23.439f - 0.00000036f* EJD);
float dd = r2d(asin(sin(d2r(e))* sin(d2r(L)))); // declination of the Sun
return dd;
}
float HourAngle( float Alfa, float Declination, float Latitude)
{
float rn =acos(
(-sin(d2r(Alfa))-sin(d2r(Latitude))*sin(d2r(Declination)))
/
(cos(d2r(Latitude))*cos(d2r(Declination)))
)/15;
return r2d(rn);
}
void Pray_Time(float TimeZone, float Latitude, float Longitude,float Altitude,float Declination, float EquationOfTime )
{
// Dzuhur
float BaseTime = fix_hour((float)12+TimeZone-(Longitude/15)-EquationOfTime);
sholatT[4] = BaseTime + (float)Prm.IH/60 + (float)Prm.IL/60;
// Ashr
float alfa =r2d(-atan(1 / (1+tan(d2r(fabs(Latitude-Declination))))));
float HA = HourAngle(alfa,Declination,Latitude);
sholatT[5] = BaseTime + HA + (float)Prm.IH/60 + (float)Prm.IA/60;
// Maghrib
alfa = 0.8333f+0.0347f*sqrt(Altitude);
HA = HourAngle(alfa,Declination,Latitude);
sholatT[6] = BaseTime + HA + (float)Prm.IH/60 + (float)Prm.IM/60;
// Terbit
sholatT[2] = BaseTime - HA;
// Isya
HA = HourAngle((float)18,Declination,Latitude);
sholatT[7] = BaseTime + HA + (float)Prm.IH/60 + (float)Prm.II/60;
// Shubuh
HA = HourAngle((float)20,Declination,Latitude);
sholatT[1] = BaseTime - HA + (float)Prm.IH/60 + (float)Prm.IS/60;
// Imsak
sholatT[0] = sholatT[1]-(float)10/60;
// Dhuha
HA = HourAngle((float)-4.5,Declination,Latitude);
sholatT[3] = BaseTime - HA;
char buff[100];
}
float fix_hour(float a)
{
a = a - (float)24.0 * floor(a / 24.0);
a = a < 0.0 ? a + 24.0 : a;
return a;
}
float fix_angle(float a)
{
a = a - (float)360.0 * floor(a / 360.0);
a = a < 0.0 ? a + 360.0 : a;
return a;
}
//------------------------------------------
// Function calculate Hijriah Date
//------------------------------------------
long Days(uint16_t Y,uint8_t M,uint8_t D)
{
if (M < 3)
{
Y -= 1;
M +=12;
}
Y = Y - 2000;
long ndays= floor(365.25*Y)+floor(30.6001*(M + 1))+floor(Y/100)+floor(Y/400)+D+196;
//long ndays= d1 + d2 - A + B + D + 196;
return ndays;
}
long DaysHijri(uint16_t Y,uint8_t M,uint8_t D)
{
Y = Y - 1420;
long hari = floor(29.5*M - 28.999)+floor(lunarY*Y)+D ;
return hari;
}
hijir_date toHijri(uint16_t Y, uint8_t M, uint8_t D,uint8_t cor) // core --> corection date today=0 yesterday=-1 tomorrow=1
{
hijir_date BuffDate;
long nday = Days(Y, M, D)+ Prm.CH + cor;
long tahun = floor(nday/lunarY) + 1420;
long bulan = 1;
long harike = 1;
while(DaysHijri(tahun, bulan, 1) <= nday){tahun++;};
tahun--;
while(DaysHijri(tahun, bulan, 1) <= nday){bulan++;};
bulan--;
harike = 1 + nday - DaysHijri(tahun, bulan, 1);
if (bulan == 13){bulan = 12; harike += 29;};
BuffDate.hD = harike;
BuffDate.hM = bulan;
BuffDate.hY = tahun;
return BuffDate;
}
/*
hijir_date toHijri(int g_y, int g_m, int g_d,int cor )
{
hijir_date BuffDate;
int year, month, day;
int zyr;
int zd;
int zm;
int zy;
float zjd;
int zl;
int zn;
int zj;
year = g_y;
month = g_m;
day = g_d;
zyr = year;
zd = day;
zm = month;
zy = zyr;
if((zy > 1582) || ((zy == 1582) && (zm > 10)) || ((zy == 1582) && (zm == 10) && (zd > 14)))
{
zjd = ((1461 * (zy + 4800 + ((zm - 14) / 12))) / 4)
+ ((367 * (zm - 2 - 12 * (((zm - 14) / 12)))) / 12)
- ((3 * (((zy + 4900 + ((zm - 14) / 12)) / 100))) / 4) + zd - 32075;
}
else
{
zjd = 367 * zy - ((7 * (zy + 5001 + ((zm - 9) / 7))) / 4)
+ ((275 * zm) / 9) + zd + 1729777;
}
zl = zjd - 1948440 + 10632;
zn = ((zl - 1) / 10631);
zl = zl - 10631 * zn + 354;
zj = (((10985 - zl) / 5316)) * ((int)((50 * zl) / 17719))
+ ((zl / 5670)) * ((int)((43 * zl) / 15238));
zl = zl - (((30 - zj) / 15)) * (((17719 * zj) / 50))
- ((zj / 16)) * (((15238 * zj) / 43)) + 29;
zm = ((24 * zl) / 709);
zd = zl - ((709 * zm) / 24);
zy = 30 * zn + zj - 30;
BuffDate.hD = zd;
BuffDate.hM = zm;
BuffDate.hY = zy;
return BuffDate;
} */