This commit is contained in:
norbert-walter 2022-04-01 18:56:33 +02:00
parent 40b7daad16
commit 22fc368dd2
4 changed files with 4 additions and 40 deletions

View File

@ -237,8 +237,6 @@ SensorData calcSunsetSunrise(double time, double date, double latitude, double l
// Calculate local time // Calculate local time
time_t t = (date * secPerYear) + (time + int(timezone * secPerHour)); time_t t = (date * secPerYear) + (time + int(timezone * secPerHour));
// api->getLogger()->logDebug(GwLog::DEBUG,"... PageClock: Lat %f, Lon %f, at: %d, next SR: %d (%s), next SS: %d (%s)", latitude, longitude, t, sunR, sSunR, sunS, sSunS);
if (!isnan(time) && !isnan(date) && !isnan(latitude) && !isnan(longitude) && !isnan(timezone)) { if (!isnan(time) && !isnan(date) && !isnan(latitude) && !isnan(longitude) && !isnan(timezone)) {
sr.calculate(latitude, longitude, t); // LAT, LON, EPOCH sr.calculate(latitude, longitude, t); // LAT, LON, EPOCH
// Sunrise // Sunrise
@ -259,42 +257,8 @@ SensorData calcSunsetSunrise(double time, double date, double latitude, double l
returnset.sunsetMinute = intminSS; returnset.sunsetMinute = intminSS;
returnset.sunriseHour = inthrSR; returnset.sunriseHour = inthrSR;
returnset.sunriseMinute = intminSR; returnset.sunriseMinute = intminSR;
returnset.sunControl = false;
// api->getLogger()->logDebug(GwLog::DEBUG,"... PageClock: at t: %d, hasRise: %d, next SR: %d '%s', hasSet: %d, next SS: %d '%s'\n", t, sr.hasRise, sr.riseTime, sSunR, sr.hasSet, sr.setTime, sSunS);
return returnset; 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 #endif

View File

@ -43,6 +43,5 @@ void displayTrendLow(int16_t x, int16_t y, uint16_t size, uint16_t color);
void displayHeader(CommonData &commonData, GwApi::BoatValue *date, GwApi::BoatValue *time); // Draw display header void displayHeader(CommonData &commonData, GwApi::BoatValue *date, GwApi::BoatValue *time); // Draw display header
SensorData calcSunsetSunrise(double time, double date, double latitude, double longitude, double timezone); // Calulate sunset and sunrise SensorData calcSunsetSunrise(double time, double date, double latitude, double longitude, double timezone); // Calulate sunset and sunrise
bool sunControl(double time, double date, double latitude, double longitude, double timezone); // Control bit for sun
#endif #endif

View File

@ -47,6 +47,7 @@ typedef struct{
int sunsetMinute = 0; int sunsetMinute = 0;
int sunriseHour = 0; int sunriseHour = 0;
int sunriseMinute = 0; int sunriseMinute = 0;
bool sunControl = false; // (sun on sky = false, sun down = true)
} SensorData; } SensorData;
typedef struct{ typedef struct{

View File

@ -394,7 +394,7 @@ void OBP60Task(GwApi *api){
// Back light with sun control // Back light with sun control
if(String(backlight) == "Control by Sun"){ if(String(backlight) == "Control by Sun"){
if(time->valid == true && date->valid == true && lat->valid == true && lon->valid == true){ if(time->valid == true && date->valid == true && lat->valid == true && lon->valid == true){
setPortPin(OBP_BACKLIGHT_LED, sunControl(time->value, date->value, lat->value, lon->value, tz.toDouble())); setPortPin(OBP_BACKLIGHT_LED, commonData.data.sunControl);
} }
} }
@ -456,7 +456,7 @@ void OBP60Task(GwApi *api){
// Backlight with sun control // Backlight with sun control
if(String(backlight) == "Control by Sun"){ if(String(backlight) == "Control by Sun"){
if(time->valid == true && date->valid == true && lat->valid == true && lon->valid == true){ if(time->valid == true && date->valid == true && lat->valid == true && lon->valid == true){
setPortPin(OBP_BACKLIGHT_LED, sunControl(time->value, date->value, lat->value, lon->value, tz.toDouble())); setPortPin(OBP_BACKLIGHT_LED, commonData.data.sunControl);
} }
} }
} }