From 7fe5edf5e2dd1bcb0ef709971e45dd40ada10f8c Mon Sep 17 00:00:00 2001 From: rusefi Date: Thu, 18 May 2017 16:16:55 -0400 Subject: [PATCH] #58 --- firmware/controllers/trigger/trigger_central.h | 8 ++++++-- firmware/controllers/trigger/trigger_decoder.cpp | 2 ++ firmware/controllers/trigger/trigger_decoder.h | 14 +++++++++----- firmware/controllers/trigger/trigger_structure.cpp | 8 ++++++++ 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/firmware/controllers/trigger/trigger_central.h b/firmware/controllers/trigger/trigger_central.h index 03622ffe0d..8ca6181538 100644 --- a/firmware/controllers/trigger/trigger_central.h +++ b/firmware/controllers/trigger/trigger_central.h @@ -20,7 +20,11 @@ class Engine; #define HW_EVENT_TYPES 6 -// todo: maybe merge TriggerCentral and TriggerState classes into one class? +/** + * Maybe merge TriggerCentral and TriggerState classes into one class? + * Probably not: we have an instance of TriggerState which is used for trigger initialization, + * also composition probably better than inheritance here + */ class TriggerCentral { public: TriggerCentral(); @@ -28,7 +32,7 @@ public: void handleShaftSignal(trigger_event_e signal DECLARE_ENGINE_PARAMETER_SUFFIX); int getHwEventCounter(int index); void resetCounters(); - TriggerState triggerState; + TriggerStateWithRunningStatistics triggerState; efitick_t nowNt; angle_t vvtPosition; /** diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index 4cc5c6a306..f23d79f902 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -398,6 +398,8 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no } } + runtimeStatistics(); + if (ENGINE(sensorChartMode) == SC_RPM_ACCEL || ENGINE(sensorChartMode) == SC_DETAILED_RPM) { angle_t currentAngle = TRIGGER_SHAPE(eventAngles[currentCycle.current_index]); // todo: make this '90' depend on cylinder count? diff --git a/firmware/controllers/trigger/trigger_decoder.h b/firmware/controllers/trigger/trigger_decoder.h index 9f63770b9a..969c587d97 100644 --- a/firmware/controllers/trigger/trigger_decoder.h +++ b/firmware/controllers/trigger/trigger_decoder.h @@ -82,11 +82,6 @@ public: uint32_t prevTotalTime[PWM_PHASE_MAX_WAVE_PER_PWM]; int expectedTotalTime[PWM_PHASE_MAX_WAVE_PER_PWM]; - // we need two instances of TriggerState - // todo: re-imiplement as a sub-class to reduce memory consumption -// uint32_t timeOfLastEvent[PWM_PHASE_MAX_COUNT]; -// float instantRpmValue[PWM_PHASE_MAX_COUNT]; - /** * how many times since ECU reboot we had unexpected number of teeth in trigger cycle */ @@ -98,6 +93,8 @@ public: void reset(); void resetRunningCounters(); + virtual void runtimeStatistics(); + uint32_t runningRevolutionCounter; /** * this is start of real trigger cycle @@ -115,6 +112,13 @@ private: efitime_t prevCycleDuration; }; +class TriggerStateWithRunningStatistics : public TriggerState { +public: + uint32_t timeOfLastEvent[PWM_PHASE_MAX_COUNT]; + float instantRpmValue[PWM_PHASE_MAX_COUNT]; + virtual void runtimeStatistics(); +}; + angle_t getEngineCycle(operation_mode_e operationMode); uint32_t findTriggerZeroEventIndex(TriggerState *state, TriggerShape * shape, trigger_config_s const*triggerConfig DECLARE_ENGINE_PARAMETER_SUFFIX); diff --git a/firmware/controllers/trigger/trigger_structure.cpp b/firmware/controllers/trigger/trigger_structure.cpp index 288e9a9adc..2185be4676 100644 --- a/firmware/controllers/trigger/trigger_structure.cpp +++ b/firmware/controllers/trigger/trigger_structure.cpp @@ -205,6 +205,14 @@ void TriggerState::resetRunningCounters() { runningOrderingErrorCounter = 0; } +void TriggerState::runtimeStatistics() { + // empty base implementation +} + +void TriggerStateWithRunningStatistics::runtimeStatistics() { + // empty base implementation +} + efitime_t TriggerState::getTotalEventCounter() { return totalEventCountBase + currentCycle.current_index; }