diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 9a9b3d0c9c..6fc6794858 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -26,6 +26,7 @@ #include "perf_trace.h" #include "sensor.h" #include "gppwm.h" +#include "tachometer.h" #if EFI_TUNER_STUDIO #include "tunerstudio_outputs.h" @@ -519,6 +520,8 @@ void Engine::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) { #endif engineState.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE); + + tachSignalCallback(PASS_ENGINE_PARAMETER_SIGNATURE); } void doScheduleStopEngine(DECLARE_ENGINE_PARAMETER_SIGNATURE) { diff --git a/firmware/controllers/gauges/tachometer.cpp b/firmware/controllers/gauges/tachometer.cpp index cae0a8bfdb..44ec6ba6bf 100644 --- a/firmware/controllers/gauges/tachometer.cpp +++ b/firmware/controllers/gauges/tachometer.cpp @@ -11,7 +11,6 @@ */ #include "tachometer.h" -#include "trigger_central.h" #include "pwm_generator_logic.h" EXTERN_ENGINE; @@ -21,31 +20,23 @@ static float tachFreq; static float duty; #if EFI_UNIT_TEST -float getTachFreq(void) { +float getTachFreq() { return tachFreq; } -float getTachDuty(void) { +float getTachDuty() { return duty; } #endif -static void tachSignalCallback(trigger_event_e ckpSignalType, - uint32_t index, efitick_t edgeTimestamp DECLARE_ENGINE_PARAMETER_SUFFIX) { - // only process at index configured to avoid too much cpu time for index 0? - if (index != (uint32_t)CONFIG(tachPulseTriggerIndex)) { +static bool tachHasInit = false; + +void tachSignalCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) { + // Only do anything if tach enabled + if (!tachHasInit) { return; } -#if EFI_UNIT_TEST - printf("tachSignalCallback(%d %d)\n", ckpSignalType, index); - printf("Current RPM: %d\n",GET_RPM()); - UNUSED(edgeTimestamp); -#else - UNUSED(ckpSignalType); - UNUSED(edgeTimestamp); -#endif - // How many tach pulse periods do we have? int periods = CONFIG(tachPulsePerRev); @@ -74,10 +65,10 @@ static void tachSignalCallback(trigger_event_e ckpSignalType, tachControl.setSimplePwmDutyCycle(duty); tachControl.setFrequency(tachFreq); - } void initTachometer(DECLARE_ENGINE_PARAMETER_SIGNATURE) { + tachHasInit = false; if (CONFIG(tachOutputPin) == GPIO_UNASSIGNED) { return; } @@ -89,7 +80,5 @@ void initTachometer(DECLARE_ENGINE_PARAMETER_SIGNATURE) { &enginePins.tachOut, NAN, 0.1f); -#if EFI_SHAFT_POSITION_INPUT - addTriggerEventListener(tachSignalCallback, "tach", engine); -#endif /* EFI_SHAFT_POSITION_INPUT */ + tachHasInit = true; } diff --git a/firmware/controllers/gauges/tachometer.h b/firmware/controllers/gauges/tachometer.h index 6f4608641d..a3574f693d 100644 --- a/firmware/controllers/gauges/tachometer.h +++ b/firmware/controllers/gauges/tachometer.h @@ -10,4 +10,4 @@ #include "engine.h" void initTachometer(DECLARE_ENGINE_PARAMETER_SIGNATURE); - +void tachSignalCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE);