lua curve progress

This commit is contained in:
rusefillc 2021-11-05 10:34:12 -04:00
parent 2bd0633ecb
commit 57dc9b36f4
2 changed files with 23 additions and 0 deletions

View File

@ -16,6 +16,10 @@ using namespace luaaa;
// Some functions lean on existing FSIO implementation // Some functions lean on existing FSIO implementation
#include "fsio_impl.h" #include "fsio_impl.h"
#if EFI_UNIT_TEST
Engine *engineForLuaUnitTests;
#endif
static int lua_readpin(lua_State* l) { static int lua_readpin(lua_State* l) {
auto msg = luaL_checkstring(l, 1); auto msg = luaL_checkstring(l, 1);
#if EFI_PROD_CODE #if EFI_PROD_CODE
@ -91,6 +95,21 @@ static int lua_table3d(lua_State* l) {
return 1; return 1;
} }
static int lua_curve2d(lua_State* l) {
auto curveIdx = luaL_checkinteger(l, 1);
auto x = luaL_checknumber(l, 2);
#if EFI_UNIT_TEST
Engine *engine = engineForLuaUnitTests;
EXPAND_Engine;
#endif
auto result = getCurveValue(curveIdx, x PASS_ENGINE_PARAMETER_SUFFIX);
lua_pushnumber(l, result);
return 1;
}
static int lua_txCan(lua_State* l) { static int lua_txCan(lua_State* l) {
auto channel = luaL_checkinteger(l, 1); auto channel = luaL_checkinteger(l, 1);
// TODO: support multiple channels // TODO: support multiple channels
@ -390,6 +409,7 @@ void configureRusefiLuaHooks(lua_State* l) {
lua_register(l, "getSensorRaw", lua_getSensorRaw); lua_register(l, "getSensorRaw", lua_getSensorRaw);
lua_register(l, "hasSensor", lua_hasSensor); lua_register(l, "hasSensor", lua_hasSensor);
lua_register(l, "table3d", lua_table3d); lua_register(l, "table3d", lua_table3d);
lua_register(l, "curve", lua_curve2d);
lua_register(l, "txCan", lua_txCan); lua_register(l, "txCan", lua_txCan);
#if !EFI_UNIT_TEST #if !EFI_UNIT_TEST

View File

@ -29,6 +29,7 @@ extern bool printTriggerDebug;
extern bool printTriggerTrace; extern bool printTriggerTrace;
extern bool printFuelDebug; extern bool printFuelDebug;
extern int minCrankingRpm; extern int minCrankingRpm;
extern Engine *engineForLuaUnitTests;
EngineTestHelperBase::EngineTestHelperBase() { EngineTestHelperBase::EngineTestHelperBase() {
// todo: make this not a global variable, we need currentTimeProvider interface on engine // todo: make this not a global variable, we need currentTimeProvider interface on engine
@ -58,6 +59,8 @@ EngineTestHelper::EngineTestHelper(engine_type_e engineType, configuration_callb
engine->setConfig(engine, &persistentConfig.engineConfiguration, &persistentConfig); engine->setConfig(engine, &persistentConfig.engineConfiguration, &persistentConfig);
EXPAND_Engine; EXPAND_Engine;
engineForLuaUnitTests = engine;
Sensor::setMockValue(SensorType::Clt, 70); Sensor::setMockValue(SensorType::Clt, 70);
Sensor::setMockValue(SensorType::Iat, 30); Sensor::setMockValue(SensorType::Iat, 30);