From 4ba6cf418566b8d8e6870a126c045f6f0b100cf3 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 25 Sep 2024 03:16:53 -0400 Subject: [PATCH] only:int rpm -> float rpm --- firmware/controllers/algo/antilag_system.cpp | 8 ++++---- firmware/controllers/algo/antilag_system.h | 6 +++--- firmware/controllers/algo/engine.cpp | 2 +- .../engine_cycle/main_trigger_callback.cpp | 2 +- firmware/controllers/engine_cycle/rpm_calculator.cpp | 2 +- firmware/controllers/engine_cycle/spark_logic.cpp | 11 +++++------ firmware/controllers/engine_cycle/spark_logic.h | 4 ++-- firmware/controllers/sensors/vr_pwm.cpp | 2 +- firmware/development/logic_analyzer.cpp | 2 +- 9 files changed, 19 insertions(+), 20 deletions(-) diff --git a/firmware/controllers/algo/antilag_system.cpp b/firmware/controllers/algo/antilag_system.cpp index 5ca1b68851..79779cf1f7 100644 --- a/firmware/controllers/algo/antilag_system.cpp +++ b/firmware/controllers/algo/antilag_system.cpp @@ -32,11 +32,11 @@ bool AntilagSystemBase::isInsideALSSwitchCondition() { } } -bool AntilagSystemBase::isALSMinRPMCondition(int rpm) const { +bool AntilagSystemBase::isALSMinRPMCondition(float rpm) const { return engineConfiguration->ALSMinRPM < rpm; } -bool AntilagSystemBase::isALSMaxRPMCondition(int rpm) const { +bool AntilagSystemBase::isALSMaxRPMCondition(float rpm) const { return engineConfiguration->ALSMaxRPM > rpm; } @@ -64,7 +64,7 @@ bool AntilagSystemBase::isInsideALSTimerCondition() { return ALStime < engineConfiguration->ALSMaxDuration; } -bool AntilagSystemBase::isAntilagConditionMet(int rpm) { +bool AntilagSystemBase::isAntilagConditionMet(float rpm) { ALSMinRPMCondition = isALSMinRPMCondition(rpm); @@ -89,7 +89,7 @@ todo: looking for a hero to figure out unit test part of this } void AntilagSystemBase::update() { - int rpm = Sensor::getOrZero(SensorType::Rpm); + float rpm = Sensor::getOrZero(SensorType::Rpm); isAntilagCondition = engineConfiguration->antiLagEnabled && isAntilagConditionMet(rpm); if (!ALSMaxRPMCondition) { diff --git a/firmware/controllers/algo/antilag_system.h b/firmware/controllers/algo/antilag_system.h index 6dfddf0f95..3b1e8c3741 100644 --- a/firmware/controllers/algo/antilag_system.h +++ b/firmware/controllers/algo/antilag_system.h @@ -16,15 +16,15 @@ class AntilagSystemBase : public antilag_system_state_s { public: void update(); - bool isALSMinRPMCondition(int rpm) const; - bool isALSMaxRPMCondition(int rpm) const; + bool isALSMinRPMCondition(float rpm) const; + bool isALSMaxRPMCondition(float rpm) const; bool isALSMinCLTCondition() const; bool isALSMaxCLTCondition() const; bool isALSMaxThrottleIntentCondition() const; bool isInsideALSSwitchCondition(); bool isInsideALSTimerCondition(); /* enabled and all conditions above */ - bool isAntilagConditionMet(int rpm); + bool isAntilagConditionMet(float rpm); private: Timer ALStimer; diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 592d54d18a..0395dd6fcb 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -222,7 +222,7 @@ void Engine::updateSlowSensors() { updateSwitchInputs(); #if EFI_SHAFT_POSITION_INPUT - int rpm = Sensor::getOrZero(SensorType::Rpm); + float rpm = Sensor::getOrZero(SensorType::Rpm); triggerCentral.isEngineSnifferEnabled = rpm < engineConfiguration->engineSnifferRpmThreshold; getEngineState()->sensorChartMode = rpm < engineConfiguration->sensorSnifferRpmThreshold ? engineConfiguration->sensorChartMode : SC_OFF; diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.cpp b/firmware/controllers/engine_cycle/main_trigger_callback.cpp index c3ef3cba67..79d7aacc78 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.cpp +++ b/firmware/controllers/engine_cycle/main_trigger_callback.cpp @@ -256,7 +256,7 @@ void mainTriggerCallback(uint32_t trgEventIndex, efitick_t edgeTimestamp, angle_ } #endif // HW_CHECK_MODE - int rpm = engine->rpmCalculator.getCachedRpm(); + float rpm = engine->rpmCalculator.getCachedRpm(); if (rpm == 0) { // this happens while we just start cranking diff --git a/firmware/controllers/engine_cycle/rpm_calculator.cpp b/firmware/controllers/engine_cycle/rpm_calculator.cpp index 8cd98cd0a2..0f8f09f1cd 100644 --- a/firmware/controllers/engine_cycle/rpm_calculator.cpp +++ b/firmware/controllers/engine_cycle/rpm_calculator.cpp @@ -374,7 +374,7 @@ void tdcMarkCallback( // two instances of scheduling_s are needed to properly handle event overlap int revIndex2 = getRevolutionCounter() % 2; - int rpm = Sensor::getOrZero(SensorType::Rpm); + float rpm = Sensor::getOrZero(SensorType::Rpm); // todo: use tooth event-based scheduling, not just time-based scheduling if (isValidRpm(rpm)) { angle_t tdcPosition = tdcPosition(); diff --git a/firmware/controllers/engine_cycle/spark_logic.cpp b/firmware/controllers/engine_cycle/spark_logic.cpp index 9971300320..9fc7e149ea 100644 --- a/firmware/controllers/engine_cycle/spark_logic.cpp +++ b/firmware/controllers/engine_cycle/spark_logic.cpp @@ -380,7 +380,7 @@ void turnSparkPinHighStartCharging(IgnitionEvent *event) { #endif static void scheduleSparkEvent(bool limitedSpark, IgnitionEvent *event, - int rpm, float dwellMs, float dwellAngle, float sparkAngle, efitick_t edgeTimestamp, float currentPhase, float nextPhase) { + float rpm, float dwellMs, float dwellAngle, float sparkAngle, efitick_t edgeTimestamp, float currentPhase, float nextPhase) { float angleOffset = dwellAngle - currentPhase; if (angleOffset < 0) { @@ -529,11 +529,10 @@ static void prepareIgnitionSchedule() { initializeIgnitionActions(); } -void onTriggerEventSparkLogic(int rpm, efitick_t edgeTimestamp, float currentPhase, float nextPhase) { +void onTriggerEventSparkLogic(float rpm, efitick_t edgeTimestamp, float currentPhase, float nextPhase) { ScopePerf perf(PE::OnTriggerEventSparkLogic); - if (!isValidRpm(rpm) || !engineConfiguration->isIgnitionEnabled) { - // this might happen for instance in case of a single trigger event after a pause + if (!engineConfiguration->isIgnitionEnabled) { return; } @@ -545,7 +544,7 @@ void onTriggerEventSparkLogic(int rpm, efitick_t edgeTimestamp, float currentPha const floatms_t dwellMs = engine->ignitionState.sparkDwell; if (std::isnan(dwellMs) || dwellMs <= 0) { - warning(ObdCode::CUSTOM_DWELL, "invalid dwell to handle: %.2f at %d", dwellMs, rpm); + warning(ObdCode::CUSTOM_DWELL, "invalid dwell to handle: %.2f", dwellMs); return; } @@ -666,7 +665,7 @@ int getNumberOfSparks(ignition_mode_e mode) { /** * @see getInjectorDutyCycle */ -percent_t getCoilDutyCycle(int rpm) { +percent_t getCoilDutyCycle(float rpm) { floatms_t totalPerCycle = engine->ignitionState.sparkDwell * getNumberOfSparks(getCurrentIgnitionMode()); floatms_t engineCycleDuration = getCrankshaftRevolutionTimeMs(rpm) * (getEngineRotationState()->getOperationMode() == TWO_STROKE ? 1 : 2); return 100 * totalPerCycle / engineCycleDuration; diff --git a/firmware/controllers/engine_cycle/spark_logic.h b/firmware/controllers/engine_cycle/spark_logic.h index c4b5eeeb4e..31fae3b2a3 100644 --- a/firmware/controllers/engine_cycle/spark_logic.h +++ b/firmware/controllers/engine_cycle/spark_logic.h @@ -7,11 +7,11 @@ #pragma once -void onTriggerEventSparkLogic(int rpm, efitick_t edgeTimestamp, float currentPhase, float nextPhase); +void onTriggerEventSparkLogic(float rpm, efitick_t edgeTimestamp, float currentPhase, float nextPhase); void turnSparkPinHighStartCharging(IgnitionEvent *event); void fireSparkAndPrepareNextSchedule(IgnitionEvent *event); int getNumberOfSparks(ignition_mode_e mode); // fact: getInjectorDutyCycle is used by limpManager as cut reason but coil duty cycle is only logged not considered for control strategy // see also maxAllowedDwellAngle which only produces a warning without cutting spark -percent_t getCoilDutyCycle(int rpm); +percent_t getCoilDutyCycle(float rpm); void initializeIgnitionActions(); diff --git a/firmware/controllers/sensors/vr_pwm.cpp b/firmware/controllers/sensors/vr_pwm.cpp index 2d56e4cab5..45c169cc2c 100644 --- a/firmware/controllers/sensors/vr_pwm.cpp +++ b/firmware/controllers/sensors/vr_pwm.cpp @@ -10,7 +10,7 @@ static SimplePwm pwms[VR_THRESHOLD_COUNT]; #define VR_SUPPLY_VOLTAGE 3.3f #endif -static void updateVrThresholdPwm(int rpm, size_t index) { +static void updateVrThresholdPwm(float rpm, size_t index) { auto& cfg = engineConfiguration->vrThreshold[index]; if (!isBrainPinValid(cfg.pin)) { diff --git a/firmware/development/logic_analyzer.cpp b/firmware/development/logic_analyzer.cpp index 7dcae96387..33096ea98c 100644 --- a/firmware/development/logic_analyzer.cpp +++ b/firmware/development/logic_analyzer.cpp @@ -212,7 +212,7 @@ static void reportWave(Logging *logging, int index) { logging->appendPrintf("%s", LOG_DELIMITER); efitimeus_t offsetUs = getWaveOffset(index); - int rpm = Sensor::getOrZero(SensorType::Rpm); + float rpm = Sensor::getOrZero(SensorType::Rpm); if (rpm != 0) { float oneDegreeUs = getOneDegreeTimeUs(rpm);