diff --git a/firmware/controllers/engine_cycle/fuel_schedule.cpp b/firmware/controllers/engine_cycle/fuel_schedule.cpp index 7afb101354..83ca872bf3 100644 --- a/firmware/controllers/engine_cycle/fuel_schedule.cpp +++ b/firmware/controllers/engine_cycle/fuel_schedule.cpp @@ -129,8 +129,15 @@ bool InjectionEvent::updateInjectionAngle() { */ bool FuelSchedule::addFuelEventsForCylinder(int i) { InjectionEvent *ev = &elements[i]; +#if EFU_UNIT_TEST + if (ev->ownIndex != i) + throw std::logic_error("index issue"); +#endif + return ev->update(); +} - bool updatedAngle = ev->updateInjectionAngle(); +bool InjectionEvent::update() { + bool updatedAngle = updateInjectionAngle(); if (!updatedAngle) { return false; @@ -145,7 +152,7 @@ bool FuelSchedule::addFuelEventsForCylinder(int i) { injectorIndex = 0; } else if (mode == IM_SEQUENTIAL || mode == IM_BATCH) { // Map order index -> cylinder index (firing order) - injectorIndex = getCylinderId(i) - 1; + injectorIndex = getCylinderId(ownIndex) - 1; } else { firmwareError(ObdCode::CUSTOM_OBD_UNEXPECTED_INJECTION_MODE, "Unexpected injection mode %d", mode); injectorIndex = 0; @@ -160,7 +167,7 @@ bool FuelSchedule::addFuelEventsForCylinder(int i) { // Compute the position of this cylinder's twin in the firing order // Each injector gets fired as a primary (the same as sequential), but also // fires the injector 360 degrees later in the firing order. - int secondOrder = (i + (engineConfiguration->cylindersCount / 2)) % engineConfiguration->cylindersCount; + int secondOrder = (ownIndex + (engineConfiguration->cylindersCount / 2)) % engineConfiguration->cylindersCount; int secondIndex = getCylinderId(secondOrder) - 1; secondOutput = &enginePins.injectors[secondIndex]; } else { @@ -168,13 +175,12 @@ bool FuelSchedule::addFuelEventsForCylinder(int i) { } InjectorOutputPin *output = &enginePins.injectors[injectorIndex]; - bool isSimultaneous = mode == IM_SIMULTANEOUS; - ev->outputs[0] = output; - ev->outputs[1] = secondOutput; - ev->isSimultaneous = isSimultaneous; + outputs[0] = output; + outputs[1] = secondOutput; + isSimultaneous = mode == IM_SIMULTANEOUS; // Stash the cylinder number so we can select the correct fueling bank later - ev->cylinderNumber = injectorIndex; + cylinderNumber = injectorIndex; if (!isSimultaneous && !output->isInitialized()) { // todo: extract method for this index math diff --git a/firmware/controllers/engine_cycle/fuel_schedule.h b/firmware/controllers/engine_cycle/fuel_schedule.h index 571fddce89..d734624acd 100644 --- a/firmware/controllers/engine_cycle/fuel_schedule.h +++ b/firmware/controllers/engine_cycle/fuel_schedule.h @@ -18,6 +18,8 @@ class InjectionEvent { public: InjectionEvent(); + bool update(); + // Update the injection start angle bool updateInjectionAngle();