ETB: do not touch HW pins if function not selected, this way Lua can use DC motor hardware pins directly

This commit is contained in:
Andrey 2021-11-08 12:44:37 -05:00
parent 8a963633d3
commit 2c715be4b7
2 changed files with 12 additions and 6 deletions

View File

@ -935,7 +935,14 @@ void doInitElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
bool shouldInitThrottles = Sensor::hasSensor(SensorType::AcceleratorPedalPrimary);
bool anyEtbConfigured = false;
// todo: technical debt: we still have DC motor code initialization in ETB-specific file while DC motors are used not just as ETB
// todo: rename etbFunctions to something-without-etb for same reason?
for (int i = 0 ; i < ETB_COUNT; i++) {
auto func = CONFIG(etbFunctions[i]);
if (func == ETB_None) {
// do not touch HW pins if function not selected, this way Lua can use DC motor hardware pins directly
continue;
}
auto motor = initDcMotor(engineConfiguration->etbIo[i], i, CONFIG(etb_use_two_wires) PASS_ENGINE_PARAMETER_SUFFIX);
// If this motor is actually set up, init the etb
@ -946,7 +953,6 @@ void doInitElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
continue;
}
auto func = CONFIG(etbFunctions[i]);
auto pid = getEtbPidForFunction(func PASS_ENGINE_PARAMETER_SUFFIX);
anyEtbConfigured |= controller->init(func, motor, pid, &pedal2tpsMap, shouldInitThrottles);

View File

@ -45,8 +45,8 @@ TEST(etb, initializationMissingThrottle) {
engine->etbControllers[i] = &mocks[i];
}
EXPECT_CALL(mocks[0], init(ETB_None, _, _, _, true)).WillOnce(Return(false));
EXPECT_CALL(mocks[1], init(ETB_None, _, _, _, true)).WillOnce(Return(false));
EXPECT_CALL(mocks[0], init(ETB_None, _, _, _, true)).Times(0);
EXPECT_CALL(mocks[1], init(ETB_None, _, _, _, true)).Times(0);
// Must have a sensor configured before init
Sensor::setMockValue(SensorType::AcceleratorPedal, 0, true);
@ -76,7 +76,7 @@ TEST(etb, initializationSingleThrottle) {
EXPECT_CALL(mocks[0], init(ETB_Throttle1, _, &engineConfiguration->etb, Ne(nullptr), true)).WillOnce(Return(true));
// Expect mock1 to be init as none
EXPECT_CALL(mocks[1], init(ETB_None, _, _, _, true)).WillOnce(Return(true));
EXPECT_CALL(mocks[1], init(ETB_None, _, _, _, true)).Times(0);
doInitElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE);
}
@ -98,7 +98,7 @@ TEST(etb, initializationSingleThrottleInSecondSlot) {
Sensor::setMockValue(SensorType::AcceleratorPedalPrimary, 0, false);
// Expect mock0 to be init as none
EXPECT_CALL(mocks[0], init(ETB_None, _, _, _, true)).WillOnce(Return(true));
EXPECT_CALL(mocks[0], init(ETB_None, _, _, _, true)).Times(0);
// Expect mock1 to be init as throttle 1, and PID params
EXPECT_CALL(mocks[1], init(ETB_Throttle1, _, &engineConfiguration->etb, Ne(nullptr), true)).WillOnce(Return(true));
@ -150,7 +150,7 @@ TEST(etb, initializationWastegate) {
EXPECT_CALL(mocks[0], init(ETB_Wastegate, _, &engineConfiguration->etbWastegatePid, Ne(nullptr), false)).WillOnce(Return(true));
// Expect mock1 to be init as none
EXPECT_CALL(mocks[1], init(ETB_None, _, _, _, false)).WillOnce(Return(true));
EXPECT_CALL(mocks[1], init(ETB_None, _, _, _, false)).Times(0);
doInitElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE);
}