From 0badb6b2ffbb26c7338b8696a56abfc02c0a6b06 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Thu, 25 Nov 2021 04:59:31 -0800 Subject: [PATCH] AC is EngineModule (#3604) * AC is engine module * missed a spot with main relay while we're at it * TS --- firmware/console/binary/tunerstudio.cpp | 2 +- firmware/controllers/actuators/ac_control.cpp | 12 ++++++++---- firmware/controllers/actuators/ac_control.h | 9 ++++++--- firmware/controllers/algo/engine.cpp | 5 ++--- firmware/controllers/algo/engine.h | 4 +++- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/firmware/console/binary/tunerstudio.cpp b/firmware/console/binary/tunerstudio.cpp index 17237b3f3a..a98df6391d 100644 --- a/firmware/console/binary/tunerstudio.cpp +++ b/firmware/console/binary/tunerstudio.cpp @@ -245,7 +245,7 @@ static const void * getStructAddr(live_data_e structId) { case LDS_TRIGGER_STATE: return static_cast(&engine->triggerCentral.triggerState); case LDS_AC_CONTROL: - return static_cast(&engine->acState); + return static_cast(&engine->module().unmock()); case LDS_FUEL_PUMP: return static_cast(&engine->module().unmock()); #if EFI_ELECTRONIC_THROTTLE_BODY diff --git a/firmware/controllers/actuators/ac_control.cpp b/firmware/controllers/actuators/ac_control.cpp index dce9115a84..20822771e4 100644 --- a/firmware/controllers/actuators/ac_control.cpp +++ b/firmware/controllers/actuators/ac_control.cpp @@ -8,7 +8,7 @@ static Deadband<200> maxRpmDeadband; static Deadband<5> maxCltDeadband; static Deadband<5> maxTpsDeadband; -bool AcState::getAcState() { +bool AcController::getAcState() { latest_usage_ac_control = getTimeNowSeconds(); auto rpm = Sensor::getOrZero(SensorType::Rpm); @@ -51,15 +51,19 @@ bool AcState::getAcState() { return acButtonState; } -bool AcState::updateAc() { +void AcController::onSlowCallback() { bool isEnabled = getAcState(); + m_acEnabled = isEnabled; + enginePins.acRelay.setValue(isEnabled); #if EFI_TUNER_STUDIO tsOutputChannels.acSwitchState = engine->acSwitchState; tsOutputChannels.acState = isEnabled; #endif // EFI_TUNER_STUDIO - - return isEnabled; +} + +bool AcController::isAcEnabled() const { + return m_acEnabled; } diff --git a/firmware/controllers/actuators/ac_control.h b/firmware/controllers/actuators/ac_control.h index b44d9f2e12..429bd235f8 100644 --- a/firmware/controllers/actuators/ac_control.h +++ b/firmware/controllers/actuators/ac_control.h @@ -2,11 +2,14 @@ #include "ac_control_generated.h" -class AcState final : public ac_control_s { +class AcController final : public ac_control_s, public EngineModule { public: - // Returns true if AC is currently active - bool updateAc(); + void onSlowCallback() override; + + bool isAcEnabled() const; private: bool getAcState(); + + bool m_acEnabled = false; }; diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 5bed1cd016..e92e5c9988 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -232,13 +232,12 @@ void Engine::periodicSlowCallback() { runHardcodedFsio(); #endif /* EFI_FSIO */ - bool acActive = acState.updateAc(); - updateFans(acActive); - updateGppwm(); engine->engineModules.apply_all([](auto & m) { m.onSlowCallback(); }); + updateFans(module().unmock().isAcEnabled()); + #if EFI_BOOST_CONTROL updateBoostControl(); #endif // EFI_BOOST_CONTROL diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index b55834cee6..69f5935cb9 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -31,6 +31,7 @@ #include "trigger_scheduler.h" #include "fuel_pump.h" #include "main_relay.h" +#include "ac_control.h" #include "type_list.h" #include "boost_control.h" @@ -110,7 +111,7 @@ protected: class Engine final : public TriggerStateListener { public: Engine(); - AcState acState; + // todo: technical debt: enableOverdwellProtection #3553 bool enableOverdwellProtection = true; @@ -138,6 +139,7 @@ public: FuelPumpController, MainRelayController, + AcController, EngineModule // dummy placeholder so the previous entries can all have commas > engineModules;