diff --git a/firmware/controllers/algo/antilag_system.cpp b/firmware/controllers/algo/antilag_system.cpp index e2db069a1f..778fe6c449 100644 --- a/firmware/controllers/algo/antilag_system.cpp +++ b/firmware/controllers/algo/antilag_system.cpp @@ -19,7 +19,9 @@ bool AntilagSystemBase::isInsideALSSwitchCondition() { if (isALSSwitchActivated) { if (isBrainPinValid(engineConfiguration->ALSActivatePin)) { +#if EFI_PROD_CODE ALSActivatePinState = engineConfiguration->ALSActivateInverted ^ efiReadPin(engineConfiguration->ALSActivatePin); +#endif } return ALSActivatePinState; } else { diff --git a/firmware/controllers/algo/antilag_system.h b/firmware/controllers/algo/antilag_system.h index cb394bccc3..847b2317f1 100644 --- a/firmware/controllers/algo/antilag_system.h +++ b/firmware/controllers/algo/antilag_system.h @@ -24,19 +24,3 @@ public: bool isAntilagConditionMet(); bool isInsideALSSwitchCondition(); }; - -/** - * See also SoftLimiterSandbox.java - */ -class ALSSoftSparkLimiter { -public: - /** - * targetSkipRatio of '0' means 'do not skip', would always return false - */ - void setTargetSkipRatio(float ALSSkipRatio); - - bool shouldSkip(); -private: - bool wasJustSkipped = false; - float ALSSkipRatio = 0; -}; diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 533a336db4..eae17a5aba 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -166,9 +166,12 @@ public: #if EFI_ANTILAG_SYSTEM AntilagSystemBase antilagController; - SoftSparkLimiter ALSsoftSparkLimiter; #endif // EFI_ANTILAG_SYSTEM +#if EFI_ANTILAG_SYSTEM + SoftSparkLimiter ALSsoftSparkLimiter; +#endif /* EFI_ANTILAG_SYSTEM */ + #if EFI_BOOST_CONTROL BoostController boostController; #endif // EFI_BOOST_CONTROL diff --git a/firmware/controllers/algo/engine2.cpp b/firmware/controllers/algo/engine2.cpp index ce05748c71..71308af45f 100644 --- a/firmware/controllers/algo/engine2.cpp +++ b/firmware/controllers/algo/engine2.cpp @@ -192,6 +192,10 @@ void EngineState::periodicFastCallback() { #if EFI_LAUNCH_CONTROL engine->launchController.update(); #endif //EFI_LAUNCH_CONTROL + +#if EFI_ANTILAG_SYSTEM + engine->antilagController.update(); +#endif //EFI_ANTILAG_SYSTEM #endif // EFI_ENGINE_CONTROL } diff --git a/firmware/controllers/engine_cycle/spark_logic.cpp b/firmware/controllers/engine_cycle/spark_logic.cpp index 1f9f1ffbd4..fdc138eaf3 100644 --- a/firmware/controllers/engine_cycle/spark_logic.cpp +++ b/firmware/controllers/engine_cycle/spark_logic.cpp @@ -498,6 +498,14 @@ void onTriggerEventSparkLogic(int rpm, efitick_t edgeTimestamp, float currentPha } #endif // EFI_LAUNCH_CONTROL +#if EFI_ANTILAG_SYSTEM + if (engine->ALSsoftSparkLimiter.shouldSkip()) { + continue; + } + auto ALSSkipRatio = engineConfiguration->ALSSkipRatio; + engine->ALSsoftSparkLimiter.setTargetSkipRatio(ALSSkipRatio); +#endif // EFI_ANTILAG_SYSTEM + scheduleSparkEvent(limitedSpark, event, rpm, edgeTimestamp, currentPhase, nextPhase); } } diff --git a/simulator/simulator/efifeatures.h b/simulator/simulator/efifeatures.h index 0120e3f720..c56b5b810a 100644 --- a/simulator/simulator/efifeatures.h +++ b/simulator/simulator/efifeatures.h @@ -16,6 +16,8 @@ #define EFI_TCU FALSE +#define EFI_ANTILAG_SYSTEM TRUE + #define ENABLE_PERF_TRACE FALSE #define EFI_PRINTF_FUEL_DETAILS FALSE diff --git a/unit_tests/efifeatures.h b/unit_tests/efifeatures.h index 5fc3f84c56..62612e89c6 100644 --- a/unit_tests/efifeatures.h +++ b/unit_tests/efifeatures.h @@ -9,6 +9,8 @@ #define EFI_ENABLE_ASSERTS TRUE +#define EFI_ANTILAG_SYSTEM TRUE + #define EFI_TUNER_STUDIO TRUE #define EFI_EMULATE_POSITION_SENSORS TRUE