diff --git a/main/ledstrip.cpp b/main/ledstrip.cpp index 1a1276f..2ff37ce 100644 --- a/main/ledstrip.cpp +++ b/main/ledstrip.cpp @@ -1,16 +1,16 @@ #include "ledstrip.h" // 3rdparty lib includes +#include +#include #include // local includes #include "globals.h" -#include "cpputils.h" -#include "espchrono.h" #include "ledstripdefines.h" -#include "utils.h" -#include "ota.h" #include "newsettings.h" +#include "ota.h" +#include "utils.h" using namespace std::chrono_literals; @@ -183,7 +183,9 @@ void updateLedStrip() } else if ((cpputils::is_in(blinkAnimation, LEDSTRIP_OVERWRITE_BLINKLEFT, LEDSTRIP_OVERWRITE_BLINKRIGHT, LEDSTRIP_OVERWRITE_BLINKBOTH)) && configs.ledstrip.enableBeepWhenBlink.value) have_disabled_beeper = false; - if (simplified || configs.ledstrip.enableStVO.value) + const auto automaticLight = activateAutomaticFrontLight(); + + if (simplified || configs.ledstrip.enableStVO.value || automaticLight) { const auto center = (std::begin(leds) + (leds.size() / 2) + configs.ledstrip.centerOffset.value); @@ -198,7 +200,7 @@ void updateLedStrip() std::fill(center + configs.ledstrip.smallOffset.value + 1U, center + configs.ledstrip.bigOffset.value + 1U, CRGB{255, 0, 0}); // Left } - if (configs.ledstrip.stvoFrontEnable.value) + if (configs.ledstrip.stvoFrontEnable.value || automaticLight) { std::fill(std::begin(leds) + configs.ledstrip.stvoFrontOffset.value, std::begin(leds) + configs.ledstrip.stvoFrontOffset.value + configs.ledstrip.stvoFrontLength.value, CRGB{255, 255, 255}); std::fill(std::end(leds) - configs.ledstrip.stvoFrontOffset.value - configs.ledstrip.stvoFrontLength.value, std::end(leds) - configs.ledstrip.stvoFrontOffset.value, CRGB{255, 255, 255}); @@ -354,3 +356,17 @@ void showCustomColor() std::fill(center - (eighth_length / 2) - eighth_length - eighth_length - eighth_length, center - (eighth_length / 2) - eighth_length - eighth_length, configs.ledstrip.custom_color[int(Bobbycar_Side::FRONT_LEFT)].value); // Front Left #endif } + +bool activateAutomaticFrontLight() +{ + if (!configs.ledstrip.automaticLight.value) + return false; + SunSet sunSet; + sunSet.setPosition(47.076668, 15.421371, 1); // Vienna + sunSet.setTZOffset(1); + const auto today = toDateTime(espchrono::utc_clock::now()); + sunSet.setCurrentDate(static_cast(today.date.year()), static_cast(today.date.month()), static_cast(today.date.day())); + const auto sunrise = static_cast(sunSet.calcSunrise()) / 60; + const auto sunset = static_cast(sunSet.calcSunset()) / 60; + return (today.hour >= sunrise && today.hour < sunset); +} diff --git a/main/ledstrip.h b/main/ledstrip.h index 06f0037..53f12f6 100644 --- a/main/ledstrip.h +++ b/main/ledstrip.h @@ -49,3 +49,5 @@ void showOtaAnimation(); void initLedStrip(); void updateLedStrip(); + +bool activateAutomaticFrontLight(); diff --git a/main/newsettings.h b/main/newsettings.h index 981be8b..a4cc301 100644 --- a/main/newsettings.h +++ b/main/newsettings.h @@ -294,6 +294,7 @@ public: ConfigWrapper {0, DoReset, {}, "ledCustomCol8" }, }; ConfigWrapper leds_per_meter {144, DoReset, {}, "ledsPerMeter" }; + ConfigWrapper automaticLight {false, DoReset, {}, "nightLights" }; } ledstrip; struct { @@ -600,7 +601,8 @@ public: x(ledstrip.enableAnimBlink) \ x(ledstrip.otaMode) \ x(ledstrip.maxMilliamps) \ - x(ledstrip.enableVisualizeBlink) \ + x(ledstrip.enableVisualizeBlink)\ + x(ledstrip.automaticLight) \ \ x(ledstrip.custom_color[0]) \ x(ledstrip.custom_color[1]) \