Added acceleration detection for brake lights

This commit is contained in:
CommanderRedYT
2022-12-18 00:18:50 +01:00
parent f6b4966071
commit b61dfcf53d
7 changed files with 61 additions and 18 deletions

View File

@@ -60,23 +60,18 @@ namespace bobbyblinker {
}
if (configs.ledstrip.enableBrakeLights.value() && espchrono::ago(*brake_last_time_sent) > 500ms)
{
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)
if (brakeLightsStatus == brakeLightsOffSent)
{
sendState("BRAKELIGHTSON");
brakeLightsOffSent = false;
}
else if (!brakeLightsOffSent && avgPwm > -1.f)
{
sendState("BRAKELIGHTSOFF");
brakeLightsOffSent = true;
if (brakeLightsStatus)
{
sendState("BRAKELIGHTSON");
brakeLightsOffSent = false;
}
else if (!brakeLightsOffSent)
{
sendState("BRAKELIGHTSOFF");
brakeLightsOffSent = true;
}
}
}
}