From 1a3f8d8b32889d46a18fbad502861c3497df0033 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Wed, 15 Dec 2021 17:48:21 -0500 Subject: [PATCH] clutch input via CAN #3605 --- firmware/controllers/algo/engine.cpp | 24 ++++++++++++++++++------ firmware/controllers/algo/engine_state.h | 2 ++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 8fab909c32..3d7c45245d 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -312,6 +312,20 @@ void Engine::updateSlowSensors() { #endif } +static bool getClutchUpState() { + if (isBrainPinValid(engineConfiguration->clutchUpPin)) { + return engineConfiguration->clutchUpPinInverted ^ efiReadPin(engineConfiguration->clutchUpPin); + } + return engine->engineState.luaAdjustments.clutchUpState; +} + +static bool getBrakePedalState() { + if (isBrainPinValid(engineConfiguration->throttlePedalUpPin)) { + return efiReadPin(engineConfiguration->brakePedalPin); + } + return engine->engineState.luaAdjustments.brakePedalState; +} + void Engine::updateSwitchInputs() { #if EFI_GPIO_HARDWARE // this value is not used yet @@ -326,16 +340,14 @@ void Engine::updateSwitchInputs() { } engine->acSwitchState = result; } - if (isBrainPinValid(engineConfiguration->clutchUpPin)) { - engine->clutchUpState = engineConfiguration->clutchUpPinInverted ^ efiReadPin(engineConfiguration->clutchUpPin); - } + engine->clutchUpState = getClutchUpState(); + if (isBrainPinValid(engineConfiguration->throttlePedalUpPin)) { engine->idle.throttlePedalUpState = efiReadPin(engineConfiguration->throttlePedalUpPin); } - if (isBrainPinValid(engineConfiguration->brakePedalPin)) { - engine->brakePedalState = efiReadPin(engineConfiguration->brakePedalPin); - } + engine->brakePedalState = getBrakePedalState(); + #endif // EFI_GPIO_HARDWARE } diff --git a/firmware/controllers/algo/engine_state.h b/firmware/controllers/algo/engine_state.h index 52413b5040..ec3744f7c3 100644 --- a/firmware/controllers/algo/engine_state.h +++ b/firmware/controllers/algo/engine_state.h @@ -19,6 +19,8 @@ struct LuaAdjustments { float fuelAdd = 0; float fuelMult = 1; float etbTargetPositionAdd = 0; + bool clutchUpState = false; + bool brakePedalState = false; }; class EngineState : public engine_state2_s {