#348 refactoring

This commit is contained in:
rusefi 2017-03-07 01:54:34 -05:00
parent 5ce35ce2d7
commit 42b709f4ef
4 changed files with 15 additions and 16 deletions

View File

@ -175,7 +175,7 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) {
currentAfr = getAfr(PASS_ENGINE_PARAMETER_F); currentAfr = getAfr(PASS_ENGINE_PARAMETER_F);
// todo: move this into slow callback, no reason for IAT corr to be here // todo: move this into slow callback, no reason for IAT corr to be here
iatFuelCorrection = getIatCorrection(iat PASS_ENGINE_PARAMETER); iatFuelCorrection = getIatFuelCorrection(iat PASS_ENGINE_PARAMETER);
// todo: move this into slow callback, no reason for CLT corr to be here // todo: move this into slow callback, no reason for CLT corr to be here
if (boardConfiguration->useWarmupPidAfr && clt < engineConfiguration->warmupAfrThreshold) { if (boardConfiguration->useWarmupPidAfr && clt < engineConfiguration->warmupAfrThreshold) {
if (rpm < 200) { if (rpm < 200) {
@ -192,10 +192,10 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) {
#endif #endif
} else { } else {
cltFuelCorrection = getCltFuelCorrection(clt PASS_ENGINE_PARAMETER); cltFuelCorrection = getCltFuelCorrection(PASS_ENGINE_PARAMETER_F);
} }
cltTimingCorrection = getCltTimingCorrection(clt PASS_ENGINE_PARAMETER); cltTimingCorrection = getCltTimingCorrection(PASS_ENGINE_PARAMETER_F);
engineNoiseHipLevel = interpolate2d(rpm, engineConfiguration->knockNoiseRpmBins, engineNoiseHipLevel = interpolate2d(rpm, engineConfiguration->knockNoiseRpmBins,
engineConfiguration->knockNoise, ENGINE_NOISE_CURVE_SIZE); engineConfiguration->knockNoise, ENGINE_NOISE_CURVE_SIZE);

View File

@ -178,20 +178,19 @@ void prepareFuelMap(DECLARE_ENGINE_PARAMETER_F) {
/** /**
* @brief Engine warm-up fuel correction. * @brief Engine warm-up fuel correction.
*/ */
float getCltFuelCorrection(float clt DECLARE_ENGINE_PARAMETER_S) { float getCltFuelCorrection(DECLARE_ENGINE_PARAMETER_F) {
if (cisnan(clt)) if (cisnan(engine->engineState.clt))
return 1; // this error should be already reported somewhere else, let's just handle it return 1; // this error should be already reported somewhere else, let's just handle it
return interpolate2d(clt, config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE) / PERCENT_MULT; return interpolate2d(engine->engineState.clt, config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE) / PERCENT_MULT;
} }
angle_t getCltTimingCorrection(float clt DECLARE_ENGINE_PARAMETER_S) { angle_t getCltTimingCorrection(DECLARE_ENGINE_PARAMETER_F) {
if (cisnan(clt)) if (cisnan(engine->engineState.clt))
return 0; // this error should be already reported somewhere else, let's just handle it return 0; // this error should be already reported somewhere else, let's just handle it
return interpolate2d(clt, engineConfiguration->cltTimingBins, engineConfiguration->cltTimingExtra, CLT_TIMING_CURVE_SIZE); return interpolate2d(engine->engineState.clt, engineConfiguration->cltTimingBins, engineConfiguration->cltTimingExtra, CLT_TIMING_CURVE_SIZE);
} }
float getIatFuelCorrection(float iat DECLARE_ENGINE_PARAMETER_S) {
float getIatCorrection(float iat DECLARE_ENGINE_PARAMETER_S) {
if (cisnan(iat)) if (cisnan(iat))
return 1; // this error should be already reported somewhere else, let's just handle it return 1; // this error should be already reported somewhere else, let's just handle it
return interpolate2d(iat, config->iatFuelCorrBins, config->iatFuelCorr, IAT_CURVE_SIZE); return interpolate2d(iat, config->iatFuelCorrBins, config->iatFuelCorr, IAT_CURVE_SIZE);

View File

@ -28,10 +28,10 @@ floatms_t getBaseTableFuel(engine_configuration_s *engineConfiguration, int rpm,
float getBaroCorrection(DECLARE_ENGINE_PARAMETER_F); float getBaroCorrection(DECLARE_ENGINE_PARAMETER_F);
int getNumberOfInjections(injection_mode_e mode DECLARE_ENGINE_PARAMETER_S); int getNumberOfInjections(injection_mode_e mode DECLARE_ENGINE_PARAMETER_S);
angle_t getinjectionOffset(float rpm DECLARE_ENGINE_PARAMETER_S); angle_t getinjectionOffset(float rpm DECLARE_ENGINE_PARAMETER_S);
float getIatCorrection(float iat DECLARE_ENGINE_PARAMETER_S); float getIatFuelCorrection(float iat DECLARE_ENGINE_PARAMETER_S);
floatms_t getInjectorLag(float vBatt DECLARE_ENGINE_PARAMETER_S); floatms_t getInjectorLag(float vBatt DECLARE_ENGINE_PARAMETER_S);
float getCltFuelCorrection(float clt DECLARE_ENGINE_PARAMETER_S); float getCltFuelCorrection(DECLARE_ENGINE_PARAMETER_F);
angle_t getCltTimingCorrection(float clt DECLARE_ENGINE_PARAMETER_S); angle_t getCltTimingCorrection(DECLARE_ENGINE_PARAMETER_F);
floatms_t getCrankingFuel(DECLARE_ENGINE_PARAMETER_F); floatms_t getCrankingFuel(DECLARE_ENGINE_PARAMETER_F);
floatms_t getCrankingFuel3(float coolantTemperature, uint32_t revolutionCounterSinceStart DECLARE_ENGINE_PARAMETER_S); floatms_t getCrankingFuel3(float coolantTemperature, uint32_t revolutionCounterSinceStart DECLARE_ENGINE_PARAMETER_S);
floatms_t getInjectionDuration(int rpm DECLARE_ENGINE_PARAMETER_S); floatms_t getInjectionDuration(int rpm DECLARE_ENGINE_PARAMETER_S);

View File

@ -88,10 +88,10 @@ void testFuelMap(void) {
setInjectorLag(0 PASS_ENGINE_PARAMETER); setInjectorLag(0 PASS_ENGINE_PARAMETER);
assertEquals(NAN, getIntakeAirTemperature(PASS_ENGINE_PARAMETER_F)); assertEquals(NAN, getIntakeAirTemperature(PASS_ENGINE_PARAMETER_F));
float iatCorrection = getIatCorrection(-KELV PASS_ENGINE_PARAMETER); float iatCorrection = getIatFuelCorrection(-KELV PASS_ENGINE_PARAMETER);
assertEqualsM("IAT", 2, iatCorrection); assertEqualsM("IAT", 2, iatCorrection);
engine->engineState.clt = getCoolantTemperature(PASS_ENGINE_PARAMETER_F); engine->engineState.clt = getCoolantTemperature(PASS_ENGINE_PARAMETER_F);
float cltCorrection = getCltFuelCorrection(engine->engineState.clt PASS_ENGINE_PARAMETER); float cltCorrection = getCltFuelCorrection(PASS_ENGINE_PARAMETER_F);
assertEqualsM("CLT", 1, cltCorrection); assertEqualsM("CLT", 1, cltCorrection);
float injectorLag = getInjectorLag(getVBatt(PASS_ENGINE_PARAMETER_F) PASS_ENGINE_PARAMETER); float injectorLag = getInjectorLag(getVBatt(PASS_ENGINE_PARAMETER_F) PASS_ENGINE_PARAMETER);
assertEqualsM("injectorLag", 0, injectorLag); assertEqualsM("injectorLag", 0, injectorLag);