From c8e3378ff7a86fee36a7bfcd914b58b4a4acaf22 Mon Sep 17 00:00:00 2001 From: rusefi Date: Fri, 12 Jul 2019 23:15:52 -0400 Subject: [PATCH] Annotations in C++ code to produce formulas in rusEfi console #807 typo & refactoring: splitting class --- .../controllers/algo/accel_enrichment.cpp | 28 ++++++++------ firmware/controllers/algo/accel_enrichment.h | 38 ++++++++++++------- firmware/controllers/algo/engine.h | 4 +- firmware/controllers/engine_controller.cpp | 4 +- 4 files changed, 44 insertions(+), 30 deletions(-) diff --git a/firmware/controllers/algo/accel_enrichment.cpp b/firmware/controllers/algo/accel_enrichment.cpp index 60cf486e3e..ed0f4a06fd 100644 --- a/firmware/controllers/algo/accel_enrichment.cpp +++ b/firmware/controllers/algo/accel_enrichment.cpp @@ -138,7 +138,7 @@ floatms_t WallFuel::getWallFuel(int injectorIndex) const { return wallFuel/*[injectorIndex]*/; } -int AccelEnrichmemnt::getMaxDeltaIndex(DECLARE_ENGINE_PARAMETER_SIGNATURE) { +int AccelEnrichment::getMaxDeltaIndex(DECLARE_ENGINE_PARAMETER_SIGNATURE) { int len = minI(cb.getSize(), cb.getCount()); if (len < 2) @@ -161,14 +161,14 @@ int AccelEnrichmemnt::getMaxDeltaIndex(DECLARE_ENGINE_PARAMETER_SIGNATURE) { return resultIndex; } -float AccelEnrichmemnt::getMaxDelta(DECLARE_ENGINE_PARAMETER_SIGNATURE) { +float AccelEnrichment::getMaxDelta(DECLARE_ENGINE_PARAMETER_SIGNATURE) { int index = getMaxDeltaIndex(PASS_ENGINE_PARAMETER_SIGNATURE); return (cb.get(index) - (cb.get(index - 1))); } // todo: eliminate code duplication between these two methods! Some pointer magic would help. -floatms_t AccelEnrichmemnt::getTpsEnrichment(DECLARE_ENGINE_PARAMETER_SIGNATURE) { +floatms_t TpsAccelEnrichment::getTpsEnrichment(DECLARE_ENGINE_PARAMETER_SIGNATURE) { int maxDeltaIndex = getMaxDeltaIndex(PASS_ENGINE_PARAMETER_SIGNATURE); // FuelSchedule *fs = engineConfiguration->injectionEvents; @@ -225,7 +225,7 @@ floatms_t AccelEnrichmemnt::getTpsEnrichment(DECLARE_ENGINE_PARAMETER_SIGNATURE) return extraFuel; } -float AccelEnrichmemnt::getEngineLoadEnrichment(DECLARE_ENGINE_PARAMETER_SIGNATURE) { +float LoadAccelEnrichment::getEngineLoadEnrichment(DECLARE_ENGINE_PARAMETER_SIGNATURE) { int index = getMaxDeltaIndex(PASS_ENGINE_PARAMETER_SIGNATURE); float d = (cb.get(index) - (cb.get(index - 1))) * CONFIG(specs.cylindersCount); @@ -256,13 +256,17 @@ float AccelEnrichmemnt::getEngineLoadEnrichment(DECLARE_ENGINE_PARAMETER_SIGNATU return result; } -void AccelEnrichmemnt::reset() { +void AccelEnrichment::resetAE() { cb.clear(); previousValue = NAN; +} + +void TpsAccelEnrichment::resetAE() { + AccelEnrichment::resetAE(); resetFractionValues(); } -void AccelEnrichmemnt::resetFractionValues() { +void TpsAccelEnrichment::resetFractionValues() { accumulatedValue = 0; maxExtraPerCycle = 0; maxExtraPerPeriod = 0; @@ -270,15 +274,15 @@ void AccelEnrichmemnt::resetFractionValues() { cycleCnt = 0; } -void AccelEnrichmemnt::setLength(int length) { +void AccelEnrichment::setLength(int length) { cb.setSize(length); } -void AccelEnrichmemnt::onNewValue(float currentValue DECLARE_ENGINE_PARAMETER_SUFFIX) { +void AccelEnrichment::onNewValue(float currentValue DECLARE_ENGINE_PARAMETER_SUFFIX) { cb.add(currentValue); } -void AccelEnrichmemnt::onEngineCycleTps(DECLARE_ENGINE_PARAMETER_SIGNATURE) { +void TpsAccelEnrichment::onEngineCycleTps(DECLARE_ENGINE_PARAMETER_SIGNATURE) { // we update values in handleFuel() directly //onNewValue(getTPS(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX); @@ -307,12 +311,12 @@ void AccelEnrichmemnt::onEngineCycleTps(DECLARE_ENGINE_PARAMETER_SIGNATURE) { } } -void AccelEnrichmemnt::onEngineCycle(DECLARE_ENGINE_PARAMETER_SIGNATURE) { +void LoadAccelEnrichment::onEngineCycle(DECLARE_ENGINE_PARAMETER_SIGNATURE) { onNewValue(getEngineLoadT(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX); } -AccelEnrichmemnt::AccelEnrichmemnt() { - reset(); +AccelEnrichment::AccelEnrichment() { + resetAE(); cb.setSize(4); } diff --git a/firmware/controllers/algo/accel_enrichment.h b/firmware/controllers/algo/accel_enrichment.h index 796edc0ee1..4ea471c13a 100644 --- a/firmware/controllers/algo/accel_enrichment.h +++ b/firmware/controllers/algo/accel_enrichment.h @@ -20,30 +20,40 @@ typedef Map3D tps_tps_Ma /** * this object is used for MAP rate-of-change and TPS rate-of-change corrections */ -class AccelEnrichmemnt { +class AccelEnrichment { public: - AccelEnrichmemnt(); - /** - * @return Extra engine load value for fuel logic calculation - */ - float getEngineLoadEnrichment(DECLARE_ENGINE_PARAMETER_SIGNATURE); - /** - * @return Extra fuel squirt duration for TPS acceleration - */ - floatms_t getTpsEnrichment(DECLARE_ENGINE_PARAMETER_SIGNATURE); + AccelEnrichment(); int getMaxDeltaIndex(DECLARE_ENGINE_PARAMETER_SIGNATURE); float getMaxDelta(DECLARE_ENGINE_PARAMETER_SIGNATURE); - void onEngineCycle(DECLARE_ENGINE_PARAMETER_SIGNATURE); - void onEngineCycleTps(DECLARE_ENGINE_PARAMETER_SIGNATURE); - void reset(); - void resetFractionValues(); + void resetAE(); void setLength(int length); cyclic_buffer cb; void onNewValue(float currentValue DECLARE_ENGINE_PARAMETER_SUFFIX); private: float previousValue; +}; + +class LoadAccelEnrichment : public AccelEnrichment { +public: + /** + * @return Extra engine load value for fuel logic calculation + */ + float getEngineLoadEnrichment(DECLARE_ENGINE_PARAMETER_SIGNATURE); + void onEngineCycle(DECLARE_ENGINE_PARAMETER_SIGNATURE); +}; + +class TpsAccelEnrichment : public AccelEnrichment { +public: + /** + * @return Extra fuel squirt duration for TPS acceleration + */ + floatms_t getTpsEnrichment(DECLARE_ENGINE_PARAMETER_SIGNATURE); + void onEngineCycleTps(DECLARE_ENGINE_PARAMETER_SIGNATURE); + void resetFractionValues(); + void resetAE(); +private: /** * Used for Fractional TPS enrichment. */ diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 933e1d38e7..bd446fbe19 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -178,8 +178,8 @@ public: */ angle_t engineCycle; - AccelEnrichmemnt engineLoadAccelEnrichment; - AccelEnrichmemnt tpsAccelEnrichment; + LoadAccelEnrichment engineLoadAccelEnrichment; + TpsAccelEnrichment tpsAccelEnrichment; TriggerCentral triggerCentral; diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index f3f35871c7..eb15477e2c 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -251,8 +251,8 @@ efitimesec_t getTimeNowSeconds(void) { #endif /* EFI_PROD_CODE */ static void resetAccel(void) { - engine->engineLoadAccelEnrichment.reset(); - engine->tpsAccelEnrichment.reset(); + engine->engineLoadAccelEnrichment.resetAE(); + engine->tpsAccelEnrichment.resetAE(); engine->wallFuel.resetWF(); }