From 40b7daad16cad753ecb45a0cf9560143a815a1a9 Mon Sep 17 00:00:00 2001 From: norbert-walter Date: Fri, 1 Apr 2022 18:41:58 +0200 Subject: [PATCH] Backup --- lib/obp60task/OBP60Extensions.cpp | 33 +++++++++++++++++++++++++++++++ lib/obp60task/OBP60Extensions.h | 1 + lib/obp60task/obp60task.cpp | 15 +++++++++++++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/lib/obp60task/OBP60Extensions.cpp b/lib/obp60task/OBP60Extensions.cpp index dff6ef5..c33a6d5 100644 --- a/lib/obp60task/OBP60Extensions.cpp +++ b/lib/obp60task/OBP60Extensions.cpp @@ -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 \ No newline at end of file diff --git a/lib/obp60task/OBP60Extensions.h b/lib/obp60task/OBP60Extensions.h index c6a30b6..525ca28 100644 --- a/lib/obp60task/OBP60Extensions.h +++ b/lib/obp60task/OBP60Extensions.h @@ -43,5 +43,6 @@ 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 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 \ No newline at end of file diff --git a/lib/obp60task/obp60task.cpp b/lib/obp60task/obp60task.cpp index ca31fa9..4352f09 100644 --- a/lib/obp60task/obp60task.cpp +++ b/lib/obp60task/obp60task.cpp @@ -391,6 +391,13 @@ void OBP60Task(GwApi *api){ setPortPin(OBP_FLASH_LED, true); } + // Back light with sun control + if(String(backlight) == "Control by Sun"){ + 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())); + } + } + // Check the keyboard message int keyboardMessage=0; while (xQueueReceive(allParameters.queue,&keyboardMessage,0)){ @@ -441,11 +448,17 @@ void OBP60Task(GwApi *api){ LOG_DEBUG(GwLog::LOG,"set pagenumber to %d",pageNumber); } - // Calculate sunrise and sunset all 1s + // Calculate sunrise, sunset and backlight control with sun status all 1s if(millis() > starttime5 + 1000){ starttime5 = millis(); if(time->valid == true && date->valid == true && lat->valid == true && lon->valid == true){ commonData.data = calcSunsetSunrise(time->value , date->value, lat->value, lon->value, tz.toDouble()); + // Backlight with sun control + if(String(backlight) == "Control by Sun"){ + 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())); + } + } } }