7const double C_PI = 3.1415926535897932384626433;
10const double C_AU = 149597870700.0;
11const double C_C = 299792458.0;
21 double lat, lon, utcOffset;
23#ifdef USTD_FEATURE_FILESYSTEM
28 Astro(
double lat,
double lon,
double utcOffset)
29 : lat(lat), lon(lon), utcOffset(utcOffset) {
58 long JDN = (1461L * ((long)year + 4800L + ((
long)month - 14L) / 12L)) / 4L +
59 (367L * ((
long)month - 2L - 12L * (((long)month - 14L) / 12L))) / 12L -
60 (3L * (((
long)year + 4900L + ((long)month - 14L) / 12L) / 100L)) / 4L +
65 static double fracDay(uint8_t hour, uint8_t min,
double sec) {
72 double dayFrac = ((double)hour + (
double)min / 60.0 + (double)sec / 3600.0) / 24.0;
76 static double julianDate(
int year, uint8_t month, uint8_t day, uint8_t hour, uint8_t min,
96 double dfrac =
fracDay(hour, min, sec) - 0.5;
97 double JD = (double)JDN + dfrac;
102 uint8_t min,
double sec) {
127 double dfrac =
fracDay(hour, min, sec) - 0.5;
128 double JD = (double)(JDN -
C_MJD) + dfrac;
133 int localOffset,
int daylightSavings,
bool bRising,
144 const double ZENITH = 90.0 + 50.0 / 60.0;
145 double N1 = floor(275.0 * month / 9.0);
146 double N2 = floor((month + 9.0) / 12.0);
147 double N3 = (1.0 + floor((year - 4 * floor(year / 4.0) + 2.0) / 3.0));
148 double N = N1 - (N2 * N3) + day - 30.0;
151 double lonHour = lon / 15.0;
154 t = N + ((6 - lonHour) / 24);
156 t = N + ((18 - lonHour) / 24);
159 double M = (0.9856 * t) - 3.289;
163 fmod(M + (1.916 * sin(
C_D2R * M)) + (0.020 * sin(2 *
C_D2R * M)) + 282.634, 360.0);
166 double RA = fmod(
C_R2D * atan(0.91764 * tan(
C_D2R * L)), 360.0);
169 double Lquadrant = floor(L / 90.0) * 90.0;
170 double RAquadrant = floor(RA / 90.0) * 90.0;
171 RA = RA + (Lquadrant - RAquadrant);
177 double sinDec = 0.39782 * sin(
C_D2R * L);
178 double cosDec = cos(asin(sinDec));
184 (cos(
C_D2R * ZENITH) - (sinDec * sin(lat *
C_D2R))) / (cosDec * cos(
C_D2R * lat));
201 H = 360.0 -
C_R2D * acos(cosH);
203 H =
C_R2D * acos(cosH);
207 double T = H + RA - (0.06571 * t) - 6.622;
210 double UT = fmod(T - lonHour, 24.0);
213 *pSunTime = UT + localOffset + daylightSavings;
253 return (h2 - h1) * 60 + m2 - m1;
257 uint8_t start_minute, uint8_t end_hour, uint8_t end_minute) {
278 static bool parseHourMinuteString(String hourMinute,
int *hour,
int *minute) {
279 int ind = hourMinute.indexOf(
':');
282 int hr = hourMinute.substring(0, ind).toInt();
283 int mn = hourMinute.substring(ind + 1).toInt();
284 if (hr < 0 || hr > 23)
286 if (mn < 0 || mn > 59)
mupplet helper for some astronomical calculations: sunrise and sunset
Definition: mup_astro.h:19
static double modifiedJulianDate(int year, uint8_t month, uint8_t day, uint8_t hour, uint8_t min, double sec)
Definition: mup_astro.h:101
static double fracDay(uint8_t hour, uint8_t min, double sec)
Definition: mup_astro.h:65
static int cmpHourMinuteTime(uint8_t h1, uint8_t m1, uint8_t h2, uint8_t m2)
Definition: mup_astro.h:217
static long julianDayNumber(int year, uint8_t month, uint8_t day)
Definition: mup_astro.h:38
static bool inHourMinuteInterval(uint8_t test_hour, uint8_t test_minute, uint8_t start_hour, uint8_t start_minute, uint8_t end_hour, uint8_t end_minute)
Definition: mup_astro.h:256
static double julianDate(int year, uint8_t month, uint8_t day, uint8_t hour, uint8_t min, double sec)
Definition: mup_astro.h:76
static bool calculateSunRiseSet(int year, int month, int day, double lat, double lon, int localOffset, int daylightSavings, bool bRising, double *pSunTime)
Definition: mup_astro.h:132
static int deltaHourMinuteTime(uint8_t h1, uint8_t m1, uint8_t h2, uint8_t m2)
Definition: mup_astro.h:236
Astro(double lat, double lon, double utcOffset)
Definition: mup_astro.h:28
The muwerk namespace.
Definition: home_assistant.h:10
const double C_MJD
MJD = JD - C_MJD.
Definition: mup_astro.h:13
const double C_C
speed of light, m/s
Definition: mup_astro.h:11
const double C_D2R
degree -> radians conversion
Definition: mup_astro.h:8
const double C_CAUD
AUs per day, approx 173.
Definition: mup_astro.h:12
const double C_AU
astronomical unit, meter
Definition: mup_astro.h:10
const double C_PI
PI.
Definition: mup_astro.h:7
const double C_R2D
radians -> degrees
Definition: mup_astro.h:9