Merge pull request #389 from bobbycar-graz/accel-brake-lights
This commit is contained in:
@ -205,6 +205,9 @@ struct LedstripEnableBlinkAnimationAccessor : public NewSettingsAccessor<bool> {
|
|||||||
struct LedstripOtaAnimationAccessor : public NewSettingsAccessor<OtaAnimationModes> { ConfigWrapper<OtaAnimationModes> &getConfig() const override { return configs.ledstrip.otaMode; } };
|
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 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; } };
|
struct LedstripAutomaticLightAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.ledstrip.automaticLight; } };
|
||||||
|
struct LedstripBrakeLightUseAccelAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.ledstrip.brakeLights_useAccel; } };
|
||||||
|
struct LedstripBrakeLightUsePowerAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.ledstrip.brakeLights_usePower; } };
|
||||||
|
|
||||||
|
|
||||||
// Battery
|
// Battery
|
||||||
struct BatterySeriesCellsAccessor : public NewSettingsAccessor<uint8_t> { ConfigWrapper<uint8_t> &getConfig() const override { return configs.battery.cellsSeries; } };
|
struct BatterySeriesCellsAccessor : public NewSettingsAccessor<uint8_t> { ConfigWrapper<uint8_t> &getConfig() const override { return configs.battery.cellsSeries; } };
|
||||||
|
@ -60,23 +60,18 @@ namespace bobbyblinker {
|
|||||||
}
|
}
|
||||||
if (configs.ledstrip.enableBrakeLights.value() && espchrono::ago(*brake_last_time_sent) > 500ms)
|
if (configs.ledstrip.enableBrakeLights.value() && espchrono::ago(*brake_last_time_sent) > 500ms)
|
||||||
{
|
{
|
||||||
float avgPwm{};
|
if (brakeLightsStatus == brakeLightsOffSent)
|
||||||
for (const Controller &controller: controllers) {
|
|
||||||
avgPwm +=
|
|
||||||
controller.command.left.pwm * (controller.invertLeft ? -1 : 1) +
|
|
||||||
controller.command.right.pwm * (controller.invertRight ? -1 : 1);
|
|
||||||
}
|
|
||||||
avgPwm /= 4;
|
|
||||||
|
|
||||||
if (avgPwm < -1.f)
|
|
||||||
{
|
{
|
||||||
sendState("BRAKELIGHTSON");
|
if (brakeLightsStatus)
|
||||||
brakeLightsOffSent = false;
|
{
|
||||||
}
|
sendState("BRAKELIGHTSON");
|
||||||
else if (!brakeLightsOffSent && avgPwm > -1.f)
|
brakeLightsOffSent = false;
|
||||||
{
|
}
|
||||||
sendState("BRAKELIGHTSOFF");
|
else if (!brakeLightsOffSent)
|
||||||
brakeLightsOffSent = true;
|
{
|
||||||
|
sendState("BRAKELIGHTSOFF");
|
||||||
|
brakeLightsOffSent = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,15 @@ constexpr char TEXT_ERASENVS[] = "Erase NVS (old)";
|
|||||||
constexpr char TEXT_RESET_NVS_NEW[] = "Reset NVS (new)";
|
constexpr char TEXT_RESET_NVS_NEW[] = "Reset NVS (new)";
|
||||||
constexpr char TEXT_DYNAMICMENU[] = "GUI experiments";
|
constexpr char TEXT_DYNAMICMENU[] = "GUI experiments";
|
||||||
constexpr char TEXT_BACK[] = "Back";
|
constexpr char TEXT_BACK[] = "Back";
|
||||||
|
|
||||||
|
class AccelerationText : public virtual espgui::TextInterface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::string text() const override
|
||||||
|
{
|
||||||
|
return fmt::format("Accel: {:.6f}", avgAccel);
|
||||||
|
}
|
||||||
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
DebugMenu::DebugMenu()
|
DebugMenu::DebugMenu()
|
||||||
@ -82,6 +91,7 @@ DebugMenu::DebugMenu()
|
|||||||
#ifdef FEATURE_CAN
|
#ifdef FEATURE_CAN
|
||||||
constructMenuItem<makeComponent<MenuItem, CanIcCrashText, StaticFont<2>, DisabledColor, DummyAction>>();
|
constructMenuItem<makeComponent<MenuItem, CanIcCrashText, StaticFont<2>, DisabledColor, DummyAction>>();
|
||||||
#endif
|
#endif
|
||||||
|
constructMenuItem<makeComponent<MenuItem, AccelerationText, StaticFont<2>, DisabledColor, DummyAction>>();
|
||||||
constructMenuItem<makeComponent<MenuItem, EmptyText, DummyAction>>();
|
constructMenuItem<makeComponent<MenuItem, EmptyText, DummyAction>>();
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_FRONTCOMMAND>, PushScreenAction<FrontCommandDebugMenu>>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_FRONTCOMMAND>, PushScreenAction<FrontCommandDebugMenu>>>();
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACKCOMMAND>, PushScreenAction<BackCommandDebugMenu>>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACKCOMMAND>, PushScreenAction<BackCommandDebugMenu>>>();
|
||||||
|
@ -48,6 +48,8 @@ constexpr char TEXT_ANIMATION_MULTIPLIER[] = "Animation Multiplier";
|
|||||||
constexpr char TEXT_LEDSTRIP_BRIGHTNESS[] = "Ledstrip Brightness";
|
constexpr char TEXT_LEDSTRIP_BRIGHTNESS[] = "Ledstrip Brightness";
|
||||||
constexpr char TEXT_LEDSTRIP_ALLCUSTOMOFF[] = "All custom off";
|
constexpr char TEXT_LEDSTRIP_ALLCUSTOMOFF[] = "All custom off";
|
||||||
constexpr char TEXT_LEDSTRIP_CHANGE_OTA_ANIM[] = "Change Ota animation";
|
constexpr char TEXT_LEDSTRIP_CHANGE_OTA_ANIM[] = "Change Ota animation";
|
||||||
|
constexpr char TEXT_LEDSTRIP_BRAKE_USE_ACCEL[] = "Brakelight use acceleration";
|
||||||
|
constexpr char TEXT_LEDSTRIP_BRAKE_USE_POWER[] = "Brakelight use motor power";
|
||||||
constexpr char TEXT_BACK[] = "Back";
|
constexpr char TEXT_BACK[] = "Back";
|
||||||
|
|
||||||
using LedsCountChangeScreen = espgui::makeComponent<
|
using LedsCountChangeScreen = espgui::makeComponent<
|
||||||
@ -179,6 +181,8 @@ LedstripMenu::LedstripMenu()
|
|||||||
if (!simplified) { constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_BIGOFFSET, BigOffsetAccessor>, espgui::PushScreenAction<BigOffsetChangeScreen>>>(); }
|
if (!simplified) { constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_BIGOFFSET, BigOffsetAccessor>, espgui::PushScreenAction<BigOffsetChangeScreen>>>(); }
|
||||||
if (!simplified) { constructMenuItem<makeComponent<MenuItem, espgui::StaticText<TEXT_LEDSTRIP_BRIGHTNESS>, espgui::PushScreenAction<LedStripBrightnessChangeScreen>>>(); }
|
if (!simplified) { constructMenuItem<makeComponent<MenuItem, espgui::StaticText<TEXT_LEDSTRIP_BRIGHTNESS>, espgui::PushScreenAction<LedStripBrightnessChangeScreen>>>(); }
|
||||||
if (!simplified) { constructMenuItem<makeComponent<MenuItem, LedStripMaxCurrentText, espgui::PushScreenAction<LedStripMaxAmpereChangeScreen>>>(); }
|
if (!simplified) { constructMenuItem<makeComponent<MenuItem, LedStripMaxCurrentText, espgui::PushScreenAction<LedStripMaxAmpereChangeScreen>>>(); }
|
||||||
|
constructMenuItem<makeComponent<MenuItem, espgui::StaticText<TEXT_LEDSTRIP_BRAKE_USE_ACCEL>, BobbyCheckbox, LedstripBrakeLightUseAccelAccessor>>();
|
||||||
|
constructMenuItem<makeComponent<MenuItem, espgui::StaticText<TEXT_LEDSTRIP_BRAKE_USE_POWER>, BobbyCheckbox, LedstripBrakeLightUsePowerAccessor>>();
|
||||||
constructMenuItem<makeComponent<MenuItem, espgui::StaticText<TEXT_BACK>, espgui::PushScreenAction<MainMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
|
constructMenuItem<makeComponent<MenuItem, espgui::StaticText<TEXT_BACK>, espgui::PushScreenAction<MainMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,72 +0,0 @@
|
|||||||
#include "ledstripselectanimationmenu.h"
|
|
||||||
|
|
||||||
// Local includes
|
|
||||||
#include "actions/dummyaction.h"
|
|
||||||
#include "actions/ledstripanimationactions.h"
|
|
||||||
#include "actions/popscreenaction.h"
|
|
||||||
#include "icons/back.h"
|
|
||||||
#include "ledstripdefines.h"
|
|
||||||
#include "ledstripmenu.h"
|
|
||||||
#include "newsettings.h"
|
|
||||||
|
|
||||||
#ifdef FEATURE_LEDSTRIP
|
|
||||||
namespace {
|
|
||||||
constexpr char TEXT_SELECTANIMATION[] = "Select Animation";
|
|
||||||
constexpr char TEXT_ANIMATION_DEFAULTRAINBOW[] = "Default Rainbow";
|
|
||||||
constexpr char TEXT_ANIMATION_BETTERRAINBOW[] = "Better Rainbow";
|
|
||||||
constexpr char TEXT_ANIMATION_SPEEDSYNCANIMATION[] = "Speed Sync";
|
|
||||||
constexpr char TEXT_ANIMATION_CUSTOMCOLOR[] = "Custom Color";
|
|
||||||
constexpr char TEXT_BACK[] = "Back";
|
|
||||||
|
|
||||||
class CurrentSelectedAnimationText : public virtual espgui::TextInterface
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
std::string text() const override;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
LedstripSelectAnimationMenu::LedstripSelectAnimationMenu()
|
|
||||||
{
|
|
||||||
using namespace espgui;
|
|
||||||
|
|
||||||
constructMenuItem<makeComponent<MenuItem, CurrentSelectedAnimationText, DisabledColor, DummyAction>>();
|
|
||||||
constructMenuItem<makeComponent<MenuItem, EmptyText, DummyAction>>();
|
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_DEFAULTRAINBOW>, LedStripSetAnimationAction<LedstripAnimation::DefaultRainbow>>>();
|
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_BETTERRAINBOW>, LedStripSetAnimationAction<LedstripAnimation::BetterRainbow>>>();
|
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_SPEEDSYNCANIMATION>, LedStripSetAnimationAction<LedstripAnimation::SpeedSync>>>();
|
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_CUSTOMCOLOR>, LedStripSetAnimationAction<LedstripAnimation::CustomColor>>>();
|
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, PopScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string LedstripSelectAnimationMenu::text() const
|
|
||||||
{
|
|
||||||
return TEXT_SELECTANIMATION;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LedstripSelectAnimationMenu::back()
|
|
||||||
{
|
|
||||||
espgui::popScreen();
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
std::string CurrentSelectedAnimationText::text() const
|
|
||||||
{
|
|
||||||
switch (configs.ledstrip.animationType.value)
|
|
||||||
{
|
|
||||||
case LedstripAnimation::DefaultRainbow:
|
|
||||||
return TEXT_ANIMATION_DEFAULTRAINBOW;
|
|
||||||
case LedstripAnimation::BetterRainbow:
|
|
||||||
return TEXT_ANIMATION_BETTERRAINBOW;
|
|
||||||
case LedstripAnimation::SpeedSync:
|
|
||||||
return TEXT_ANIMATION_SPEEDSYNCANIMATION;
|
|
||||||
case LedstripAnimation::CustomColor:
|
|
||||||
return TEXT_ANIMATION_CUSTOMCOLOR;
|
|
||||||
default:
|
|
||||||
return "Animation Unkown";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
#endif
|
|
@ -15,8 +15,12 @@ float gametrakDist;
|
|||||||
float avgSpeed{};
|
float avgSpeed{};
|
||||||
float avgSpeedKmh{};
|
float avgSpeedKmh{};
|
||||||
float sumCurrent{};
|
float sumCurrent{};
|
||||||
|
float lastAvgSpeedKmh{};
|
||||||
|
float avgAccel{};
|
||||||
bool isLocked{};
|
bool isLocked{};
|
||||||
|
|
||||||
|
espchrono::millis_clock::time_point lastAvgSpeedKmhTs{};
|
||||||
|
|
||||||
std::optional<int> sunrise;
|
std::optional<int> sunrise;
|
||||||
std::optional<int> sunset;
|
std::optional<int> sunset;
|
||||||
std::optional<espchrono::DateTime> sunrise_dt;
|
std::optional<espchrono::DateTime> sunrise_dt;
|
||||||
|
@ -53,8 +53,12 @@ extern esp_pm_config_esp32_t pm_config;
|
|||||||
|
|
||||||
extern float avgSpeed;
|
extern float avgSpeed;
|
||||||
extern float avgSpeedKmh;
|
extern float avgSpeedKmh;
|
||||||
|
extern float lastAvgSpeedKmh;
|
||||||
|
extern float avgAccel;
|
||||||
extern float sumCurrent;
|
extern float sumCurrent;
|
||||||
|
|
||||||
|
extern espchrono::millis_clock::time_point lastAvgSpeedKmhTs;
|
||||||
|
|
||||||
extern bool isLocked;
|
extern bool isLocked;
|
||||||
|
|
||||||
#ifdef GLOBALS_PLUGIN
|
#ifdef GLOBALS_PLUGIN
|
||||||
|
@ -19,10 +19,53 @@ std::vector<CRGB> leds;
|
|||||||
uint8_t gHue = 0;
|
uint8_t gHue = 0;
|
||||||
float gLedPosition = 0; // yes, this is intendet as a float value! Do NOT change!
|
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;
|
uint16_t blinkAnimation = LEDSTRIP_OVERWRITE_NONE;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
bool initialized{false};
|
bool initialized{false};
|
||||||
|
|
||||||
|
bool brakeLights()
|
||||||
|
{
|
||||||
|
float avgPwm{};
|
||||||
|
for (const Controller &controller : controllers)
|
||||||
|
{
|
||||||
|
avgPwm +=
|
||||||
|
controller.command.left.pwm * (controller.invertLeft ? -1 : 1) +
|
||||||
|
controller.command.right.pwm * (controller.invertRight ? -1 : 1);
|
||||||
|
}
|
||||||
|
avgPwm /= 4;
|
||||||
|
|
||||||
|
if (avgPwm < -1.f)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (configs.ledstrip.brakeLights_useAccel.value() && (avgAccel < -0.001f && avgSpeedKmh > 2.f))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (espchrono::ago(brakeLightTimer) < 200ms)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (configs.ledstrip.brakeLights_usePower.value() && brakeLightsStatus)
|
||||||
|
{
|
||||||
|
if (const auto avgVoltage = controllers.getAvgVoltage(); avgVoltage)
|
||||||
|
{
|
||||||
|
const auto watt = sumCurrent * *avgVoltage;
|
||||||
|
|
||||||
|
return watt < -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void initLedStrip()
|
void initLedStrip()
|
||||||
@ -140,20 +183,17 @@ void updateLedStrip()
|
|||||||
{
|
{
|
||||||
if (configs.ledstrip.enableBrakeLights.value())
|
if (configs.ledstrip.enableBrakeLights.value())
|
||||||
{
|
{
|
||||||
float avgPwm{};
|
// avgAccel in m/s/s
|
||||||
for (const Controller &controller : controllers)
|
if (brakeLights())
|
||||||
{
|
{
|
||||||
avgPwm +=
|
if (!(espchrono::ago(brakeLightTimer) < 200ms))
|
||||||
controller.command.left.pwm * (controller.invertLeft ? -1 : 1) +
|
{
|
||||||
controller.command.right.pwm * (controller.invertRight ? -1 : 1);
|
brakeLightTimer = espchrono::millis_clock::now();
|
||||||
}
|
}
|
||||||
avgPwm /= 4;
|
|
||||||
|
|
||||||
if (avgPwm < -1.f)
|
|
||||||
{
|
|
||||||
auto color = avgSpeedKmh < -0.1f ? CRGB{255, 255, 255} : CRGB{255, 0, 0};
|
auto color = avgSpeedKmh < -0.1f ? CRGB{255, 255, 255} : CRGB{255, 0, 0};
|
||||||
|
|
||||||
const auto center = (std::begin(leds) + (leds.size() / 2) + configs.ledstrip.centerOffset.value());
|
brakeLightsStatus = true;
|
||||||
|
|
||||||
std::fill(std::begin(leds), std::end(leds), CRGB{0, 0, 0});
|
std::fill(std::begin(leds), std::end(leds), CRGB{0, 0, 0});
|
||||||
if (configs.ledstrip.enableFullBlink.value())
|
if (configs.ledstrip.enableFullBlink.value())
|
||||||
@ -162,12 +202,15 @@ void updateLedStrip()
|
|||||||
}
|
}
|
||||||
else if(!configs.ledstrip.enableAnimBlink.value())
|
else if(!configs.ledstrip.enableAnimBlink.value())
|
||||||
{
|
{
|
||||||
|
const auto center = (std::begin(leds) + (leds.size() / 2) + configs.ledstrip.centerOffset.value());
|
||||||
|
|
||||||
std::fill(center - configs.ledstrip.bigOffset.value() - 2, center - configs.ledstrip.smallOffset.value() + 2, color);
|
std::fill(center - configs.ledstrip.bigOffset.value() - 2, center - configs.ledstrip.smallOffset.value() + 2, color);
|
||||||
std::fill(center + configs.ledstrip.smallOffset.value() - 2, center + configs.ledstrip.bigOffset.value() + 2, color);
|
std::fill(center + configs.ledstrip.smallOffset.value() - 2, center + configs.ledstrip.bigOffset.value() + 2, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
brakeLightsStatus = false;
|
||||||
showAnimation();
|
showAnimation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
// 3rdparty lib includes
|
// 3rdparty lib includes
|
||||||
|
#include <espchrono.h>
|
||||||
#include <FastLED.h>
|
#include <FastLED.h>
|
||||||
|
|
||||||
// local includes
|
// local includes
|
||||||
@ -44,6 +45,10 @@ extern float gLedPosition; // yes, this is intendet as a float value! Do NOT cha
|
|||||||
|
|
||||||
extern uint16_t blinkAnimation;
|
extern uint16_t blinkAnimation;
|
||||||
|
|
||||||
|
extern bool brakeLightsStatus;
|
||||||
|
|
||||||
|
extern espchrono::millis_clock::time_point brakeLightTimer;
|
||||||
|
|
||||||
void showDefaultLedstrip();
|
void showDefaultLedstrip();
|
||||||
void showAnimation();
|
void showAnimation();
|
||||||
void showBetterRainbow();
|
void showBetterRainbow();
|
||||||
|
@ -415,6 +415,8 @@ public:
|
|||||||
};
|
};
|
||||||
ConfigWrapperLegacy<uint8_t> leds_per_meter {144, DoReset, {}, "ledsPerMeter" };
|
ConfigWrapperLegacy<uint8_t> leds_per_meter {144, DoReset, {}, "ledsPerMeter" };
|
||||||
ConfigWrapperLegacy<bool> automaticLight {false, DoReset, {}, "nightLights" };
|
ConfigWrapperLegacy<bool> automaticLight {false, DoReset, {}, "nightLights" };
|
||||||
|
ConfigWrapperLegacy<bool> brakeLights_useAccel {false, DoReset, {}, "brakeLightsA" };
|
||||||
|
ConfigWrapperLegacy<bool> brakeLights_usePower {false, DoReset, {}, "brakeLightsP" };
|
||||||
} ledstrip;
|
} ledstrip;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
@ -749,6 +751,8 @@ public:
|
|||||||
x(ledstrip.maxMilliamps) \
|
x(ledstrip.maxMilliamps) \
|
||||||
x(ledstrip.enableVisualizeBlink)\
|
x(ledstrip.enableVisualizeBlink)\
|
||||||
x(ledstrip.automaticLight) \
|
x(ledstrip.automaticLight) \
|
||||||
|
x(ledstrip.brakeLights_useAccel) \
|
||||||
|
x(ledstrip.brakeLights_usePower) \
|
||||||
\
|
\
|
||||||
x(ledstrip.custom_color[0]) \
|
x(ledstrip.custom_color[0]) \
|
||||||
x(ledstrip.custom_color[1]) \
|
x(ledstrip.custom_color[1]) \
|
||||||
|
@ -248,6 +248,28 @@ void updateAccumulators()
|
|||||||
sumCurrent = fixCurrent(sumCurrent);
|
sumCurrent = fixCurrent(sumCurrent);
|
||||||
|
|
||||||
avgSpeedKmh = convertToKmh(avgSpeed);
|
avgSpeedKmh = convertToKmh(avgSpeed);
|
||||||
|
|
||||||
|
// accel
|
||||||
|
EVERY_N_MILLIS(100)
|
||||||
|
{
|
||||||
|
const auto now = espchrono::millis_clock::now();
|
||||||
|
const auto delta = now - lastAvgSpeedKmhTs;
|
||||||
|
const auto deltaSpeedKmh = avgSpeedKmh - lastAvgSpeedKmh;
|
||||||
|
|
||||||
|
// ESP_LOGI("utils.cpp", "delta: %lli ms, deltaSpeedKmh: %f", delta.count() / 1000, deltaSpeedKmh);
|
||||||
|
|
||||||
|
const auto deltaMilliseconds = delta.count() / 1000.f;
|
||||||
|
|
||||||
|
const auto kmh_s = deltaSpeedKmh / deltaMilliseconds; // km/h / s
|
||||||
|
const auto m_s2 = kmh_s * 1000.f / 3600.f; // m/s^2
|
||||||
|
|
||||||
|
// ESP_LOGI("utils.cpp", "m_s2: %f", m_s2);
|
||||||
|
|
||||||
|
avgAccel = avgAccel * 0.3f + m_s2 * 0.7f;
|
||||||
|
|
||||||
|
lastAvgSpeedKmh = avgSpeedKmh;
|
||||||
|
lastAvgSpeedKmhTs = espchrono::millis_clock::now();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float wattToAmpere(float watt) {
|
float wattToAmpere(float watt) {
|
||||||
|
Reference in New Issue
Block a user