more of LuaAdjustments

This commit is contained in:
rusefillc 2021-09-24 00:34:06 -04:00
parent 0978722225
commit e242315773
3 changed files with 26 additions and 1 deletions

View File

@ -163,7 +163,7 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
injectionOffset = getInjectionOffset(rpm, fuelLoad PASS_ENGINE_PARAMETER_SUFFIX);
float ignitionLoad = getIgnitionLoad(PASS_ENGINE_PARAMETER_SIGNATURE);
timingAdvance = getAdvance(rpm, ignitionLoad PASS_ENGINE_PARAMETER_SUFFIX) + luaAdjustments.ignitionTimingAdd;
timingAdvance = getAdvance(rpm, ignitionLoad PASS_ENGINE_PARAMETER_SUFFIX) * luaAdjustments.ignitionTimingMult + luaAdjustments.ignitionTimingAdd;
// TODO: calculate me from a table!
trailingSparkAngle = CONFIG(trailingSparkAngle);

View File

@ -15,6 +15,9 @@
struct LuaAdjustments {
float ignitionTimingAdd = 0;
float ignitionTimingMult = 1;
float fuelAdd = 0;
float fuelMult = 1;
};
class EngineState : public engine_state2_s {

View File

@ -313,6 +313,24 @@ static int lua_setTimingAdd(lua_State* l) {
return 0;
}
static int lua_setTimingMult(lua_State* l) {
ENGINE(engineState).luaAdjustments.ignitionTimingMult = luaL_checknumber(l, 1);
return 0;
}
static int lua_setFuelAdd(lua_State* l) {
ENGINE(engineState).luaAdjustments.fuelAdd = luaL_checknumber(l, 1);
return 0;
}
static int lua_setFuelMult(lua_State* l) {
ENGINE(engineState).luaAdjustments.fuelMult = luaL_checknumber(l, 1);
return 0;
}
#endif // EFI_UNIT_TEST
void configureRusefiLuaHooks(lua_State* l) {
@ -346,5 +364,9 @@ void configureRusefiLuaHooks(lua_State* l) {
lua_register(l, "stopEngine", lua_stopEngine);
lua_register(l, "setTimingAdd", lua_setTimingAdd);
lua_register(l, "setTimingMult", lua_setTimingMult);
lua_register(l, "setFuelAdd", lua_setFuelAdd);
lua_register(l, "setFuelMult", lua_setFuelMult);
#endif
}