From cc74d09ba7777e073203b5a9f52982db822206c2 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Thu, 27 Jun 2024 12:53:58 -0700 Subject: [PATCH] controller does warning LED --- firmware/console/status_loop.cpp | 12 ------------ firmware/controllers/algo/engine.h | 4 ++++ firmware/controllers/engine_controller.cpp | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 90e74189f3..b52f88186a 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -280,7 +280,6 @@ class CommunicationBlinkingTask : public PeriodicTimerController { void PeriodicTask() override { counter++; - bool lowVBatt = Sensor::getOrZero(SensorType::BatteryVoltage) < LOW_VBATT; if (counter == 1) { // first invocation of BlinkingTask @@ -290,10 +289,6 @@ class CommunicationBlinkingTask : public PeriodicTimerController { setAllLeds(0); } else if (counter % 2 == 0) { enginePins.communicationLedPin.setValue(0); - - if (!lowVBatt) { - enginePins.warningLedPin.setValue(0); - } } else { #define BLINKING_PERIOD_MS 33 @@ -321,13 +316,6 @@ class CommunicationBlinkingTask : public PeriodicTimerController { } enginePins.communicationLedPin.setValue(1); - - #if EFI_ENGINE_CONTROL - if (lowVBatt || isTriggerErrorNow()) { - // todo: at the moment warning codes do not affect warning LED?! - enginePins.warningLedPin.setValue(1); - } - #endif /* EFI_ENGINE_CONTROL */ } } diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index e3ebf1ce3e..2b9c4133de 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -101,6 +101,10 @@ class IEtbController; class LedBlinkingTask : public EngineModule { public: void onSlowCallback() override; + +private: + void updateRunningLed(); + void updateWarningLed(); }; class Engine final : public TriggerStateListener { diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 545a4b4b01..3011720499 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -370,12 +370,21 @@ static void initConfigActions() { #endif /* EFI_UNIT_TEST */ void LedBlinkingTask::onSlowCallback() { + updateRunningLed(); + updateWarningLed(); +} + +void LedBlinkingTask::updateRunningLed() { #if EFI_SHAFT_POSITION_INPUT bool is_running = engine->rpmCalculator.isRunning(); #else bool is_running = false; #endif /* EFI_SHAFT_POSITION_INPUT */ + // Running -> flashing + // Stopped -> off + // Cranking -> on + if (is_running) { // blink in running mode enginePins.runningLedPin.toggle(); @@ -385,6 +394,18 @@ void LedBlinkingTask::onSlowCallback() { } } +void LedBlinkingTask::updateWarningLed() { + bool warnLedState = Sensor::getOrZero(SensorType::BatteryVoltage) < LOW_VBATT; + +#if EFI_ENGINE_CONTROL + // TODO: should this do something more intelligent? + // warnLedState |= isTriggerErrorNow(); +#endif + + // todo: at the moment warning codes do not affect warning LED?! + enginePins.warningLedPin.setValue(warnLedState); +} + // this method is used by real firmware and simulator and unit test void commonInitEngineController() { initInterpolation();