diff --git a/firmware/controllers/actuators/ac_control.cpp b/firmware/controllers/actuators/ac_control.cpp index f4384f154d..af655354b6 100644 --- a/firmware/controllers/actuators/ac_control.cpp +++ b/firmware/controllers/actuators/ac_control.cpp @@ -45,6 +45,9 @@ bool AcController::getAcState() { if (tpsTooHigh) { return false; } + if (isDisabledByLua) { + return false; + } acButtonState = engine->acSwitchState; // All conditions allow AC, simply pass thru switch diff --git a/firmware/controllers/actuators/ac_control.txt b/firmware/controllers/actuators/ac_control.txt index b9e69c7064..92aa1b8694 100644 --- a/firmware/controllers/actuators/ac_control.txt +++ b/firmware/controllers/actuators/ac_control.txt @@ -7,8 +7,9 @@ bit engineTooHot bit tpsTooHigh bit acButtonState -bit isDisabledByLua +bit isDisabledByLua;For setAcDisabled Lua method int latest_usage_ac_control; +int acSwitchLastChangeTimeMs; end_struct diff --git a/firmware/controllers/lua/lua.cpp b/firmware/controllers/lua/lua.cpp index a2510c83c6..6f7f4cae4c 100644 --- a/firmware/controllers/lua/lua.cpp +++ b/firmware/controllers/lua/lua.cpp @@ -292,6 +292,17 @@ struct LuaThread : ThreadController<4096> { void ThreadTask() override; }; +static void resetLua() { + engine->module().unmock().isDisabledByLua = false; +#if EFI_CAN_SUPPORT + resetLuaCanRx(); +#endif // EFI_CAN_SUPPORT + + // De-init pins, they will reinit next start of the script. + luaDeInitPins(); +} + + static bool needsReset = false; // Each invocation of runOneLua will: @@ -335,12 +346,7 @@ static bool runOneLua(lua_Alloc alloc, const char* script) { engine->outputChannels.luaInvocationCounter++; } -#if EFI_CAN_SUPPORT - resetLuaCanRx(); -#endif // EFI_CAN_SUPPORT - - // De-init pins, they will reinit next start of the script. - luaDeInitPins(); + resetLua(); return true; } diff --git a/firmware/controllers/lua/lua_hooks.cpp b/firmware/controllers/lua/lua_hooks.cpp index 322009fef6..ced47825b4 100644 --- a/firmware/controllers/lua/lua_hooks.cpp +++ b/firmware/controllers/lua/lua_hooks.cpp @@ -588,6 +588,12 @@ void configureRusefiLuaHooks(lua_State* l) { return 0; }); + lua_register(l, "setAcDisabled", [](lua_State* l) { + auto value = lua_toboolean(l, 1); + engine->module().unmock().isDisabledByLua = value; + return 0; + }); + lua_register(l, "setTimingAdd", [](lua_State* l) { engine->engineState.luaAdjustments.ignitionTimingAdd = luaL_checknumber(l, 1); return 0;