Added brake light optimizations

This commit is contained in:
CommanderRedYT
2022-12-18 02:31:41 +01:00
parent b61dfcf53d
commit 52ff7acd02
3 changed files with 12 additions and 2 deletions

View File

@ -21,6 +21,8 @@ float gLedPosition = 0; // yes, this is intendet as a float value! Do NOT change
bool brakeLightsStatus;
espchrono::millis_clock::time_point brakeLightTimer;
uint16_t blinkAnimation = LEDSTRIP_OVERWRITE_NONE;
namespace {
@ -152,8 +154,13 @@ void updateLedStrip()
avgPwm /= 4;
// avgAccel in m/s/s
if (avgPwm < -1.f || (avgAccel < -0.001f && avgSpeedKmh > 5.f))
if (avgPwm < -1.f || (avgAccel < -0.001f && avgSpeedKmh > 5.f) || espchrono::ago(brakeLightTimer) < 200ms)
{
if (!(espchrono::ago(brakeLightTimer) < 200ms))
{
brakeLightTimer = espchrono::millis_clock::now();
}
auto color = avgSpeedKmh < -0.1f ? CRGB{255, 255, 255} : CRGB{255, 0, 0};
brakeLightsStatus = true;

View File

@ -4,6 +4,7 @@
#include <vector>
// 3rdparty lib includes
#include <espchrono.h>
#include <FastLED.h>
// local includes
@ -46,6 +47,8 @@ extern uint16_t blinkAnimation;
extern bool brakeLightsStatus;
extern espchrono::millis_clock::time_point brakeLightTimer;
void showDefaultLedstrip();
void showAnimation();
void showBetterRainbow();

View File

@ -265,7 +265,7 @@ void updateAccumulators()
// ESP_LOGI("utils.cpp", "m_s2: %f", m_s2);
avgAccel = m_s2;
avgAccel = avgAccel * 0.3f + m_s2 * 0.7f;
lastAvgSpeedKmh = avgSpeedKmh;
lastAvgSpeedKmhTs = espchrono::millis_clock::now();