script settings need names!

This commit is contained in:
rusefillc 2021-11-14 12:51:41 -05:00
parent d69b742bce
commit 14c0711011
4 changed files with 36 additions and 3 deletions

View File

@ -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"(

View File

@ -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;i<SCRIPT_SETTING_COUNT;i++) {
if (strEqualCaseInsensitive(name, engineConfiguration->scriptSettingName[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

@ -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);

View File

@ -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);