refactoring: reduce magic constant

This commit is contained in:
rusefillc 2021-08-09 16:33:06 -04:00
parent f9dfcc8b9a
commit 4c7e8560e0
4 changed files with 5 additions and 5 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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);

View File

@ -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;
}