diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.cpp b/firmware/controllers/engine_cycle/main_trigger_callback.cpp index ff3805b091..7f40f88564 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.cpp +++ b/firmware/controllers/engine_cycle/main_trigger_callback.cpp @@ -114,6 +114,44 @@ void turnInjectionPinHigh(InjectionEvent *event) { } } +void InjectorOutputPin::setHigh() { + NamedOutputPin::setHigh(); + // this is NASTY but what's the better option? bytes? At cost of 22 extra bytes in output status packet? + switch (injectorIndex) { + case 0: + engine->outputChannels.injectorState1 = true; + break; + case 1: + engine->outputChannels.injectorState2 = true; + break; + case 2: + engine->outputChannels.injectorState3 = true; + break; + case 3: + engine->outputChannels.injectorState4 = true; + break; + } +} + +void InjectorOutputPin::setLow() { + NamedOutputPin::setLow(); + // this is NASTY but what's the better option? bytes? At cost of 22 extra bytes in output status packet? + switch (injectorIndex) { + case 0: + engine->outputChannels.injectorState1 = false; + break; + case 1: + engine->outputChannels.injectorState2 = false; + break; + case 2: + engine->outputChannels.injectorState3 = false; + break; + case 3: + engine->outputChannels.injectorState4 = false; + break; + } +} + void InjectorOutputPin::close(efitick_t nowNt) { #if FUEL_MATH_EXTREME_LOGGING if (printFuelDebug) { diff --git a/firmware/controllers/system/efi_gpio.cpp b/firmware/controllers/system/efi_gpio.cpp index d9fba64086..73ef4b45dd 100644 --- a/firmware/controllers/system/efi_gpio.cpp +++ b/firmware/controllers/system/efi_gpio.cpp @@ -130,6 +130,7 @@ EnginePins::EnginePins() : static_assert(efi::size(trailNames) >= MAX_CYLINDER_COUNT, "Too many ignition pins"); static_assert(efi::size(injectorNames) >= MAX_CYLINDER_COUNT, "Too many injection pins"); for (int i = 0; i < MAX_CYLINDER_COUNT;i++) { + enginePins.coils[i].coilIndex = i; enginePins.coils[i].name = sparkNames[i]; enginePins.coils[i].shortName = sparkShortNames[i]; @@ -376,6 +377,44 @@ IgnitionOutputPin::IgnitionOutputPin() { reset(); } +void IgnitionOutputPin::setHigh() { + NamedOutputPin::setHigh(); + // this is NASTY but what's the better option? bytes? At cost of 22 extra bytes in output status packet? + switch (coilIndex) { + case 0: + engine->outputChannels.coilState1 = true; + break; + case 1: + engine->outputChannels.coilState2 = true; + break; + case 2: + engine->outputChannels.coilState3 = true; + break; + case 3: + engine->outputChannels.coilState4 = true; + break; + } +} + +void IgnitionOutputPin::setLow() { + NamedOutputPin::setLow(); + // this is NASTY but what's the better option? bytes? At cost of 22 extra bytes in output status packet? + switch (coilIndex) { + case 0: + engine->outputChannels.coilState1 = false; + break; + case 1: + engine->outputChannels.coilState2 = false; + break; + case 2: + engine->outputChannels.coilState3 = false; + break; + case 3: + engine->outputChannels.coilState4 = false; + break; + } +} + void IgnitionOutputPin::reset() { outOfOrder = false; signalFallSparkId = 0; diff --git a/firmware/controllers/system/efi_gpio.h b/firmware/controllers/system/efi_gpio.h index 7bd001267b..499e96c07e 100644 --- a/firmware/controllers/system/efi_gpio.h +++ b/firmware/controllers/system/efi_gpio.h @@ -99,8 +99,8 @@ class NamedOutputPin : public virtual OutputPin { public: NamedOutputPin(); explicit NamedOutputPin(const char *name); - void setHigh(); - void setLow(); + virtual void setHigh(); + virtual void setLow(); const char *getName() const; const char *getShortName() const; /** @@ -122,6 +122,8 @@ public: void open(efitick_t nowNt); void close(efitick_t nowNt); + void setHigh() override; + void setLow() override; int8_t getOverlappingCounter() const { return overlappingCounter; } @@ -135,9 +137,12 @@ private: class IgnitionOutputPin : public NamedOutputPin { public: IgnitionOutputPin(); + void setHigh() override; + void setLow() override; void reset(); int signalFallSparkId; bool outOfOrder; // https://sourceforge.net/p/rusefi/tickets/319/ + int8_t coilIndex; }; /**