diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index 2e2168f367..3a472b14a9 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -62,6 +62,7 @@ uint32_t RpmCalculator::getRevolutionCounterSinceStart(void) { /** * @return -1 in case of isNoisySignal(), current RPM otherwise + * See NOISY_RPM */ // todo: migrate to float return result or add a float version? this would have with calculations int RpmCalculator::getRpm(DECLARE_ENGINE_PARAMETER_SIGNATURE) const { diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index 25a270aa3a..c620faeeb0 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -556,7 +556,7 @@ void triggerInfo(void) { #endif /* EFI_PROD_CODE || EFI_SIMULATOR */ #if EFI_PROD_CODE - if (engineConfiguration->camInput != GPIO_UNASSIGNED) { + if (HAVE_CAM_INPUT()) { scheduleMsg(logger, "VVT input: %s mode %s", hwPortname(engineConfiguration->camInput), getVvt_mode_e(engineConfiguration->vvtMode)); scheduleMsg(logger, "VVT event counters: %d/%d", vvtEventRiseCounter, vvtEventFallCounter); diff --git a/firmware/controllers/trigger/trigger_central.h b/firmware/controllers/trigger/trigger_central.h index a2726839d0..63aff6234d 100644 --- a/firmware/controllers/trigger/trigger_central.h +++ b/firmware/controllers/trigger/trigger_central.h @@ -15,6 +15,8 @@ class Engine; typedef void (*ShaftPositionListener)(trigger_event_e signal, uint32_t index DECLARE_ENGINE_PARAMETER_SUFFIX); +#define HAVE_CAM_INPUT() engineConfiguration->camInput != GPIO_UNASSIGNED + #define HW_EVENT_TYPES 6 /** diff --git a/unit_tests/engine_test_helper.h b/unit_tests/engine_test_helper.h index e7510888ed..bca182ebe2 100644 --- a/unit_tests/engine_test_helper.h +++ b/unit_tests/engine_test_helper.h @@ -33,11 +33,11 @@ public: void fireFall(int delayMs); /** - * See also #fireRise() + * See also #fireRise() which would also move time forward */ void firePrimaryTriggerRise(); /** - * See also #fireFall() + * See also #fireFall() which would also move time forward */ void firePrimaryTriggerFall(); void fireTriggerEvents(int count); diff --git a/unit_tests/tests/test_cam_vtt_input.cpp b/unit_tests/tests/test_cam_vtt_input.cpp index ffb2175cdd..0ed36f69ed 100644 --- a/unit_tests/tests/test_cam_vtt_input.cpp +++ b/unit_tests/tests/test_cam_vtt_input.cpp @@ -8,6 +8,30 @@ #include "engine_test_helper.h" TEST(sensors, testCamInput) { + // setting some weird engine + WITH_ENGINE_TEST_HELPER(FORD_ESCORT_GT); + + // and now changing to ONE trigger on CRANK with CAM/VVT + + setOperationMode(engineConfiguration, FOUR_STROKE_CRANK_SENSOR); + eth.setTriggerType(TT_ONE PASS_ENGINE_PARAMETER_SUFFIX); + engineConfiguration->useOnlyRisingEdgeForTrigger = true; + engineConfiguration->camInput = GPIOA_10; + + ASSERT_EQ( 0, GET_RPM()) << "testCamInput RPM"; + + eth.firePrimaryTriggerRise(); + eth.firePrimaryTriggerRise(); + eth.firePrimaryTriggerRise(); + eth.firePrimaryTriggerRise(); + // error condition since two events happened too quick + ASSERT_EQ(NOISY_RPM, GET_RPM()) << "testCamInput RPM should be noisy"; + eth.fireRise(50); + eth.fireRise(50); + eth.fireRise(50); + eth.fireRise(50); + eth.fireRise(50); + ASSERT_EQ(1200, GET_RPM()) << "testCamInput RPM"; }