diff --git a/firmware/config/engines/custom_engine.cpp b/firmware/config/engines/custom_engine.cpp index c48b86eef2..34a405bcfa 100644 --- a/firmware/config/engines/custom_engine.cpp +++ b/firmware/config/engines/custom_engine.cpp @@ -799,6 +799,12 @@ void setHellenDefaultVrThresholds(DECLARE_CONFIG_PARAMETER_SIGNATURE) { } void proteusHarley(DECLARE_CONFIG_PARAMETER_SIGNATURE) { + strcpy(engineConfiguration->scriptSettingName[0], "compReleaseRpm"); + engineConfiguration->scriptSetting[0] = 300; + strcpy(engineConfiguration->scriptSettingName[1], "compReleaseDur"); + engineConfiguration->scriptSetting[1] = 5000; + + engineConfiguration->luaOutputPins[0] = PROTEUS_LS_12; #if HW_PROTEUS strncpy(config->luaScript, R"( diff --git a/firmware/controllers/core/fsio_impl.cpp b/firmware/controllers/core/fsio_impl.cpp index 8fda12d0ac..2d4e5c9ae2 100644 --- a/firmware/controllers/core/fsio_impl.cpp +++ b/firmware/controllers/core/fsio_impl.cpp @@ -280,6 +280,7 @@ ValueProvider3D *getscriptTable(int index) { } } +// todo: template this copy-pasta /** * @return zero-based index of curve with given name */ @@ -301,6 +302,15 @@ int getTableIndexByName(const char *name DECLARE_ENGINE_PARAMETER_SUFFIX) { return EFI_ERROR_CODE; } +int getSettingIndexByName(const char *name DECLARE_ENGINE_PARAMETER_SUFFIX) { + for (int i = 0;iscriptSettingName[i])) { + return i; + } + } + return EFI_ERROR_CODE; +} + float getCurveValue(int index, float key DECLARE_ENGINE_PARAMETER_SUFFIX) { // not great code at all :( switch (index) { diff --git a/firmware/controllers/core/fsio_impl.h b/firmware/controllers/core/fsio_impl.h index 49497ab39f..f125dd1f56 100644 --- a/firmware/controllers/core/fsio_impl.h +++ b/firmware/controllers/core/fsio_impl.h @@ -31,5 +31,6 @@ void runHardcodedFsio(DECLARE_ENGINE_PARAMETER_SIGNATURE); float getCurveValue(int index, float key DECLARE_ENGINE_PARAMETER_SUFFIX); int getCurveIndexByName(const char *name DECLARE_ENGINE_PARAMETER_SUFFIX); int getTableIndexByName(const char *name DECLARE_ENGINE_PARAMETER_SUFFIX); +int getSettingIndexByName(const char *name DECLARE_ENGINE_PARAMETER_SUFFIX); ValueProvider3D *getscriptTable(int index); diff --git a/firmware/controllers/lua/lua_hooks.cpp b/firmware/controllers/lua/lua_hooks.cpp index 342a2952ba..7ad079f980 100644 --- a/firmware/controllers/lua/lua_hooks.cpp +++ b/firmware/controllers/lua/lua_hooks.cpp @@ -480,16 +480,32 @@ void configureRusefiLuaHooks(lua_State* l) { EXPAND_Engine; #endif auto name = luaL_checklstring(l, 1, nullptr); - auto result = getTableIndexByName(name PASS_ENGINE_PARAMETER_SUFFIX); - if (result == EFI_ERROR_CODE) { + auto index = getTableIndexByName(name PASS_ENGINE_PARAMETER_SUFFIX); + if (index == EFI_ERROR_CODE) { lua_pushnil(l); } else { // TS counts curve from 1 so convert indexing here - lua_pushnumber(l, result + HUMAN_OFFSET); + lua_pushnumber(l, index + HUMAN_OFFSET); } return 1; }); + lua_register(l, "findSetting", + [](lua_State* l) { +#if EFI_UNIT_TEST + Engine *engine = engineForLuaUnitTests; + EXPAND_Engine; +#endif + auto name = luaL_checklstring(l, 1, nullptr); + auto index = getSettingIndexByName(name PASS_ENGINE_PARAMETER_SUFFIX); + if (index == EFI_ERROR_CODE) { + lua_pushnil(l); + } else { + // TS counts curve from 1 so convert indexing here + lua_pushnumber(l, engineConfiguration->scriptSetting[index]); + } + return 1; + }); #if !EFI_UNIT_TEST lua_register(l, "startPwm", lua_startPwm);