findTableIndex

This commit is contained in:
rusefi 2021-11-13 10:02:01 -05:00
parent f7d1a3e542
commit d172961577
3 changed files with 28 additions and 0 deletions

View File

@ -616,6 +616,15 @@ int getCurveIndexByName(const char *name DECLARE_ENGINE_PARAMETER_SUFFIX) {
return EFI_ERROR_CODE;
}
int getTableIndexByName(const char *name DECLARE_ENGINE_PARAMETER_SUFFIX) {
for (int i = 0;i<SCRIPT_TABLE_COUNT;i++) {
if (strEqualCaseInsensitive(name, engineConfiguration->scriptTableName[i])) {
return i;
}
}
return EFI_ERROR_CODE;
}
float getCurveValue(int index, float key DECLARE_ENGINE_PARAMETER_SUFFIX) {
// not great code at all :(
switch (index) {

View File

@ -40,5 +40,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);
ValueProvider3D *getFSIOTable(int index);

View File

@ -473,6 +473,24 @@ void configureRusefiLuaHooks(lua_State* l) {
// used by unit tests
lua_register(l, "txCan", lua_txCan);
lua_register(l, "findTableIndex",
[](lua_State* l) {
#if EFI_UNIT_TEST
Engine *engine = engineForLuaUnitTests;
EXPAND_Engine;
#endif
auto name = luaL_checklstring(l, 1, nullptr);
auto result = getTableIndexByName(name PASS_ENGINE_PARAMETER_SUFFIX);
if (result == EFI_ERROR_CODE) {
lua_pushnil(l);
} else {
// TS counts curve from 1 so convert indexing here
lua_pushnumber(l, result + HUMAN_OFFSET);
}
return 1;
});
#if !EFI_UNIT_TEST
lua_register(l, "startPwm", lua_startPwm);
lua_register(l, "setPwmDuty", lua_setPwmDuty);