Added acceleration and power cause for 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 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 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
|
||||
struct BatterySeriesCellsAccessor : public NewSettingsAccessor<uint8_t> { ConfigWrapper<uint8_t> &getConfig() const override { return configs.battery.cellsSeries; } };
|
||||
|
@ -48,6 +48,8 @@ constexpr char TEXT_ANIMATION_MULTIPLIER[] = "Animation Multiplier";
|
||||
constexpr char TEXT_LEDSTRIP_BRIGHTNESS[] = "Ledstrip Brightness";
|
||||
constexpr char TEXT_LEDSTRIP_ALLCUSTOMOFF[] = "All custom off";
|
||||
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";
|
||||
|
||||
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, espgui::StaticText<TEXT_LEDSTRIP_BRIGHTNESS>, espgui::PushScreenAction<LedStripBrightnessChangeScreen>>>(); }
|
||||
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>>>();
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,46 @@ espchrono::millis_clock::time_point brakeLightTimer;
|
||||
uint16_t blinkAnimation = LEDSTRIP_OVERWRITE_NONE;
|
||||
|
||||
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)
|
||||
{
|
||||
auto watt = sumCurrent * *avgVoltage;
|
||||
|
||||
return watt < -20;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void initLedStrip()
|
||||
@ -144,17 +183,8 @@ void updateLedStrip()
|
||||
{
|
||||
if (configs.ledstrip.enableBrakeLights.value())
|
||||
{
|
||||
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;
|
||||
|
||||
// avgAccel in m/s/s
|
||||
if (avgPwm < -1.f || (avgAccel < -0.001f && avgSpeedKmh > 5.f) || espchrono::ago(brakeLightTimer) < 200ms)
|
||||
if (brakeLights())
|
||||
{
|
||||
if (!(espchrono::ago(brakeLightTimer) < 200ms))
|
||||
{
|
||||
|
@ -415,6 +415,8 @@ public:
|
||||
};
|
||||
ConfigWrapperLegacy<uint8_t> leds_per_meter {144, DoReset, {}, "ledsPerMeter" };
|
||||
ConfigWrapperLegacy<bool> automaticLight {false, DoReset, {}, "nightLights" };
|
||||
ConfigWrapperLegacy<bool> brakeLights_useAccel {false, DoReset, {}, "brakeLightsA" };
|
||||
ConfigWrapperLegacy<bool> brakeLights_usePower {false, DoReset, {}, "brakeLightsP" };
|
||||
} ledstrip;
|
||||
|
||||
struct {
|
||||
@ -749,6 +751,8 @@ public:
|
||||
x(ledstrip.maxMilliamps) \
|
||||
x(ledstrip.enableVisualizeBlink)\
|
||||
x(ledstrip.automaticLight) \
|
||||
x(ledstrip.brakeLights_useAccel) \
|
||||
x(ledstrip.brakeLights_usePower) \
|
||||
\
|
||||
x(ledstrip.custom_color[0]) \
|
||||
x(ledstrip.custom_color[1]) \
|
||||
|
Reference in New Issue
Block a user