diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index f17c351db0..43eaedf9fc 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -668,7 +668,7 @@ void updateTunerStudioState() { // offset 0 tsOutputChannels->RPMValue = rpm; - auto instantRpm = engine->triggerCentral.triggerState.getInstantRpm(); + auto instantRpm = engine->triggerCentral.instantRpm.getInstantRpm(); tsOutputChannels->instantRpm = instantRpm; updateSensors(); diff --git a/firmware/controllers/actuators/idle_thread.cpp b/firmware/controllers/actuators/idle_thread.cpp index bc25a5913a..65188b29b8 100644 --- a/firmware/controllers/actuators/idle_thread.cpp +++ b/firmware/controllers/actuators/idle_thread.cpp @@ -358,7 +358,7 @@ float IdleController::getIdlePosition(float rpm) { } void IdleController::onSlowCallback() { - float position = getIdlePosition(engine->triggerCentral.triggerState.getInstantRpm()); + float position = getIdlePosition(engine->triggerCentral.instantRpm.getInstantRpm()); applyIACposition(position); } diff --git a/firmware/controllers/algo/advance_map.cpp b/firmware/controllers/algo/advance_map.cpp index a1326f06ca..3539782f7c 100644 --- a/firmware/controllers/algo/advance_map.cpp +++ b/firmware/controllers/algo/advance_map.cpp @@ -104,7 +104,7 @@ angle_t getAdvanceCorrections(int rpm) { ); } - float instantRpm = engine->triggerCentral.triggerState.getInstantRpm(); + float instantRpm = engine->triggerCentral.instantRpm.getInstantRpm(); engine->engineState.timingPidCorrection = engine->module()->getIdleTimingAdjustment(instantRpm); diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index e6e394ec19..fc0a886b20 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -314,7 +314,7 @@ void Engine::OnTriggerSynchronizationLost() { rpmCalculator.setStopSpinning(); triggerCentral.triggerState.resetState(); - triggerCentral.triggerState.instantRpm.resetInstantRpm(); + triggerCentral.instantRpm.resetInstantRpm(); for (size_t i = 0; i < efi::size(triggerCentral.vvtState); i++) { for (size_t j = 0; j < efi::size(triggerCentral.vvtState[0]); j++) { diff --git a/firmware/controllers/engine_cycle/rpm_calculator.cpp b/firmware/controllers/engine_cycle/rpm_calculator.cpp index 234001a898..20d74d76b1 100644 --- a/firmware/controllers/engine_cycle/rpm_calculator.cpp +++ b/firmware/controllers/engine_cycle/rpm_calculator.cpp @@ -240,12 +240,12 @@ void RpmCalculator::setSpinningUp(efitick_t nowNt) { // Only a completely stopped and non-spinning engine can enter the spinning-up state. if (isStopped() && !isSpinning) { state = SPINNING_UP; - engine->triggerCentral.triggerState.instantRpm.spinningEventIndex = 0; + engine->triggerCentral.instantRpm.spinningEventIndex = 0; isSpinning = true; } // update variables needed by early instant RPM calc. if (isSpinningUp() && !engine->triggerCentral.triggerState.getShaftSynchronized()) { - engine->triggerCentral.triggerState.instantRpm.setLastEventTimeForInstantRpm(nowNt); + engine->triggerCentral.instantRpm.setLastEventTimeForInstantRpm(nowNt); } } @@ -298,7 +298,7 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType, } else { // we are here only once trigger is synchronized for the first time // while transitioning from 'spinning' to 'running' - engine->triggerCentral.triggerState.instantRpm.movePreSynchTimestamps(); + engine->triggerCentral.instantRpm.movePreSynchTimestamps(); } rpmState->onNewEngineCycle(); @@ -315,13 +315,13 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType, #endif /* EFI_SENSOR_CHART */ // Always update instant RPM even when not spinning up - engine->triggerCentral.triggerState.instantRpm.updateInstantRpm( + engine->triggerCentral.instantRpm.updateInstantRpm( engine->triggerCentral.triggerState.currentCycle.current_index, engine->triggerCentral.triggerShape, &engine->triggerCentral.triggerFormDetails, trgEventIndex, nowNt); - float instantRpm = engine->triggerCentral.triggerState.getInstantRpm(); + float instantRpm = engine->triggerCentral.instantRpm.getInstantRpm(); if (alwaysInstantRpm) { rpmState->setRpmValue(instantRpm); } else if (rpmState->isSpinningUp()) { diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index 2f8c370bb7..967a786684 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -131,7 +131,7 @@ angle_t TriggerCentral::syncAndReport(int divider, int remainder) { if (totalShift != 0) { // Reset instant RPM, since the engine phase has now changed, invalidating the tooth history buffer // maybe TODO: could/should we rotate the buffer around to re-align it instead? Is that worth it? - triggerState.instantRpm.resetInstantRpm(); + instantRpm.resetInstantRpm(); } return totalShift; } diff --git a/firmware/controllers/trigger/trigger_central.h b/firmware/controllers/trigger/trigger_central.h index 09584fec71..99b37e246b 100644 --- a/firmware/controllers/trigger/trigger_central.h +++ b/firmware/controllers/trigger/trigger_central.h @@ -55,6 +55,8 @@ public: void validateCamVvtCounters(); void updateWaveform(); + InstantRpmCalculator instantRpm; + void prepareTriggerShape() { #if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT if (triggerShape.shapeDefinitionError) { diff --git a/firmware/controllers/trigger/trigger_decoder.h b/firmware/controllers/trigger/trigger_decoder.h index 867461b77d..df6ccc39ef 100644 --- a/firmware/controllers/trigger/trigger_decoder.h +++ b/firmware/controllers/trigger/trigger_decoder.h @@ -255,12 +255,6 @@ public: angle_t syncEnginePhase(int divider, int remainder, angle_t engineCycle); - InstantRpmCalculator instantRpm; - - float getInstantRpm() const { - return instantRpm.getInstantRpm(); - } - // Returns true if syncEnginePhase has been called, // i.e. if we have enough VVT information to have full sync on // an indeterminite crank pattern