diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 2b1ac8b6df..f0f388aa9d 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -122,10 +122,14 @@ public: /** * pre-calculated offset for given sequence index within engine cycle - * not cylinder ID + * (not cylinder ID) * todo: better name? */ - float angleExtra[IGNITION_PIN_COUNT]; + angle_t angleExtra[IGNITION_PIN_COUNT]; + /** + * pre-calculated reference to which output pin should be used for + * given sequence index within engine cycle + */ NamedOutputPin *ignitionPin[IGNITION_PIN_COUNT]; void onTriggerEvent(uint64_t nowNt); diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index 948eb7659f..951158d93b 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -102,7 +102,7 @@ void initializeIgnitionActions(angle_t advance, angle_t dwellAngle, list->reset(); for (int i = 0; i < CONFIG(specs.cylindersCount); i++) { - float localAdvance = advance + ENGINE(angleExtra[i]); + angle_t localAdvance = advance + ENGINE(angleExtra[i]); NamedOutputPin *output = ENGINE(ignitionPin[i]); IgnitionEvent *event = list->add(); @@ -145,7 +145,6 @@ void FuelSchedule::registerInjectionEvent(OutputSignalList *sourceList, NamedOut } FuelSchedule::FuelSchedule() { - clear(); } void FuelSchedule::clear() { @@ -153,6 +152,7 @@ void FuelSchedule::clear() { } void FuelSchedule::addFuelEvents(OutputSignalList *sourceList, injection_mode_e mode DECLARE_ENGINE_PARAMETER_S) { + clear(); // this method is relatively heavy sourceList->reset(); events.reset(); diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index 05909208d2..c548aa8449 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -278,7 +278,7 @@ void showMainHistogram(void) { #endif } -static void doSomeCalc(int rpm DECLARE_ENGINE_PARAMETER_S) { +static void ignitionCalc(int rpm DECLARE_ENGINE_PARAMETER_S) { /** * Within one engine cycle all cylinders are fired with same timing advance. * todo: one day we can control cylinders individually? @@ -340,7 +340,7 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t eventIndex DECL if (eventIndex == engineConfiguration->ignMathCalculateAtIndex) { engine->beforeIgnitionMath = GET_TIMESTAMP(); - doSomeCalc(rpm PASS_ENGINE_PARAMETER); + ignitionCalc(rpm PASS_ENGINE_PARAMETER); engine->ignitionMathTime = GET_TIMESTAMP() - engine->beforeIgnitionMath; } diff --git a/firmware/controllers/trigger/trigger_structure.h b/firmware/controllers/trigger/trigger_structure.h index 4099b551f5..ce6bbaca5e 100644 --- a/firmware/controllers/trigger/trigger_structure.h +++ b/firmware/controllers/trigger/trigger_structure.h @@ -52,7 +52,7 @@ public: * that's the angle distance from trigger event #0 and actual engine TDC * see also globalTriggerAngleOffset */ - float tdcPosition; + angle_t tdcPosition; /** * Should we use falls or rises for gap ratio detection? diff --git a/java_console/autotest/src/com/rusefi/TestingUtils.java b/java_console/autotest/src/com/rusefi/TestingUtils.java index 714e0fc89f..7fe1029b8b 100644 --- a/java_console/autotest/src/com/rusefi/TestingUtils.java +++ b/java_console/autotest/src/com/rusefi/TestingUtils.java @@ -49,6 +49,14 @@ public class TestingUtils { } static void assertWave(String msg, WaveChart chart, String key, double width, double... expectedAngles) { + assertWave(true, msg, chart, key, width, expectedAngles); + } + + static void assertWaveFall(String msg, WaveChart chart, String key, double width, double... expectedAngles) { + assertWave(false, msg, chart, key, width, expectedAngles); + } + + static void assertWave(boolean rise, String msg, WaveChart chart, String key, double width, double... expectedAngles) { RevolutionLog revolutionLog = chart.getRevolutionsLog(); if (revolutionLog.keySet().isEmpty()) throw new IllegalStateException(msg + " Empty revolutions in " + chart); @@ -58,8 +66,9 @@ public class TestingUtils { List wr = WaveReport.parse(events.toString()); assertTrue(msg + " waves for " + key, !wr.isEmpty()); for (WaveReport.UpDown ud : wr) { - double angleByTime = revolutionLog.getCrankAngleByTime(ud.upTime); - assertCloseEnough(msg + " angle for " + key + "@" + ud.upTime, angleByTime, expectedAngles); + int eventTime = rise ? ud.upTime : ud.downTime; + double angleByTime = revolutionLog.getCrankAngleByTime(eventTime); + assertCloseEnough(msg + " angle for " + key + "@" + eventTime, angleByTime, expectedAngles); assertCloseEnough(msg + "width for " + key, ud.getDutyCycle(revolutionLog), width); }