lua hook for timing add (#3260)
* load script * test * needs more rams * embiggen stack * init system lua from lua thread * de-embiggen stack * infra * hook * system needs a little more * semicolon Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
parent
759582948a
commit
0978722225
|
@ -163,7 +163,7 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
injectionOffset = getInjectionOffset(rpm, fuelLoad PASS_ENGINE_PARAMETER_SUFFIX);
|
injectionOffset = getInjectionOffset(rpm, fuelLoad PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
|
|
||||||
float ignitionLoad = getIgnitionLoad(PASS_ENGINE_PARAMETER_SIGNATURE);
|
float ignitionLoad = getIgnitionLoad(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
timingAdvance = getAdvance(rpm, ignitionLoad PASS_ENGINE_PARAMETER_SUFFIX);
|
timingAdvance = getAdvance(rpm, ignitionLoad PASS_ENGINE_PARAMETER_SUFFIX) + luaAdjustments.ignitionTimingAdd;
|
||||||
|
|
||||||
// TODO: calculate me from a table!
|
// TODO: calculate me from a table!
|
||||||
trailingSparkAngle = CONFIG(trailingSparkAngle);
|
trailingSparkAngle = CONFIG(trailingSparkAngle);
|
||||||
|
|
|
@ -13,6 +13,10 @@
|
||||||
#include "pid.h"
|
#include "pid.h"
|
||||||
#include "engine_state_generated.h"
|
#include "engine_state_generated.h"
|
||||||
|
|
||||||
|
struct LuaAdjustments {
|
||||||
|
float ignitionTimingAdd = 0;
|
||||||
|
};
|
||||||
|
|
||||||
class EngineState : public engine_state2_s {
|
class EngineState : public engine_state2_s {
|
||||||
public:
|
public:
|
||||||
EngineState();
|
EngineState();
|
||||||
|
@ -86,4 +90,6 @@ public:
|
||||||
|
|
||||||
float targetLambda = 0.0f;
|
float targetLambda = 0.0f;
|
||||||
float stoichiometricRatio = 0.0f;
|
float stoichiometricRatio = 0.0f;
|
||||||
|
|
||||||
|
LuaAdjustments luaAdjustments;
|
||||||
};
|
};
|
||||||
|
|
|
@ -344,6 +344,9 @@ void LuaThread::ThreadTask() {
|
||||||
while (!chThdShouldTerminateX()) {
|
while (!chThdShouldTerminateX()) {
|
||||||
bool wasOk = runOneLua(myAlloc<0>, config->luaScript);
|
bool wasOk = runOneLua(myAlloc<0>, config->luaScript);
|
||||||
|
|
||||||
|
// Reset any lua adjustments the script made
|
||||||
|
ENGINE(engineState).luaAdjustments = {};
|
||||||
|
|
||||||
if (!wasOk) {
|
if (!wasOk) {
|
||||||
// Something went wrong executing the script, spin
|
// Something went wrong executing the script, spin
|
||||||
// until reset invoked (maybe the user fixed the script)
|
// until reset invoked (maybe the user fixed the script)
|
||||||
|
|
|
@ -307,6 +307,12 @@ static int lua_stopEngine(lua_State*) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int lua_setTimingAdd(lua_State* l) {
|
||||||
|
ENGINE(engineState).luaAdjustments.ignitionTimingAdd = luaL_checknumber(l, 1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#endif // EFI_UNIT_TEST
|
#endif // EFI_UNIT_TEST
|
||||||
|
|
||||||
void configureRusefiLuaHooks(lua_State* l) {
|
void configureRusefiLuaHooks(lua_State* l) {
|
||||||
|
@ -338,5 +344,7 @@ void configureRusefiLuaHooks(lua_State* l) {
|
||||||
lua_register(l, "setAirmass", lua_setAirmass);
|
lua_register(l, "setAirmass", lua_setAirmass);
|
||||||
|
|
||||||
lua_register(l, "stopEngine", lua_stopEngine);
|
lua_register(l, "stopEngine", lua_stopEngine);
|
||||||
|
|
||||||
|
lua_register(l, "setTimingAdd", lua_setTimingAdd);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue