From 4c7e8560e0bd23f94c44319faf3d455d5263ef40 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Mon, 9 Aug 2021 16:33:06 -0400 Subject: [PATCH] refactoring: reduce magic constant --- firmware/controllers/algo/dynoview.cpp | 2 +- firmware/controllers/algo/engine.cpp | 2 +- firmware/controllers/algo/engine2.cpp | 4 ++-- firmware/controllers/sensors/map.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/firmware/controllers/algo/dynoview.cpp b/firmware/controllers/algo/dynoview.cpp index 3d78ab24bc..d13143329b 100644 --- a/firmware/controllers/algo/dynoview.cpp +++ b/firmware/controllers/algo/dynoview.cpp @@ -69,7 +69,7 @@ void DynoView::update(vssSrc src) { */ void DynoView::updateAcceleration(efitimeus_t deltaTime, float deltaSpeed) { if (deltaSpeed != 0.0) { - acceleration = ((deltaSpeed / 3.6) / (deltaTime / 1000000.0)); + acceleration = ((deltaSpeed / 3.6) / (deltaTime / US_PER_SECOND_F)); if (direction) { //decceleration acceleration *= -1; diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 2889038a6a..45131c01a3 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -623,7 +623,7 @@ float Engine::getTimeIgnitionSeconds(void) const { // return negative if the ignition is turned off if (ignitionOnTimeNt == 0) return -1; - float numSeconds = (float)NT2US(getTimeNowNt() - ignitionOnTimeNt) / 1000000.0f; + float numSeconds = (float)NT2US(getTimeNowNt() - ignitionOnTimeNt) / US_PER_SECOND_F; return numSeconds; } diff --git a/firmware/controllers/algo/engine2.cpp b/firmware/controllers/algo/engine2.cpp index 82a3b08dcd..e332b59643 100644 --- a/firmware/controllers/algo/engine2.cpp +++ b/firmware/controllers/algo/engine2.cpp @@ -128,7 +128,7 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) { // for compatibility reasons, apply only if the factor is greater than unity (only allow adding fuel) if (engineConfiguration->postCrankingFactor > 1.0f) { // convert to microsecs and then to seconds - running.timeSinceCrankingInSecs = NT2US(timeSinceCranking) / 1000000.0f; + running.timeSinceCrankingInSecs = NT2US(timeSinceCranking) / US_PER_SECOND_F; // use interpolation for correction taper running.postCrankingFuelCorrection = interpolateClamped(0.0f, engineConfiguration->postCrankingFactor, engineConfiguration->postCrankingDurationSec, 1.0f, running.timeSinceCrankingInSecs); @@ -184,7 +184,7 @@ void EngineState::updateTChargeK(int rpm, float tps DECLARE_ENGINE_PARAMETER_SUF float newTCharge = getTCharge(rpm, tps PASS_ENGINE_PARAMETER_SUFFIX); // convert to microsecs and then to seconds efitick_t curTime = getTimeNowNt(); - float secsPassed = (float)NT2US(curTime - timeSinceLastTChargeK) / 1000000.0f; + float secsPassed = (float)NT2US(curTime - timeSinceLastTChargeK) / US_PER_SECOND_F; if (!cisnan(newTCharge)) { // control the rate of change or just fill with the initial value sd.tCharge = (sd.tChargeK == 0) ? newTCharge : limitRateOfChange(newTCharge, sd.tCharge, CONFIG(tChargeAirIncrLimit), CONFIG(tChargeAirDecrLimit), secsPassed); diff --git a/firmware/controllers/sensors/map.cpp b/firmware/controllers/sensors/map.cpp index fae8f10348..879a52e69a 100644 --- a/firmware/controllers/sensors/map.cpp +++ b/firmware/controllers/sensors/map.cpp @@ -219,7 +219,7 @@ static void applyConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE) { static void digitalMapWidthCallback(void) { efitick_t nowNt = getTimeNowNt(); - mapFreq = 1000000.0 / NT2US(nowNt - prevWidthTimeNt); + mapFreq = US_PER_SECOND_F / NT2US(nowNt - prevWidthTimeNt); prevWidthTimeNt = nowNt; }