migrate amazing idle from FSIO to less opaque TS #1581

This commit is contained in:
rusefi 2020-07-08 01:12:08 -04:00
parent e0535c7298
commit 720ade2319
3 changed files with 17 additions and 12 deletions

View File

@ -82,13 +82,13 @@ public:
Engine *engine = unitTestEngine; Engine *engine = unitTestEngine;
EXPAND_Engine; EXPAND_Engine;
#endif #endif
float result = parameters->offset;
#if EFI_FSIO #if EFI_FSIO
if (engineConfiguration->useFSIO12ForIdleOffset) { if (engineConfiguration->useFSIO12ForIdleOffset) {
return ENGINE(fsioState.fsioIdleOffset); return result + ENGINE(fsioState.fsioIdleOffset);
} }
#endif /* EFI_FSIO */ #endif /* EFI_FSIO */
return parameters->offset; return result;
} }
float getMinValue() const override { float getMinValue() const override {
@ -96,23 +96,27 @@ public:
Engine *engine = unitTestEngine; Engine *engine = unitTestEngine;
EXPAND_Engine; EXPAND_Engine;
#endif #endif
float result = parameters->minValue;
#if EFI_FSIO #if EFI_FSIO
if (engineConfiguration->useFSIO13ForIdleMinValue) { if (engineConfiguration->useFSIO13ForIdleMinValue) {
return ENGINE(fsioState.fsioIdleMinValue); return result + ENGINE(fsioState.fsioIdleMinValue);
} }
#endif /* EFI_FSIO */ #endif /* EFI_FSIO */
return parameters->minValue; return result;
} }
}; };
PidWithOverrides idlePid; PidWithOverrides idlePid;
#endif /* EFI_IDLE_PID_CIC */ #endif /* EFI_IDLE_PID_CIC */
float getIdlePidOffset() { float getIdlePidOffset() {
return idlePid.getOffset(); return idlePid.getOffset();
} }
float getIdlePidMinValue() {
return idlePid.getMinValue();
}
// todo: extract interface for idle valve hardware, with solenoid and stepper implementations? // todo: extract interface for idle valve hardware, with solenoid and stepper implementations?
static SimplePwm idleSolenoidOpen("idle open"); static SimplePwm idleSolenoidOpen("idle open");
static SimplePwm idleSolenoidClose("idle close"); static SimplePwm idleSolenoidClose("idle close");

View File

@ -37,3 +37,4 @@ void initIdleHardware(DECLARE_ENGINE_PARAMETER_SIGNATURE);
bool isIdleHardwareRestartNeeded(); bool isIdleHardwareRestartNeeded();
void onConfigurationChangeIdleCallback(engine_configuration_s *previousConfiguration); void onConfigurationChangeIdleCallback(engine_configuration_s *previousConfiguration);
float getIdlePidOffset(); float getIdlePidOffset();
float getIdlePidMinValue();

View File

@ -27,16 +27,16 @@ TEST(idle, fsioPidParameters) {
unitTestEngine = engine; unitTestEngine = engine;
engineConfiguration->idleRpmPid.offset = 40; engineConfiguration->idleRpmPid.offset = 40;
engineConfiguration->idleRpmPid2.offset = 50; engineConfiguration->acIdleExtraOffset = 10;
engineConfiguration->idleRpmPid.minValue = 30; engineConfiguration->idleRpmPid.minValue = 30;
engineConfiguration->idleRpmPid2.minValue = 60; engineConfiguration->acIdleExtraMin = 30;
engineConfiguration->useFSIO12ForIdleOffset = true; engineConfiguration->useFSIO12ForIdleOffset = true;
setFsioExpression(QUOTE(MAGIC_OFFSET_FOR_IDLE_OFFSET), "ac_on_switch cfg_idleRpmPid_offset cfg_idleRpmPid2_offset if" PASS_ENGINE_PARAMETER_SUFFIX); setFsioExpression(QUOTE(MAGIC_OFFSET_FOR_IDLE_OFFSET), "ac_on_switch 0 cfg_acIdleExtraOffset if" PASS_ENGINE_PARAMETER_SUFFIX);
engineConfiguration->useFSIO13ForIdleMinValue = true; engineConfiguration->useFSIO13ForIdleMinValue = true;
setFsioExpression(QUOTE(MAGIC_OFFSET_FOR_IDLE_MIN_VALUE), "ac_on_switch cfg_idleRpmPid_minValue cfg_idleRpmPid2_minValue if" PASS_ENGINE_PARAMETER_SUFFIX); setFsioExpression(QUOTE(MAGIC_OFFSET_FOR_IDLE_MIN_VALUE), "ac_on_switch 0 cfg_acIdleExtraMin if" PASS_ENGINE_PARAMETER_SUFFIX);
ASSERT_EQ(1, hasAcToggle(PASS_ENGINE_PARAMETER_SIGNATURE)); ASSERT_EQ(1, hasAcToggle(PASS_ENGINE_PARAMETER_SIGNATURE));
setMockVoltage(engineConfiguration->acSwitchAdc, 0 PASS_ENGINE_PARAMETER_SUFFIX); setMockVoltage(engineConfiguration->acSwitchAdc, 0 PASS_ENGINE_PARAMETER_SUFFIX);
@ -44,14 +44,14 @@ TEST(idle, fsioPidParameters) {
eth.engine.periodicSlowCallback(PASS_ENGINE_PARAMETER_SIGNATURE); eth.engine.periodicSlowCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
ASSERT_EQ(40, getIdlePidOffset()); ASSERT_EQ(40, getIdlePidOffset());
ASSERT_EQ(30, ENGINE(fsioState.fsioIdleMinValue)); ASSERT_EQ(30, getIdlePidMinValue());
setMockVoltage(engineConfiguration->acSwitchAdc, 5 PASS_ENGINE_PARAMETER_SUFFIX); setMockVoltage(engineConfiguration->acSwitchAdc, 5 PASS_ENGINE_PARAMETER_SUFFIX);
ASSERT_EQ(0, getAcToggle(PASS_ENGINE_PARAMETER_SIGNATURE)); ASSERT_EQ(0, getAcToggle(PASS_ENGINE_PARAMETER_SIGNATURE));
eth.engine.periodicSlowCallback(PASS_ENGINE_PARAMETER_SIGNATURE); eth.engine.periodicSlowCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
ASSERT_EQ(50, getIdlePidOffset()); ASSERT_EQ(50, getIdlePidOffset());
ASSERT_EQ(60, ENGINE(fsioState.fsioIdleMinValue)); ASSERT_EQ(60, getIdlePidMinValue());
// todo finish this unit test! // todo finish this unit test!