From eb28b70d90f9d4502ceedbf9355a2bebec54c4c8 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Sun, 8 Feb 2015 18:04:13 -0600 Subject: [PATCH] auto-sync --- firmware/config/engines/subaru.cpp | 2 +- firmware/controllers/math/speed_density.cpp | 5 +++-- firmware/development/analog_chart.cpp | 13 ++++++++++++- unit_tests/test_trigger_decoder.cpp | 1 + 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/firmware/config/engines/subaru.cpp b/firmware/config/engines/subaru.cpp index aa71024dcb..db4c0db23e 100644 --- a/firmware/config/engines/subaru.cpp +++ b/firmware/config/engines/subaru.cpp @@ -22,5 +22,5 @@ void setSubaru2003Wrx(engine_configuration_s *engineConfiguration) { engineConfiguration->trigger.customTotalToothCount = 5; engineConfiguration->trigger.customSkippedToothCount = 1; - + engineConfiguration->analogChartFrequency = 2; } diff --git a/firmware/controllers/math/speed_density.cpp b/firmware/controllers/math/speed_density.cpp index a39f129bb0..4938a4a2a8 100644 --- a/firmware/controllers/math/speed_density.cpp +++ b/firmware/controllers/math/speed_density.cpp @@ -45,7 +45,7 @@ float getTCharge(int rpm, float tps, float coolantTemp, float airTemp) { #define GAS_R 0.28705 /** - * @return value in seconds + * @return per cylinder injection time, in seconds */ float sdMath(engine_configuration_s *engineConfiguration, float VE, float MAP, float AFR, float tempK) { if (MAP < 0.001 || cisnan(MAP)) { @@ -54,12 +54,13 @@ float sdMath(engine_configuration_s *engineConfiguration, float VE, float MAP, f } float injectorFlowRate = cc_minute_to_gramm_second(engineConfiguration->injector.flow); + // todo: pre-calculate cylinder displacement to save one division float Vol = engineConfiguration->specs.displacement / engineConfiguration->cylindersCount; return (Vol * VE * MAP) / (AFR * injectorFlowRate * GAS_R * tempK); } /** - * @return value in Milliseconds + * @return per cylinder injection time, in Milliseconds */ float getSpeedDensityFuel(Engine *engine, int rpm) { //int rpm = engine->rpmCalculator->rpm(); diff --git a/firmware/development/analog_chart.cpp b/firmware/development/analog_chart.cpp index 9944282558..735f02e5c9 100644 --- a/firmware/development/analog_chart.cpp +++ b/firmware/development/analog_chart.cpp @@ -26,13 +26,24 @@ void acAddData(float angle, float value) { return; // this is possible because of initialization sequence } - if (engineConfiguration->analogChartFrequency < 1) { + if (engineConfiguration->analogChartFrequency < 2) { + /** + * analog chart frequency cannot be 1 because of the way + * data flush is implemented, see below + */ //todofirmwareError() return; } if (getRevolutionCounter() % engineConfiguration->analogChartFrequency != 0) { + /** + * We are here if we do NOT need to add an event to the analog chart + */ if (pendingData) { + /** + * We are here if that's the first time we do not need to add + * data after we have added some data - meaning it's time to flush + */ // message terminator appendPrintf(&logging, DELIMETER); // output pending data diff --git a/unit_tests/test_trigger_decoder.cpp b/unit_tests/test_trigger_decoder.cpp index 21cb4b7ef2..cf6fc89eef 100644 --- a/unit_tests/test_trigger_decoder.cpp +++ b/unit_tests/test_trigger_decoder.cpp @@ -492,6 +492,7 @@ void testTriggerDecoder(void) { test1995FordInline6TriggerDecoder(); testMazdaMianaNbDecoder(); testTriggerDecoder2("testGY6_139QMB", GY6_139QMB, 0, 0.4375, 0.0); + testTriggerDecoder2("testSubary", SUBARU_2003_WRX, 0, 0.4000, 0.0); testTriggerDecoder2("testFordEscortGt", FORD_ESCORT_GT, 0, 0.8096, 0.3844); testTriggerDecoder2("testMiniCooper", MINI_COOPER_R50, 121, 0.5222, 0.4959);