Skip to content

Commit

Permalink
hoist dwell check out of loop
Browse files Browse the repository at this point in the history
  • Loading branch information
mck1117 committed Aug 31, 2024
1 parent 7593cd6 commit 3fc4222
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions firmware/controllers/engine_cycle/spark_logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,6 @@ static void scheduleSparkEvent(bool limitedSpark, IgnitionEvent *event,
int rpm, efitick_t edgeTimestamp, float currentPhase, float nextPhase) {

angle_t sparkAngle = event->sparkAngle;
const floatms_t dwellMs = engine->ignitionState.sparkDwell;
if (std::isnan(dwellMs) || dwellMs <= 0) {
warning(ObdCode::CUSTOM_DWELL, "invalid dwell to handle: %.2f at %d", dwellMs, rpm);
return;
}
if (std::isnan(sparkAngle)) {
warning(ObdCode::CUSTOM_ADVANCE_SPARK, "NaN advance");
return;
Expand Down Expand Up @@ -457,6 +452,12 @@ void onTriggerEventSparkLogic(int rpm, efitick_t edgeTimestamp, float currentPha
engine->outputChannels.sparkCutReason = (int8_t)limitedSparkState.reason;
bool limitedSpark = !limitedSparkState.value;

const floatms_t dwellMs = engine->ignitionState.sparkDwell;
if (std::isnan(dwellMs) || dwellMs <= 0) {
warning(ObdCode::CUSTOM_DWELL, "invalid dwell to handle: %.2f at %d", dwellMs, rpm);
return;
}

if (!engine->ignitionEvents.isReady) {
prepareIgnitionSchedule();
}
Expand Down

0 comments on commit 3fc4222

Please sign in to comment.