mirror of
https://github.com/tbnobody/OpenDTU.git
synced 2026-01-04 03:43:37 +01:00
Compute sunrise and sunset only if necessary.
Sunrise and -set must recomputed if one of the following conditions is met: * The date changed (based on the selected timezone) * Location (Lat/Lon) changed * Sunset type changed So instead of calculating that every minute just do it on update via web interface or date change. If a new config is uploaded, the DTU gets restarted. There is no need to initiate a recalculation in this case.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <sunset.h>
|
||||
|
||||
#define SUNPOS_UPDATE_INTERVAL 60000l
|
||||
@@ -15,9 +16,12 @@ public:
|
||||
bool isSunsetAvailable();
|
||||
bool sunsetTime(struct tm* info);
|
||||
bool sunriseTime(struct tm* info);
|
||||
void setDoRecalc(bool doRecalc);
|
||||
|
||||
private:
|
||||
void updateSunData();
|
||||
bool checkRecalcDayChanged();
|
||||
bool getDoRecalc();
|
||||
|
||||
SunSet _sun;
|
||||
bool _isDayPeriod = true;
|
||||
@@ -25,8 +29,10 @@ private:
|
||||
uint32_t _sunriseMinutes = 0;
|
||||
uint32_t _sunsetMinutes = 0;
|
||||
|
||||
uint32_t _lastUpdate = 0;
|
||||
bool _isValidInfo = false;
|
||||
bool _doRecalc = true;
|
||||
std::mutex _recalcLock;
|
||||
uint32_t _lastSunPositionCalculatedYMD = 0;
|
||||
};
|
||||
|
||||
extern SunPositionClass SunPosition;
|
||||
extern SunPositionClass SunPosition;
|
||||
|
||||
Reference in New Issue
Block a user