From 1774a75732104c3a74e7aa7c82c36c41c74d1478 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 15 Aug 2023 12:25:53 -0400 Subject: [PATCH] docs & extracing constant --- .../trigger/decoders/trigger_universal.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/firmware/controllers/trigger/decoders/trigger_universal.cpp b/firmware/controllers/trigger/decoders/trigger_universal.cpp index ef7f4ee691..3d16c8b0e2 100644 --- a/firmware/controllers/trigger/decoders/trigger_universal.cpp +++ b/firmware/controllers/trigger/decoders/trigger_universal.cpp @@ -16,19 +16,24 @@ angle_t getEngineCycle(operation_mode_e operationMode) { return operationMode == TWO_STROKE ? 360 : FOUR_STROKE_ENGINE_CYCLE; } +/** + * last fall aligned at 720 and skipped area is right before 720 + */ void addSkippedToothTriggerEvents(TriggerWheel wheel, TriggerWaveform *s, int totalTeethCount, int skippedCount, float toothWidth, float offset, float engineCycle, float filterLeft, float filterRight) { efiAssertVoid(ObdCode::CUSTOM_ERR_6586, totalTeethCount > 0, "total count"); efiAssertVoid(ObdCode::CUSTOM_ERR_6587, skippedCount >= 0, "skipped count"); + float oneTooth = engineCycle / totalTeethCount; + for (int i = 0; i < totalTeethCount - skippedCount - 1; i++) { - float angleDown = engineCycle / totalTeethCount * (i + (1 - toothWidth)); - float angleUp = engineCycle / totalTeethCount * (i + 1); + float angleDown = oneTooth * (i + (1 - toothWidth)); + float angleUp = oneTooth * (i + 1); s->addEventClamped(offset + angleDown, TriggerValue::RISE, wheel, filterLeft, filterRight); s->addEventClamped(offset + angleUp, TriggerValue::FALL, wheel, filterLeft, filterRight); } - float angleDown = engineCycle / totalTeethCount * (totalTeethCount - skippedCount - 1 + (1 - toothWidth)); + float angleDown = oneTooth * (totalTeethCount - skippedCount - 1 + (1 - toothWidth)); s->addEventClamped(offset + angleDown, TriggerValue::RISE, wheel, filterLeft, filterRight); // custom handling of last event in order to avoid rounding error s->addEventClamped(offset + engineCycle, TriggerValue::FALL, wheel, filterLeft, filterRight);