findTableIndex
This commit is contained in:
parent
6be84c0de9
commit
676f2dfb93
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue