only: refactoring: InjectionEvent knowns it's index
This commit is contained in:
parent
07a7cd746d
commit
c16581c316
|
@ -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
|
||||
|
|
|
@ -18,6 +18,8 @@ class InjectionEvent {
|
|||
public:
|
||||
InjectionEvent();
|
||||
|
||||
bool update();
|
||||
|
||||
// Update the injection start angle
|
||||
bool updateInjectionAngle();
|
||||
|
||||
|
|
Loading…
Reference in New Issue