From f39de8c0946bbeac56e90c68e2e7cb1ae3ed474a Mon Sep 17 00:00:00 2001 From: rusefillc Date: Tue, 19 Apr 2022 12:40:02 -0400 Subject: [PATCH] https://github.com/rusefi/alphax-2chan/issues/50 refactoring: extract method --- .../controllers/actuators/idle_thread_io.cpp | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/firmware/controllers/actuators/idle_thread_io.cpp b/firmware/controllers/actuators/idle_thread_io.cpp index e0ecfc2dd4..d1f3127e5b 100644 --- a/firmware/controllers/actuators/idle_thread_io.cpp +++ b/firmware/controllers/actuators/idle_thread_io.cpp @@ -90,6 +90,12 @@ void setManualIdleValvePosition(int positionPercent) { engineConfiguration->manIdlePosition = positionPercent; } +static void startInputPinIfValid(const char *msg, brain_pin_e pin, pin_input_mode_e mode) { + if (isBrainPinValid(pin)) { + efiSetPadMode(msg, engineConfiguration->clutchDownPin, getInputMode(mode)); + } +} + #endif /* EFI_UNIT_TEST */ percent_t getIdlePosition() { @@ -100,25 +106,13 @@ void startPedalPins() { #if EFI_PROD_CODE // this is neutral/no gear switch input. on Miata it's wired both to clutch pedal and neutral in gearbox // this switch is not used yet - if (isBrainPinValid(engineConfiguration->clutchDownPin)) { - efiSetPadMode("clutch down switch", engineConfiguration->clutchDownPin, - getInputMode(engineConfiguration->clutchDownPinMode)); - } + startInputPinIfValid("clutch down switch", engineConfiguration->clutchDownPin, engineConfiguration->clutchDownPinMode); - if (isBrainPinValid(engineConfiguration->clutchUpPin)) { - efiSetPadMode("clutch up switch", engineConfiguration->clutchUpPin, - getInputMode(engineConfiguration->clutchUpPinMode)); - } + startInputPinIfValid("clutch up switch", engineConfiguration->clutchUpPin, engineConfiguration->clutchUpPinMode); - if (isBrainPinValid(engineConfiguration->throttlePedalUpPin)) { - efiSetPadMode("throttle pedal up switch", engineConfiguration->throttlePedalUpPin, - getInputMode(engineConfiguration->throttlePedalUpPinMode)); - } + startInputPinIfValid("throttle pedal up switch", engineConfiguration->throttlePedalUpPin, engineConfiguration->throttlePedalUpPinMode); - if (isBrainPinValid(engineConfiguration->brakePedalPin)) { - efiSetPadMode("brake pedal switch", engineConfiguration->brakePedalPin, - getInputMode(engineConfiguration->brakePedalPinMode)); - } + startInputPinIfValid("brake pedal switch", engineConfiguration->brakePedalPin, engineConfiguration->brakePedalPinMode); #endif /* EFI_PROD_CODE */ }