muwerk mupplet Core Library
muwerk applets; mupplets: functional units that support specific hardware or reusable applications
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
ustd::Astro Class Reference

mupplet helper for some astronomical calculations: sunrise and sunset More...

#include <mup_astro.h>

Public Member Functions

 Astro (double lat, double lon, double utcOffset)
 

Static Public Member Functions

static long julianDayNumber (int year, uint8_t month, uint8_t day)
 
static double fracDay (uint8_t hour, uint8_t min, double sec)
 
static double julianDate (int year, uint8_t month, uint8_t day, uint8_t hour, uint8_t min, double sec)
 
static double modifiedJulianDate (int year, uint8_t month, uint8_t day, uint8_t hour, uint8_t min, double sec)
 
static bool calculateSunRiseSet (int year, int month, int day, double lat, double lon, int localOffset, int daylightSavings, bool bRising, double *pSunTime)
 
static int cmpHourMinuteTime (uint8_t h1, uint8_t m1, uint8_t h2, uint8_t m2)
 
static int deltaHourMinuteTime (uint8_t h1, uint8_t m1, uint8_t h2, uint8_t m2)
 
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)
 

Detailed Description

mupplet helper for some astronomical calculations: sunrise and sunset

Warning: WIP!

Constructor & Destructor Documentation

◆ Astro()

ustd::Astro::Astro ( double  lat,
double  lon,
double  utcOffset 
)
inline

Instantiate an Astro object

Parameters
latlattitude in degree
lonlongitude in degree
utcOffsetUTC time offset in seconds

Member Function Documentation

◆ calculateSunRiseSet()

static bool ustd::Astro::calculateSunRiseSet ( int  year,
int  month,
int  day,
double  lat,
double  lon,
int  localOffset,
int  daylightSavings,
bool  bRising,
double *  pSunTime 
)
inlinestatic

Source: http://edwilliams.org/sunrise_sunset_algorithm.htm

    localOffset will be <0 for western hemisphere and >0 for eastern hemisphere
    daylightSavings should be 1 if it is in effect during the summer otherwise it should be 0

    Warning: WIP! Isn't integrated with class functions yet...

◆ cmpHourMinuteTime()

static int ustd::Astro::cmpHourMinuteTime ( uint8_t  h1,
uint8_t  m1,
uint8_t  h2,
uint8_t  m2 
)
inlinestatic

compare two hour/minute times h1:m1 and h2:m2

Parameters
h1hour 0-23 of time-1
m1minute 0-59 of time-1
h2hour of time-2
m2minute of time-2
Returns
1: if h2:m2 is later than h1:m1, -1 if earlier, 0 if equal.

◆ deltaHourMinuteTime()

static int ustd::Astro::deltaHourMinuteTime ( uint8_t  h1,
uint8_t  m1,
uint8_t  h2,
uint8_t  m2 
)
inlinestatic

time difference between h2:m2 and h1:m1 in minutes.

Parameters
h1hour 0-23 of time-1
m1minute 0-59 of time-1
h2hour of time-2
m2minute of time-2
Returns
time difference in minutes.

◆ fracDay()

static double ustd::Astro::fracDay ( uint8_t  hour,
uint8_t  min,
double  sec 
)
inlinestatic

calculate fractional day [0.0 - 1.0[

Parameters
hour[0..23]
min[0..59]
sec[0 .. 59.999..]
Returns
fractional day [0(midnight) .. 0.9999..(23:59:59.999)]

◆ inHourMinuteInterval()

static bool ustd::Astro::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 
)
inlinestatic

test if test_hour:test_minute is in interval [start_hour:start_minute, end_hour, end_minute]

Returns
true if test_hour:test_minute is between start end end time.

◆ julianDate()

static double ustd::Astro::julianDate ( int  year,
uint8_t  month,
uint8_t  day,
uint8_t  hour,
uint8_t  min,
double  sec 
)
inlinestatic

fractional julian date

The Julian date (JD) of any instant is the Julian day number plus the fraction of a day since the preceding noon in Universal Time. Julian dates are expressed as a Julian day number (JDN) with a decimal fraction added. See: julianDayNumber().

Warning: this function exceeds the calculation precision of double on 8-bit MCUs, use modifiedJulianDate() instead.

Parameters
year4-digit year, e.g. 2021
month[1-12]
day[1-31]
hour[0-23]
min[0-59]
sec[0.0-59.99999..]
Returns
fractional julian day

◆ julianDayNumber()

static long ustd::Astro::julianDayNumber ( int  year,
uint8_t  month,
uint8_t  day 
)
inlinestatic

Calculate the julian day number

from Wikipedia: The Julian day number (JDN) is the integer assigned to a whole solar day in the Julian day count starting from noon Universal time, with Julian day number 0 assigned to the day starting at noon on Monday, January 1, 4713 BC, proleptic Julian calendar (November 24, 4714 BC, in the proleptic Gregorian calendar), a date at which three multi-year cycles started (which are: Indiction, Solar, and Lunar cycles) and which preceded any dates in recorded history. The 7,980-year Julian Period was formed by multiplying the 15-year indiction cycle, the 28-year solar cycle and the 19-year Metonic cycle. Indiction: (Y + 2) mod 15 + 1, with year AD.

see also: julianDate(), modifiedJulianDate()

Parameters
year4-digit year, e.g. 2021
month[1-12]
day[1-31]
Returns
Integer julian day number (JDN)

◆ modifiedJulianDate()

static double ustd::Astro::modifiedJulianDate ( int  year,
uint8_t  month,
uint8_t  day,
uint8_t  hour,
uint8_t  min,
double  sec 
)
inlinestatic

fractional modified julian date

calculated as julianDay()-2400000.5, avoiding exhaustion of precision of 8-bit MCUs.

from Wikipedia: The Modified Julian Date (MJD) was introduced by the Smithsonian Astrophysical Observatory in 1957 to record the orbit of Sputnik via an IBM 704 (36-bit machine) and using only 18 bits until August 7, 2576. MJD is the epoch of VAX/VMS and its successor OpenVMS, using 63-bit date/time, which allows times to be stored up to July 31, 31086, 02:48:05.47. The MJD has a starting point of midnight on November 17, 1858 and is computed by MJD = JD - 2400000.5

Warning: using julianDate() on 8-bit MCUs results in inprecise results due to exceeded precision, whereas this function has higher precision due to it's modified range.

see also: julianDayNumber() (JDN)

Parameters
year4-digit year, e.g. 2021
month[1-12]
day[1-31]
hour[0-23]
min[0-59]
sec[0.0-59.99999..]

The documentation for this class was generated from the following file: