From ff76620329f416d57e713b3609d699015514570e Mon Sep 17 00:00:00 2001 From: norbert-walter Date: Mon, 4 Apr 2022 17:41:55 +0200 Subject: [PATCH] Fix for sunset/sunrise --- lib/obp60task/OBP60Extensions.cpp | 6 ++---- lib/obp60task/OBP60Extensions.h | 2 +- lib/obp60task/PageClock.cpp | 4 ++-- lib/obp60task/Pagedata.h | 9 +++++++++ lib/obp60task/obp60task.cpp | 5 +++-- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/obp60task/OBP60Extensions.cpp b/lib/obp60task/OBP60Extensions.cpp index 3e987bb..14cce61 100644 --- a/lib/obp60task/OBP60Extensions.cpp +++ b/lib/obp60task/OBP60Extensions.cpp @@ -220,10 +220,9 @@ void displayHeader(CommonData &commonData, GwApi::BoatValue *date, GwApi::BoatVa } // Sunset und sunrise calculation -SensorData calcSunsetSunrise(GwApi *api, double time, double date, double latitude, double longitude, double timezone){ -/* +SunData calcSunsetSunrise(GwApi *api, double time, double date, double latitude, double longitude, double timezone){ GwLog *logger=api->getLogger(); - SensorData returnset; + SunData returnset; SunRise sr; int secPerHour = 3600; int secPerYear = 86400; @@ -268,7 +267,6 @@ SensorData calcSunsetSunrise(GwApi *api, double time, double date, double latitu returnset.sunriseMinute = intminSR; returnset.sunDown = sunDown; return returnset; -*/ } // Battery graphic with fill level diff --git a/lib/obp60task/OBP60Extensions.h b/lib/obp60task/OBP60Extensions.h index dd34b1b..e6e1fd8 100644 --- a/lib/obp60task/OBP60Extensions.h +++ b/lib/obp60task/OBP60Extensions.h @@ -42,7 +42,7 @@ 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(GwApi *api, double time, double date, double latitude, double longitude, double timezone); // Calulate sunset and sunrise +SunData calcSunsetSunrise(GwApi *api, double time, double date, double latitude, double longitude, double timezone); // Calulate sunset and sunrise void batteryGraphic(uint x, uint y, float percent, int pcolor, int bcolor); // Battery graphic with fill level diff --git a/lib/obp60task/PageClock.cpp b/lib/obp60task/PageClock.cpp index 3e1eaf3..4fad454 100644 --- a/lib/obp60task/PageClock.cpp +++ b/lib/obp60task/PageClock.cpp @@ -149,7 +149,7 @@ public: // Show values sunrise String sunrise = "---"; if(valid1 == true && valid2 == true){ - sunrise = String(commonData.data.sunriseHour) + ":" + String(commonData.data.sunriseMinute + 100).substring(1); + sunrise = String(commonData.sundata.sunriseHour) + ":" + String(commonData.sundata.sunriseMinute + 100).substring(1); } display.setTextColor(textcolor); @@ -166,7 +166,7 @@ public: // Show values sunset String sunset = "---"; if(valid1 == true && valid2 == true){ - sunset = String(commonData.data.sunsetHour) + ":" + String(commonData.data.sunsetMinute + 100).substring(1); + sunset = String(commonData.sundata.sunsetHour) + ":" + String(commonData.sundata.sunsetMinute + 100).substring(1); } display.setTextColor(textcolor); diff --git a/lib/obp60task/Pagedata.h b/lib/obp60task/Pagedata.h index 9a6e26d..a814172 100644 --- a/lib/obp60task/Pagedata.h +++ b/lib/obp60task/Pagedata.h @@ -50,11 +50,20 @@ typedef struct{ bool sunDown = true; } SensorData; +typedef struct{ + int sunsetHour = 0; + int sunsetMinute = 0; + int sunriseHour = 0; + int sunriseMinute = 0; + bool sunDown = true; +} SunData; + typedef struct{ GwApi::Status status; GwLog *logger=NULL; GwConfigHandler *config=NULL; SensorData data; + SunData sundata; GwApi::BoatValue *time=NULL; GwApi::BoatValue *date=NULL; } CommonData; diff --git a/lib/obp60task/obp60task.cpp b/lib/obp60task/obp60task.cpp index 842a242..aaff823 100644 --- a/lib/obp60task/obp60task.cpp +++ b/lib/obp60task/obp60task.cpp @@ -445,10 +445,11 @@ void OBP60Task(GwApi *api){ if(millis() > starttime5 + 1000){ starttime5 = millis(); if(time->valid == true && date->valid == true && lat->valid == true && lon->valid == true){ - commonData.data = calcSunsetSunrise(api, time->value , date->value, lat->value, lon->value, tz.toDouble()); + // Provide sundata to all pages + commonData.sundata = calcSunsetSunrise(api, time->value , date->value, lat->value, lon->value, tz.toDouble()); // Backlight with sun control if(String(backlight) == "Control by Sun"){ - setPortPin(OBP_BACKLIGHT_LED, commonData.data.sunDown); + setPortPin(OBP_BACKLIGHT_LED, commonData.sundata.sunDown); } } }