diff --git a/firmware/controllers/lua/lua.cpp b/firmware/controllers/lua/lua.cpp index ddb2b1ead6..fb076e5b58 100644 --- a/firmware/controllers/lua/lua.cpp +++ b/firmware/controllers/lua/lua.cpp @@ -247,6 +247,9 @@ static bool runOneLua() { chThdSleepMilliseconds(luaTickPeriodMs); } + // De-init pins, they will reinit next start of the script. + luaDeInitPins(); + return true; } diff --git a/firmware/controllers/lua/lua_hooks.cpp b/firmware/controllers/lua/lua_hooks.cpp index 69d7d64ceb..3007716af0 100644 --- a/firmware/controllers/lua/lua_hooks.cpp +++ b/firmware/controllers/lua/lua_hooks.cpp @@ -101,6 +101,13 @@ static int lua_startPwm(lua_State* l) { return 0; } +void luaDeInitPins() { + // Simply de-init all pins - when the script runs again, they will be re-init'd + for (size_t i = 0; i < efi::size(pins); i++) { + pins[i].deInit(); + } +} + static int lua_setPwmDuty(lua_State* l) { auto p = luaL_checkPwmIndex(l, 1); auto duty = luaL_checknumber(l, 2); diff --git a/firmware/controllers/lua/lua_hooks.h b/firmware/controllers/lua/lua_hooks.h index b7e225b96a..ca2bca57c6 100644 --- a/firmware/controllers/lua/lua_hooks.h +++ b/firmware/controllers/lua/lua_hooks.h @@ -1,3 +1,4 @@ #pragma once void configureRusefiLuaHooks(lua_State*); +void luaDeInitPins();