proportional spark cut #3427
This commit is contained in:
parent
c951d1d0c0
commit
a61043e570
|
@ -115,6 +115,7 @@ public:
|
|||
|
||||
GearControllerBase *gearController;
|
||||
LaunchControlBase launchController;
|
||||
SoftSparkLimiter softSparkLimiter;
|
||||
|
||||
efitick_t mostRecentSparkEvent;
|
||||
efitick_t mostRecentTimeBetweenSparkEvents;
|
||||
|
|
|
@ -137,6 +137,21 @@ bool LaunchControlBase::isLaunchFuelRpmRetardCondition() const {
|
|||
return isLaunchRpmRetardCondition() && engineConfiguration->launchFuelCutEnable;
|
||||
}
|
||||
|
||||
void SoftSparkLimiter::setTargetSkipRatio(float targetSkipRatio) {
|
||||
this->targetSkipRatio = targetSkipRatio;
|
||||
}
|
||||
|
||||
bool SoftSparkLimiter::shouldSkip() {
|
||||
if (targetSkipRatio == 0 || wasJustSkipped) {
|
||||
wasJustSkipped = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
float r = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
|
||||
wasJustSkipped = r < 2 * targetSkipRatio;
|
||||
return wasJustSkipped;
|
||||
}
|
||||
|
||||
void initLaunchControl() {
|
||||
engine->launchController.inject();
|
||||
}
|
||||
|
|
|
@ -35,3 +35,17 @@ private:
|
|||
|
||||
Timer m_launchTimer;
|
||||
};
|
||||
|
||||
|
||||
class SoftSparkLimiter {
|
||||
public:
|
||||
/**
|
||||
* targetSkipRatio of '0' means 'do not skip', would always return false
|
||||
*/
|
||||
void setTargetSkipRatio(float targetSkipRatio);
|
||||
|
||||
bool shouldSkip();
|
||||
private:
|
||||
bool wasJustSkipped = false;
|
||||
float targetSkipRatio = 0;
|
||||
};
|
||||
|
|
|
@ -486,6 +486,12 @@ void configureRusefiLuaHooks(lua_State* l) {
|
|||
return 1;
|
||||
});
|
||||
|
||||
lua_register(l, "setSparkSkipRatio", [](lua_State* l) {
|
||||
auto targetSkipRatio = luaL_checknumber(l, 1);
|
||||
engine->softSparkLimiter.setTargetSkipRatio(targetSkipRatio);
|
||||
return 1;
|
||||
});
|
||||
|
||||
#if !EFI_UNIT_TEST
|
||||
lua_register(l, "startPwm", lua_startPwm);
|
||||
lua_register(l, "setPwmDuty", lua_setPwmDuty);
|
||||
|
|
Loading…
Reference in New Issue