From ff864ec0bf884fba94d028e5f1eccab896ef8f14 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Thu, 14 Oct 2021 00:47:26 -0400 Subject: [PATCH] Whatever we call it, how ever we implement it - we need live data / remote view into rusEFI actual state #3353 --- firmware/controllers/actuators/ac_control.cpp | 37 +++++++++---------- firmware/controllers/actuators/ac_control.h | 11 +++++- firmware/controllers/algo/engine.cpp | 2 +- firmware/controllers/algo/engine.h | 2 + firmware/integration/rusefi_config.txt | 1 + 5 files changed, 30 insertions(+), 23 deletions(-) diff --git a/firmware/controllers/actuators/ac_control.cpp b/firmware/controllers/actuators/ac_control.cpp index 4f584f106c..b1751f7932 100644 --- a/firmware/controllers/actuators/ac_control.cpp +++ b/firmware/controllers/actuators/ac_control.cpp @@ -8,52 +8,49 @@ static Deadband<200> maxRpmDeadband; static Deadband<5> maxCltDeadband; static Deadband<5> maxTpsDeadband; -static bool getAcState(DECLARE_ENGINE_PARAMETER_SIGNATURE) { +bool AcState::getAcState(DECLARE_ENGINE_PARAMETER_SIGNATURE) { auto rpm = Sensor::getOrZero(SensorType::Rpm); - // Engine too slow, disable - if (rpm < 500) { + engineTooSlow = rpm < 500; + + if (engineTooSlow) { return false; } - // Engine too fast, disable auto maxRpm = CONFIG(maxAcRpm); - if (maxRpm != 0) { - if (maxRpmDeadband.gt(rpm, maxRpm)) { - return false; - } + engineTooFast = maxRpm != 0 && maxRpmDeadband.gt(rpm, maxRpm); + if (engineTooFast) { + return false; } auto clt = Sensor::get(SensorType::Clt); + noClt = !clt; // No AC with failed CLT - if (!clt) { + if (noClt) { return false; } // Engine too hot, disable auto maxClt = CONFIG(maxAcClt); - if (maxClt != 0) { - if (maxCltDeadband.gt(maxClt, clt.Value)) { - return false; - } + engineTooHot = (maxClt != 0) && maxCltDeadband.gt(maxClt, clt.Value); + if (engineTooHot) { + return false; } // TPS too high, disable auto maxTps = CONFIG(maxAcTps); - if (maxTps != 0) { - auto tps = Sensor::getOrZero(SensorType::Tps1); - - if (maxTpsDeadband.gt(maxTps, tps)) { + tpsTooHigh = maxTps != 0 && maxTpsDeadband.gt(maxTps, Sensor::getOrZero(SensorType::Tps1)); + if (tpsTooHigh) { return false; - } } + acButtonState = ENGINE(acSwitchState); // All conditions allow AC, simply pass thru switch - return ENGINE(acSwitchState); + return acButtonState; } -bool updateAc(DECLARE_ENGINE_PARAMETER_SIGNATURE) { +bool AcState::updateAc(DECLARE_ENGINE_PARAMETER_SIGNATURE) { bool isEnabled = getAcState(PASS_ENGINE_PARAMETER_SIGNATURE); enginePins.acRelay.setValue(isEnabled); diff --git a/firmware/controllers/actuators/ac_control.h b/firmware/controllers/actuators/ac_control.h index ad33fc6960..a3a1658901 100644 --- a/firmware/controllers/actuators/ac_control.h +++ b/firmware/controllers/actuators/ac_control.h @@ -1,6 +1,13 @@ #pragma once #include "engine_ptr.h" +#include "ac_control_generated.h" -// Returns true if AC is currently active -bool updateAc(DECLARE_ENGINE_PARAMETER_SIGNATURE); +class AcState final : public ac_control_s { +public: + // Returns true if AC is currently active + bool updateAc(DECLARE_ENGINE_PARAMETER_SIGNATURE); + +private: + bool getAcState(DECLARE_ENGINE_PARAMETER_SIGNATURE); +}; diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index aeb7449c94..fd6f63a59b 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -225,7 +225,7 @@ void Engine::periodicSlowCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) { runHardcodedFsio(PASS_ENGINE_PARAMETER_SIGNATURE); #endif /* EFI_FSIO */ - bool acActive = updateAc(PASS_ENGINE_PARAMETER_SIGNATURE); + bool acActive = acState.updateAc(PASS_ENGINE_PARAMETER_SIGNATURE); updateFans(acActive PASS_ENGINE_PARAMETER_SUFFIX); updateGppwm(); diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 73ff7026fb..0360262851 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -20,6 +20,7 @@ #include "gear_controller.h" #include "limp_manager.h" #include "pin_repository.h" +#include "ac_control.h" #if EFI_SIGNAL_EXECUTOR_ONE_TIMER // PROD real firmware uses this implementation @@ -88,6 +89,7 @@ public: DECLARE_ENGINE_PTR; Engine(); + AcState acState; bool enableOverdwellProtection = true; bool isPwmEnabled = true; int triggerActivitySecond = 0; diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 6a792958c5..a5a668d10b 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -1762,6 +1762,7 @@ end_struct #define LDS_ALTERNATOR_PID_STATE_INDEX 9 #define LDS_CJ125_PID_STATE_INDEX 10 #define LDS_TRIGGER_STATE_STATE_INDEX 11 +#define LDS_AC_STATE 12