only:minor encapsulation

This commit is contained in:
rusefi 2023-10-13 00:17:06 -04:00 committed by Andrey
parent b721882952
commit 4e32f39070
3 changed files with 21 additions and 18 deletions

View File

@ -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();

View File

@ -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<float> 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<float> 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:

View File

@ -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) {