mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-15 06:53:07 +01:00
Backup
This commit is contained in:
@@ -264,4 +264,37 @@ SensorData calcSunsetSunrise(double time, double date, double latitude, double l
|
||||
return returnset;
|
||||
}
|
||||
|
||||
// Sun control (return valu by sun on sky = false, sun down = true)
|
||||
bool sunControl(double time, double date, double latitude, double longitude, double timezone){
|
||||
SunRise sr;
|
||||
int secPerHour = 3600;
|
||||
int secPerYear = 86400;
|
||||
sr.hasRise = false;
|
||||
sr.hasSet = false;
|
||||
time_t sunR = 0;
|
||||
time_t sunS = 0;
|
||||
|
||||
// Calculate local time
|
||||
time_t t = (date * secPerYear) + (time + int(timezone * secPerHour));
|
||||
|
||||
if (!isnan(time) && !isnan(date) && !isnan(latitude) && !isnan(longitude) && !isnan(timezone)) {
|
||||
sr.calculate(latitude, longitude, t); // LAT, LON, EPOCH
|
||||
// Sunrise
|
||||
if (sr.hasRise) {
|
||||
sunR = (sr.riseTime + int(timezone * secPerHour) + 30); // add 30 seconds: round to minutes
|
||||
}
|
||||
// Sunset
|
||||
if (sr.hasSet) {
|
||||
sunS = (sr.setTime + int(timezone * secPerHour) + 30); // add 30 seconds: round to minutes
|
||||
}
|
||||
}
|
||||
// Return values (sun on sky = false, sun down = true)
|
||||
if(t > sunR && t < sunS){
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user