From d671f569c347d156046bfa15d830d61848bfe1fe Mon Sep 17 00:00:00 2001 From: rusefi Date: Sat, 19 Jan 2019 11:28:37 -0500 Subject: [PATCH] #35 progress --- firmware/hw_layer/HIP9011.cpp | 2 -- firmware/hw_layer/HIP9011_logic.cpp | 25 +++++++++---------------- firmware/hw_layer/HIP9011_logic.h | 20 ++++++++++---------- unit_tests/tests/test_hip9011.cpp | 4 +--- 4 files changed, 20 insertions(+), 31 deletions(-) diff --git a/firmware/hw_layer/HIP9011.cpp b/firmware/hw_layer/HIP9011.cpp index f69ccfe472..e45d798e25 100644 --- a/firmware/hw_layer/HIP9011.cpp +++ b/firmware/hw_layer/HIP9011.cpp @@ -299,8 +299,6 @@ void hipAdcCallback(adcsample_t adcValue) { hipValueMax = maxF(engine->knockVolts, hipValueMax); engine->knockLogic(engine->knockVolts); - instance.setAngleWindowWidth(); - instance.handleValue(GET_RPM() DEFINE_PARAM_SUFFIX(PASS_HIP_PARAMS)); } diff --git a/firmware/hw_layer/HIP9011_logic.cpp b/firmware/hw_layer/HIP9011_logic.cpp index 30e2681b1b..8035cca14f 100644 --- a/firmware/hw_layer/HIP9011_logic.cpp +++ b/firmware/hw_layer/HIP9011_logic.cpp @@ -9,22 +9,7 @@ EXTERN_ENGINE; -HIP9011::HIP9011(Hip9011HardwareInterface *hardware) { - needToInit = true; - state = NOT_READY; - /** - * band index is only send to HIP chip on startup - */ - currentBandIndex = 0; - currentGainIndex = -1; - currentIntergratorIndex = -1; - settingUpdateCount = 0; - totalKnockEventsCount = 0; - currentPrescaler = 0; - correctResponsesCount = 0; - invalidHip9011ResponsesCount = 0; - angleWindowWidth = -1; - +HIP9011::HIP9011(Hip9011HardwareInterface *hardware) : rpmLookup() { this->hardware = hardware; } @@ -80,6 +65,12 @@ int HIP9011::getIntegrationIndexByRpm(float rpm) { void HIP9011::setAngleWindowWidth(DEFINE_HIP_PARAMS) { float angleWindowWidth = GET_CONFIG_VALUE(knockDetectionWindowEnd) - GET_CONFIG_VALUE(knockDetectionWindowStart); + if (angleWindowWidth < 0) { +#if EFI_PROD_CODE + warning(CUSTOM_ERR_6697, "invalid knock window"); +#endif + angleWindowWidth = 0; + } // float '==' is totally appropriate here if (this->angleWindowWidth == angleWindowWidth) return; // exit if value has not change @@ -88,6 +79,8 @@ void HIP9011::setAngleWindowWidth(DEFINE_HIP_PARAMS) { } void HIP9011::handleValue(int rpm DEFINE_PARAM_SUFFIX(DEFINE_HIP_PARAMS)) { + setAngleWindowWidth(FORWARD_HIP_PARAMS); + int prescalerIndex = GET_CONFIG_VALUE(hip9011PrescalerAndSDO); int integratorIndex = getIntegrationIndexByRpm(rpm); int gainIndex = getHip9011GainIndex(FORWARD_HIP_PARAMS); diff --git a/firmware/hw_layer/HIP9011_logic.h b/firmware/hw_layer/HIP9011_logic.h index 13d4c31893..bdd432795e 100644 --- a/firmware/hw_layer/HIP9011_logic.h +++ b/firmware/hw_layer/HIP9011_logic.h @@ -67,17 +67,17 @@ public: /** * band index is only send to HIP chip on startup */ - int currentBandIndex; - int currentGainIndex; - int correctResponsesCount; - int invalidHip9011ResponsesCount; - float angleWindowWidth; + int currentBandIndex = 0; + int currentGainIndex = -1; + int correctResponsesCount = 0; + int invalidHip9011ResponsesCount = 0; + float angleWindowWidth = - 1; - int currentIntergratorIndex; - bool needToInit; - int settingUpdateCount; - int totalKnockEventsCount; - int currentPrescaler; + int currentIntergratorIndex = -1; + bool needToInit = true; + int settingUpdateCount = 0; + int totalKnockEventsCount = 0; + int currentPrescaler = 0; Hip9011HardwareInterface *hardware; /** * Int/Hold pin is controlled from scheduler call-backs which are set according to current RPM diff --git a/unit_tests/tests/test_hip9011.cpp b/unit_tests/tests/test_hip9011.cpp index 54822bdca3..cbf6fe84f3 100644 --- a/unit_tests/tests/test_hip9011.cpp +++ b/unit_tests/tests/test_hip9011.cpp @@ -60,10 +60,8 @@ TEST(hip9011, configurationCommands) { HIP9011 instance(&mock); - instance.prepareHip9011RpmLookup(50); - // want to invoke method with same parameters a few times -#define PARAMETERS 600, /* knockBandCustom*/0, /*cylinderBore*/76, /*hip9011Gain*/1, _8MHZ_PRESCALER, NAN, NAN +#define PARAMETERS 600, /* knockBandCustom*/0, /*cylinderBore*/76, /*hip9011Gain*/1, _8MHZ_PRESCALER, 0.0, 50.0 // Not making assumptions on the message send ... EXPECT_CALL(mock, sendSyncCommand(_)).Times(0);