Skip to content

Commit 473d175

Browse files
authored
Fix potential issue in speeduino#1275 (speeduino#1361)
1 parent ab02bd7 commit 473d175

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

speeduino/schedule_calcs.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@ static inline uint32_t calculateInjectorTimeout(const FuelSchedule &schedule, in
2727
{
2828
int16_t delta = openAngle - crankAngle;
2929

30-
while(delta < 0) { delta += CRANK_ANGLE_MAX_INJ; }
31-
32-
return angleToTimeMicroSecPerDegree((uint16_t)delta);
30+
if ( (schedule.Status == RUNNING) || (schedule.Status == OFF))
31+
{
32+
while(delta < 0) {
33+
delta += CRANK_ANGLE_MAX_INJ;
34+
}
35+
}
36+
37+
return angleToTimeMicroSecPerDegree((uint16_t)max((int16_t)0, delta));
3338
}
3439

3540
static inline void calculateIgnitionAngle(const uint16_t dwellAngle, const uint16_t channelIgnDegrees, int8_t advance, int *pEndAngle, int *pStartAngle)

0 commit comments

Comments
 (0)