Merge pull request #298 from bobbycar-graz/nightlight
Turn on lights when dark
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -61,3 +61,6 @@
|
||||
[submodule "components/QRCode-esp32"]
|
||||
path = components/QRCode-esp32
|
||||
url = ../QRCode-esp32.git
|
||||
[submodule "components/sunset"]
|
||||
path = components/sunset
|
||||
url = ../sunset.git
|
||||
|
1
components/sunset
Submodule
1
components/sunset
Submodule
Submodule components/sunset added at 0520b0945c
@ -486,7 +486,7 @@ set(sources
|
||||
set(dependencies
|
||||
freertos nvs_flash esp_http_server esp_https_ota mdns app_update esp_system esp_websocket_client driver
|
||||
arduino-esp32 ArduinoJson esp-nimble-cpp FastLED-idf TFT_eSPI QRCode-esp32
|
||||
bobbycar-protocol cpputils cxx-ring-buffer date
|
||||
bobbycar-protocol cpputils cxx-ring-buffer date sunset
|
||||
espasynchttpreq espasyncota espchrono espcpputils espconfiglib esp-gui-lib esphttpdutils espwifistack expected fmt
|
||||
)
|
||||
|
||||
|
@ -194,6 +194,7 @@ struct LedstripBrightnessAccessor : public NewSettingsAccessor<uint8_t> { Config
|
||||
struct LedstripEnableBlinkAnimationAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.ledstrip.enableAnimBlink; } };
|
||||
struct LedstripOtaAnimationAccessor : public NewSettingsAccessor<OtaAnimationModes> { ConfigWrapper<OtaAnimationModes> &getConfig() const override { return configs.ledstrip.otaMode; } };
|
||||
struct LedstripEnableVisualizeBlinkAnimationAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.ledstrip.enableVisualizeBlink; } };
|
||||
struct LedstripAutomaticLightAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.ledstrip.automaticLight; } };
|
||||
|
||||
// Battery
|
||||
struct BatterySeriesCellsAccessor : public NewSettingsAccessor<uint8_t> { ConfigWrapper<uint8_t> &getConfig() const override { return configs.battery.cellsSeries; } };
|
||||
|
@ -42,6 +42,7 @@ constexpr char TEXT_LEDSTRIP_STVO[] = "Enable StVO";
|
||||
constexpr char TEXT_STVO_FRONTOFFSET[] = "StVO Front Offset";
|
||||
constexpr char TEXT_STVO_FRONTLENGTH[] = "StVO Front Length";
|
||||
constexpr char TEXT_STVO_ENABLEFRONTLIGHT[] = "StVO Front Enable";
|
||||
constexpr char TEXT_AUTOMATIC_LIGHTS[] = "Automatic Lights";
|
||||
constexpr char TEXT_ANIMATION_MULTIPLIER[] = "Animation Multiplier";
|
||||
constexpr char TEXT_LEDSTRIP_BRIGHTNESS[] = "Ledstrip Brightness";
|
||||
constexpr char TEXT_LEDSTRIP_ALLCUSTOMOFF[] = "All custom off";
|
||||
@ -150,6 +151,7 @@ LedstripMenu::LedstripMenu()
|
||||
|
||||
if (!simplified) { constructMenuItem<makeComponent<MenuItem, espgui::StaticText<TEXT_LEDSTRIP_STVO>, BobbyCheckbox, EnableLedstripStVOAccessor>>(); }
|
||||
constructMenuItem<makeComponent<MenuItem, espgui::StaticText<TEXT_STVO_ENABLEFRONTLIGHT>, BobbyCheckbox, EnableLedstripStVOFrontlight>>();
|
||||
constructMenuItem<makeComponent<MenuItem, espgui::StaticText<TEXT_AUTOMATIC_LIGHTS>, BobbyCheckbox, LedstripAutomaticLightAccessor>>();
|
||||
|
||||
constructMenuItem<makeComponent<MenuItem, espgui::StaticText<TEXT_LEDANIMATION>, BobbyCheckbox, EnableLedAnimationAccessor>>();
|
||||
constructMenuItem<SwitchScreenTypeSafeChangeMenuItem<LedstripAnimation, LedstripMenu, TEXT_SELECTANIMATION>>(&configs.ledstrip.animationType);
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "actions/dummyaction.h"
|
||||
#include "icons/back.h"
|
||||
#include "espstrutils.h"
|
||||
#include <sunset.h>
|
||||
|
||||
// local includes
|
||||
#include "displays/bobbychangevaluedisplay.h"
|
||||
@ -53,6 +54,26 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class SuntimeText : public virtual espgui::TextInterface
|
||||
{
|
||||
public:
|
||||
std::string text() const override
|
||||
{
|
||||
SunSet sunSet;
|
||||
sunSet.setPosition(47.076668, 15.421371, 2); // Vienna
|
||||
sunSet.setTZOffset(2);
|
||||
const auto today = toDateTime(espchrono::utc_clock::now());
|
||||
sunSet.setCurrentDate(static_cast<int>(today.date.year()), static_cast<uint>(today.date.month()), static_cast<uint>(today.date.day()));
|
||||
const auto sunrise = static_cast<int>(sunSet.calcSunrise());
|
||||
const auto sunset = static_cast<int>(sunSet.calcSunset());
|
||||
const int sunriseHour = sunrise / 60;
|
||||
const int sunriseMinute = sunrise % 60;
|
||||
const int sunsetHour = sunset / 60;
|
||||
const int sunsetMinute = sunset % 60;
|
||||
return fmt::format("sunrise: {}:{:02d} sunset: {}:{:02d}", sunriseHour, sunriseMinute, sunsetHour, sunsetMinute);
|
||||
}
|
||||
};
|
||||
|
||||
using TimezoneOffsetChangeDisplay = espgui::makeComponent<
|
||||
BobbyChangeValueDisplay<int32_t>,
|
||||
espgui::StaticText<TEXT_OFFSET>,
|
||||
@ -108,6 +129,7 @@ TimeSettingsMenu::TimeSettingsMenu()
|
||||
using namespace espgui;
|
||||
constructMenuItem<makeComponent<MenuItem, CurrentUtcDateTimeText, StaticFont<2>, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, CurrentLocalDateTimeText, StaticFont<2>, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, SuntimeText, StaticFont<2>, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_OFFSET>, SwitchScreenAction<TimezoneOffsetChangeDisplay>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_DAYLIGHTSAVINGMODE>, SwitchScreenAction<DaylightSavingModeChangeDisplay>>>();
|
||||
if (configs.feature.ntp.isEnabled.value)
|
||||
|
@ -1,15 +1,16 @@
|
||||
#include "ledstrip.h"
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <cpputils.h>
|
||||
#include <espchrono.h>
|
||||
#include <sunset.h>
|
||||
|
||||
// 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;
|
||||
|
||||
@ -182,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);
|
||||
|
||||
@ -197,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});
|
||||
@ -353,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
|
||||
}
|
||||
|
||||
[[nodiscard]] bool activateAutomaticFrontLight()
|
||||
{
|
||||
if (!configs.ledstrip.automaticLight.value)
|
||||
return false;
|
||||
SunSet sunSet;
|
||||
sunSet.setPosition(47.076668, 15.421371, 0); // Vienna
|
||||
sunSet.setTZOffset(0);
|
||||
const auto today = toDateTime(espchrono::utc_clock::now());
|
||||
sunSet.setCurrentDate(static_cast<int>(today.date.year()), static_cast<uint>(today.date.month()), static_cast<uint>(today.date.day()));
|
||||
const auto sunrise = static_cast<int>(sunSet.calcSunrise()) / 60;
|
||||
const auto sunset = static_cast<int>(sunSet.calcSunset()) / 60;
|
||||
return (today.hour >= sunrise && today.hour < sunset);
|
||||
}
|
||||
|
@ -49,3 +49,5 @@ void showOtaAnimation();
|
||||
|
||||
void initLedStrip();
|
||||
void updateLedStrip();
|
||||
|
||||
[[nodiscard]] bool activateAutomaticFrontLight();
|
||||
|
@ -294,6 +294,7 @@ public:
|
||||
ConfigWrapper<uint32_t> {0, DoReset, {}, "ledCustomCol8" },
|
||||
};
|
||||
ConfigWrapper<uint8_t> leds_per_meter {144, DoReset, {}, "ledsPerMeter" };
|
||||
ConfigWrapper<bool> 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]) \
|
||||
|
@ -338,3 +338,9 @@ float float_map(float x, float in_min, float in_max, float out_min, float out_ma
|
||||
|
||||
return (delta * dividend + (divisor / 2.f)) / divisor + out_min;
|
||||
}
|
||||
|
||||
bool is_valid_timestamp(espchrono::utc_clock::time_point timestamp)
|
||||
{
|
||||
using namespace date;
|
||||
return timestamp.time_since_epoch() > sys_seconds{sys_days{1_d/January/2000}}.time_since_epoch();
|
||||
}
|
||||
|
@ -80,3 +80,4 @@ inline CRGB UINT32_TO_CRGB(uint32_t color)
|
||||
|
||||
std::string get_wifi_security_string(wifi_auth_mode_t authMode);
|
||||
float float_map(float x, float in_min, float in_max, float out_min, float out_max);
|
||||
bool is_valid_timestamp(espchrono::utc_clock::time_point timestamp);
|
||||
|
Reference in New Issue
Block a user