From 4e32f3907058752edc806d7a140e0f0dd46a1c22 Mon Sep 17 00:00:00 2001 From: rusefi Date: Fri, 13 Oct 2023 00:17:06 -0400 Subject: [PATCH] only:minor encapsulation --- .../engine_cycle/fuel_schedule.cpp | 20 +++++++++---------- .../controllers/engine_cycle/fuel_schedule.h | 15 +++++++++----- .../engine_cycle/main_trigger_callback.cpp | 4 ++-- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/firmware/controllers/engine_cycle/fuel_schedule.cpp b/firmware/controllers/engine_cycle/fuel_schedule.cpp index 6ad024f83e..83a8fa5fb6 100644 --- a/firmware/controllers/engine_cycle/fuel_schedule.cpp +++ b/firmware/controllers/engine_cycle/fuel_schedule.cpp @@ -124,10 +124,8 @@ bool InjectionEvent::updateInjectionAngle() { /** * @returns false in case of error, true if success */ -bool FuelSchedule::addFuelEventsForCylinder(int i) { - InjectionEvent *ev = &elements[i]; - - bool updatedAngle = ev->updateInjectionAngle(); +bool InjectionEvent::update() { + bool updatedAngle = updateInjectionAngle(); if (!updatedAngle) { return false; @@ -142,7 +140,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; @@ -157,7 +155,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 { @@ -167,11 +165,11 @@ 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 = isSimultaneous; // 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 @@ -183,7 +181,7 @@ bool FuelSchedule::addFuelEventsForCylinder(int i) { void FuelSchedule::addFuelEvents() { for (size_t cylinderIndex = 0; cylinderIndex < engineConfiguration->cylindersCount; cylinderIndex++) { - bool result = addFuelEventsForCylinder(cylinderIndex); + bool result = elements[cylinderIndex].update(); if (!result) { invalidate(); diff --git a/firmware/controllers/engine_cycle/fuel_schedule.h b/firmware/controllers/engine_cycle/fuel_schedule.h index cc4e665466..befe99a383 100644 --- a/firmware/controllers/engine_cycle/fuel_schedule.h +++ b/firmware/controllers/engine_cycle/fuel_schedule.h @@ -18,11 +18,7 @@ class InjectionEvent { public: InjectionEvent(); - // Update the injection start angle - bool updateInjectionAngle(); - - // Compute the injection start angle, compensating for injection duration and injection phase settings. - expected computeInjectionAngle() const; + bool update(); // Call this every decoded trigger tooth. It will schedule any relevant events for this injector. void onTriggerTooth(int rpm, efitick_t nowNt, float currentPhase, float nextPhase); @@ -33,6 +29,13 @@ public: ownIndex = index; } +private: + // Update the injection start angle + bool updateInjectionAngle(); + + // Compute the injection start angle, compensating for injection duration and injection phase settings. + expected computeInjectionAngle() const; + /** * This is a performance optimization for IM_SIMULTANEOUS fuel strategy. * It's more efficient to handle all injectors together if that's the case @@ -41,6 +44,7 @@ public: uint8_t ownIndex = 0; uint8_t cylinderNumber = 0; +public: scheduling_s signalTimerUp; scheduling_s endOfInjectionEvent; @@ -53,6 +57,7 @@ public: */ bool isScheduled = false; +private: WallFuel wallFuel; public: diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.cpp b/firmware/controllers/engine_cycle/main_trigger_callback.cpp index bc7391c5fe..06ce778910 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.cpp +++ b/firmware/controllers/engine_cycle/main_trigger_callback.cpp @@ -50,7 +50,7 @@ void endSimultaneousInjection(InjectionEvent *event) { event->isScheduled = false; endSimultaneousInjectionOnlyTogglePins(); - getFuelSchedule()->addFuelEventsForCylinder(event->ownIndex); + event->update(); } void turnInjectionPinLow(InjectionEvent *event) { @@ -63,7 +63,7 @@ void turnInjectionPinLow(InjectionEvent *event) { output->close(nowNt); } } - getFuelSchedule()->addFuelEventsForCylinder(event->ownIndex); + event->update(); } void InjectionEvent::onTriggerTooth(int rpm, efitick_t nowNt, float currentPhase, float nextPhase) {