From 1c0d38abef68e4c7ef2faaf3a799364e1dca70c5 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Sun, 18 Aug 2019 15:53:38 -0400 Subject: [PATCH] new feature: check engine light to blink on trigger synchronization --- .../actuators/malfunction_indicator.cpp | 12 ++++++++++-- firmware/controllers/algo/rusefi_types.h | 2 ++ firmware/controllers/engine_controller.cpp | 2 +- firmware/controllers/math/engine_math.h | 2 +- .../controllers/trigger/trigger_decoder.cpp | 19 ++++++++++++++++--- .../controllers/trigger/trigger_decoder.h | 2 ++ 6 files changed, 32 insertions(+), 7 deletions(-) diff --git a/firmware/controllers/actuators/malfunction_indicator.cpp b/firmware/controllers/actuators/malfunction_indicator.cpp index 12f2572c3f..83684c0256 100644 --- a/firmware/controllers/actuators/malfunction_indicator.cpp +++ b/firmware/controllers/actuators/malfunction_indicator.cpp @@ -45,6 +45,7 @@ EXTERN_ENGINE; static void blink_digits(int digit, int duration) { for (int iter = 0; iter < digit; iter++) { + // todo: why we set LOW and then HIGH? not the other way around? enginePins.checkEnginePin.setValue(0); chThdSleepMilliseconds(duration); enginePins.checkEnginePin.setValue(1); @@ -85,8 +86,15 @@ public: private: void PeriodicTask(efitime_t nowNt) override { UNUSED(nowNt); - static error_codes_set_s localErrorCopy; + if (nowNt - engine->triggerCentral.triggerState.mostRecentSyncTime < US2NT(MS2US(500))) { + enginePins.checkEnginePin.setValue(1); + chThdSleepMilliseconds(500); + enginePins.checkEnginePin.setValue(0); + } + + static error_codes_set_s localErrorCopy; + // todo: why do I not see this on a real vehicle? is this whole blinking logic not used? getErrorCodes(&localErrorCopy); for (int p = 0; p < localErrorCopy.count; p++) { // Calculate how many digits in this integer and display error code from start to end @@ -113,7 +121,7 @@ void initMalfunctionIndicator(void) { if (!isMilEnabled()) { return; } - instance.setPeriod(10); + instance.setPeriod(10 /*ms*/); instance.Start(); #if TEST_MIL_CODE diff --git a/firmware/controllers/algo/rusefi_types.h b/firmware/controllers/algo/rusefi_types.h index 11a982d1fa..578bc0bd83 100644 --- a/firmware/controllers/algo/rusefi_types.h +++ b/firmware/controllers/algo/rusefi_types.h @@ -45,6 +45,8 @@ typedef int pid_dt; * is actually after timeNow() due to interrupt context switches * * See getTimeNowNt() + * See US2NT + * See MS2US */ typedef int64_t efitime_t; diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 64c495167a..c0e340351e 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -812,6 +812,6 @@ int getRusEfiVersion(void) { if (initBootloader() != 0) return 123; #endif /* EFI_BOOTLOADER_INCLUDE_CODE */ - return 20190817; + return 20190818; } #endif /* EFI_UNIT_TEST */ diff --git a/firmware/controllers/math/engine_math.h b/firmware/controllers/math/engine_math.h index 0761a5057a..be87d84adc 100644 --- a/firmware/controllers/math/engine_math.h +++ b/firmware/controllers/math/engine_math.h @@ -67,4 +67,4 @@ void setSingleCoilDwell(engine_configuration_s *engineConfiguration); // expectation is that for well-known triggers CONFIG(globalTriggerAngleOffset) would usually be zero // while for toothed wheels user would have to provide a value #define tdcPosition() \ - (ENGINE(triggerCentral.triggerShape.tdcPosition) + CONFIG(globalTriggerAngleOffset)) + (TRIGGER_SHAPE(tdcPosition) + CONFIG(globalTriggerAngleOffset)) diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index 98929952f4..b9c404ac28 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -38,9 +38,22 @@ TriggerState::TriggerState() { resetTriggerState(); } +void TriggerState::setShaftSynchronized(bool value) { + if (value) { + if (!shaft_is_synchronized) { + // just got synchronized + mostRecentSyncTime = getTimeNowNt(); + } + } else { + // sync loss + mostRecentSyncTime = 0; + } + shaft_is_synchronized = value; +} + void TriggerState::resetTriggerState() { triggerCycleCallback = NULL; - shaft_is_synchronized = false; + setShaftSynchronized(false); toothed_previous_time = 0; memset(toothDurations, 0, sizeof(toothDurations)); @@ -316,7 +329,7 @@ bool TriggerState::isEvenRevolution() const { } void TriggerState::onSynchronizationLost(DECLARE_ENGINE_PARAMETER_SIGNATURE) { - shaft_is_synchronized = false; + setShaftSynchronized(false); // Needed for early instant-RPM detection engine->rpmCalculator.setStopSpinning(PASS_ENGINE_PARAMETER_SIGNATURE); } @@ -369,7 +382,7 @@ void TriggerState::handleTriggerError(DECLARE_ENGINE_PARAMETER_SIGNATURE) { } void TriggerState::onShaftSynchronization(efitime_t nowNt, trigger_wheel_e triggerWheel DECLARE_ENGINE_PARAMETER_SUFFIX) { - shaft_is_synchronized = true; + setShaftSynchronized(true); // this call would update duty cycle values nextTriggerEvent() ; diff --git a/firmware/controllers/trigger/trigger_decoder.h b/firmware/controllers/trigger/trigger_decoder.h index 0f87132e0c..925d341197 100644 --- a/firmware/controllers/trigger/trigger_decoder.h +++ b/firmware/controllers/trigger/trigger_decoder.h @@ -76,6 +76,7 @@ public: * TRUE if we know where we are */ bool shaft_is_synchronized; + efitime_t mostRecentSyncTime; efitick_t lastDecodingErrorTime; // the boolean flag is a performance optimization so that complex comparison is avoided if no error @@ -99,6 +100,7 @@ public: uint32_t orderingErrorCounter; void resetTriggerState(); + void setShaftSynchronized(bool value); #if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT virtual void runtimeStatistics(efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);