From da3da6b50568062271097e31375903866e714825 Mon Sep 17 00:00:00 2001 From: Geronius Date: Sun, 3 Apr 2022 20:32:54 +0200 Subject: [PATCH] fix sunset/sunrise bug --- lib/obp60task/OBP60Extensions.cpp | 12 +++++------- lib/obp60task/PageClock.cpp | 2 -- lib/obp60task/platformio.ini | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/obp60task/OBP60Extensions.cpp b/lib/obp60task/OBP60Extensions.cpp index 79182a0..e1fe6f4 100644 --- a/lib/obp60task/OBP60Extensions.cpp +++ b/lib/obp60task/OBP60Extensions.cpp @@ -237,11 +237,11 @@ SensorData calcSunsetSunrise(GwApi *api, double time, double date, double latitu int intminSS = 0; bool sunDown = false; -// api->getLogger()->logDebug(GwLog::DEBUG,"... calcSun: Lat %f, Lon %f, at: %d, next SR: %d, next SS: %d", latitude, longitude, t, sunR, sunS); - if (!isnan(time) && !isnan(date) && !isnan(latitude) && !isnan(longitude) && !isnan(timezone)) { - // Calculate local time - t = (date * secPerYear) + (time + int(timezone * secPerHour)); + + // Calculate local epoch + t = (date * secPerYear) + time; + // api->getLogger()->logDebug(GwLog::DEBUG,"... calcSun: Lat %f, Lon %f, at: %d ", latitude, longitude, t); sr.calculate(latitude, longitude, t); // LAT, LON, EPOCH // Sunrise if (sr.hasRise) { @@ -256,7 +256,7 @@ SensorData calcSunsetSunrise(GwApi *api, double time, double date, double latitu intminSS = int((sunS - inthrSS * secPerHour)/60); } // Sun control (return value by sun on sky = false, sun down = true) - if ((t >= (sr.riseTime + int(timezone * secPerHour))) && (t <= (sr.setTime + int(timezone * secPerHour)))) + if ((t >= sr.riseTime) && (t <= sr.setTime)) sunDown = false; else sunDown = true; } @@ -266,8 +266,6 @@ SensorData calcSunsetSunrise(GwApi *api, double time, double date, double latitu returnset.sunriseHour = inthrSR; returnset.sunriseMinute = intminSR; returnset.sunDown = sunDown; - -// api->getLogger()->logDebug(GwLog::DEBUG,"... calcSun: at t: %d, hasRise: %d, next SR: %d, hasSet: %d, next SS: %d\n", t, sr.hasRise, sr.riseTime, sr.hasSet, sr.setTime); return returnset; } diff --git a/lib/obp60task/PageClock.cpp b/lib/obp60task/PageClock.cpp index e83524d..3e1eaf3 100644 --- a/lib/obp60task/PageClock.cpp +++ b/lib/obp60task/PageClock.cpp @@ -169,8 +169,6 @@ public: sunset = String(commonData.data.sunsetHour) + ":" + String(commonData.data.sunsetMinute + 100).substring(1); } - LOG_DEBUG(GwLog::LOG,"sunrise: .%s., sunset: .%s.", String(commonData.data.sunriseMinute + 100), String(commonData.data.sunsetMinute + 100)); - display.setTextColor(textcolor); display.setFont(&Ubuntu_Bold8pt7b); display.setCursor(335, 250); diff --git a/lib/obp60task/platformio.ini b/lib/obp60task/platformio.ini index 6be9046..96afbe6 100644 --- a/lib/obp60task/platformio.ini +++ b/lib/obp60task/platformio.ini @@ -22,6 +22,6 @@ lib_deps = build_flags= -D BOARD_NODEMCU32S_OBP60 ${env.build_flags} -upload_port = COM3 +upload_port = COM6 upload_protocol = esptool monitor_speed = 115200 \ No newline at end of file