etb function config 1 (#1881)

* this should all be safe...

* test fix
This commit is contained in:
Matthew Kennedy 2020-10-14 19:02:09 -07:00 committed by GitHub
parent 6cafebc6bd
commit 299a345c1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View File

@ -172,6 +172,8 @@ bool EtbController::init(etb_function_e function, DcMotor *motor, pid_s *pidPara
m_pid.initPidClass(pidParameters);
m_pedalMap = pedalMap;
reset();
return true;
}
@ -756,6 +758,10 @@ void setDefaultEtbParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
}
}
// Default is to run each throttle off its respective hbridge
engineConfiguration->etbFunctions[0] = ETB_Throttle1;
engineConfiguration->etbFunctions[1] = ETB_Throttle2;
engineConfiguration->etbFreq = DEFAULT_ETB_PWM_FREQUENCY;
// voltage, not ADC like with TPS
@ -831,16 +837,23 @@ void doInitElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
engine->etbActualCount = Sensor::hasSensor(SensorType::Tps2) ? 2 : 1;
bool anyEtbConfigured = false;
for (int i = 0 ; i < engine->etbActualCount; i++) {
auto motor = initDcMotor(i, CONFIG(etb_use_two_wires) PASS_ENGINE_PARAMETER_SUFFIX);
// If this motor is actually set up, init the etb
if (motor)
{
auto controller = engine->etbControllers[i];
if (!controller) {
continue;
}
// TODO: configure per-motor in config so wastegate/VW idle works
auto func = i == 0 ? ETB_Throttle1 : ETB_Throttle2;
engine->etbControllers[i]->init(func, motor, &engineConfiguration->etb, &pedal2tpsMap);
anyEtbConfigured |= controller->init(func, motor, &engineConfiguration->etb, &pedal2tpsMap);
INJECT_ENGINE_REFERENCE(engine->etbControllers[i]);
}
}
@ -858,8 +871,6 @@ void doInitElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
}
#endif /* EFI_UNIT_TEST */
etbPidReset(PASS_ENGINE_PARAMETER_SIGNATURE);
#if !EFI_UNIT_TEST
etbThread.Start();
#endif

View File

@ -47,7 +47,6 @@ TEST(etb, initializationSingleThrottle) {
// Expect mock0 to be init as throttle 1, and PID params
EXPECT_CALL(mocks[0], init(ETB_Throttle1, _, &engineConfiguration->etb, Ne(nullptr))).WillOnce(Return(true));
EXPECT_CALL(mocks[0], reset);
// We do not expect throttle #2 to be initialized
@ -72,11 +71,9 @@ TEST(etb, initializationDualThrottle) {
// Expect mock0 to be init as throttle 1, and PID params
EXPECT_CALL(mocks[0], init(ETB_Throttle1, _, &engineConfiguration->etb, Ne(nullptr))).WillOnce(Return(true));
EXPECT_CALL(mocks[0], reset);
// Expect mock1 to be init as throttle 2, and PID params
EXPECT_CALL(mocks[1], init(ETB_Throttle2, _, &engineConfiguration->etb, Ne(nullptr))).WillOnce(Return(true));
EXPECT_CALL(mocks[1], reset);
doInitElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE);
}