remove some uses of EFI_ERROR_CODE (#4496)
* lua hooks * findAngleMatch * s * s
This commit is contained in:
parent
4df628998b
commit
b662e59707
|
@ -40,10 +40,10 @@ int MultiChannelStateSequence::findInsertionAngle(const float angle) const {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int MultiChannelStateSequence::findAngleMatch(const float angle) const {
|
||||
expected<int> MultiChannelStateSequence::findAngleMatch(const float angle) const {
|
||||
for (int i = 0; i < phaseCount; i++) {
|
||||
if (isSameF(getSwitchTime(i), angle))
|
||||
return i;
|
||||
}
|
||||
return EFI_ERROR_CODE;
|
||||
return unexpected;
|
||||
}
|
||||
|
|
|
@ -47,8 +47,8 @@ public:
|
|||
// Make sure the switch times are in order and end at the very end.
|
||||
void checkSwitchTimes(float scale) const;
|
||||
|
||||
// Find the exact angle, or EFI_ERROR_CODE if it doesn't exist
|
||||
int findAngleMatch(float angle) const;
|
||||
// Find the exact angle, or unexpected if it doesn't exist
|
||||
expected<int> findAngleMatch(float angle) const;
|
||||
|
||||
// returns the index at which given value would need to be inserted into sorted array
|
||||
int findInsertionAngle(float angle) const;
|
||||
|
|
|
@ -616,11 +616,11 @@ void configureRusefiLuaHooks(lua_State* l) {
|
|||
lua_register(l, "findCurveIndex", [](lua_State* l) {
|
||||
auto name = luaL_checklstring(l, 1, nullptr);
|
||||
auto result = getCurveIndexByName(name);
|
||||
if (result == EFI_ERROR_CODE) {
|
||||
if (!result) {
|
||||
lua_pushnil(l);
|
||||
} else {
|
||||
// TS counts curve from 1 so convert indexing here
|
||||
lua_pushnumber(l, result + HUMAN_OFFSET);
|
||||
lua_pushnumber(l, result.Value + HUMAN_OFFSET);
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
|
@ -633,11 +633,11 @@ void configureRusefiLuaHooks(lua_State* l) {
|
|||
[](lua_State* l) {
|
||||
auto name = luaL_checklstring(l, 1, nullptr);
|
||||
auto index = getTableIndexByName(name);
|
||||
if (index == EFI_ERROR_CODE) {
|
||||
if (!index) {
|
||||
lua_pushnil(l);
|
||||
} else {
|
||||
// TS counts curve from 1 so convert indexing here
|
||||
lua_pushnumber(l, index + HUMAN_OFFSET);
|
||||
lua_pushnumber(l, index.Value + HUMAN_OFFSET);
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
|
@ -648,11 +648,11 @@ void configureRusefiLuaHooks(lua_State* l) {
|
|||
auto defaultValue = luaL_checknumber(l, 2);
|
||||
|
||||
auto index = getSettingIndexByName(name);
|
||||
if (index == EFI_ERROR_CODE) {
|
||||
if (!index) {
|
||||
lua_pushnumber(l, defaultValue);
|
||||
} else {
|
||||
// TS counts curve from 1 so convert indexing here
|
||||
lua_pushnumber(l, engineConfiguration->scriptSetting[index]);
|
||||
lua_pushnumber(l, engineConfiguration->scriptSetting[index.Value]);
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
|
|
|
@ -34,31 +34,34 @@ ValueProvider3D *getscriptTable(int index) {
|
|||
/**
|
||||
* @return zero-based index of curve with given name
|
||||
*/
|
||||
int getCurveIndexByName(const char *name) {
|
||||
expected<int> getCurveIndexByName(const char *name) {
|
||||
for (int i = 0;i<SCRIPT_CURVE_COUNT;i++) {
|
||||
if (strEqualCaseInsensitive(name, engineConfiguration->scriptCurveName[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return EFI_ERROR_CODE;
|
||||
|
||||
return unexpected;
|
||||
}
|
||||
|
||||
int getTableIndexByName(const char *name) {
|
||||
expected<int> getTableIndexByName(const char *name) {
|
||||
for (int i = 0;i<SCRIPT_TABLE_COUNT;i++) {
|
||||
if (strEqualCaseInsensitive(name, engineConfiguration->scriptTableName[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return EFI_ERROR_CODE;
|
||||
|
||||
return unexpected;
|
||||
}
|
||||
|
||||
int getSettingIndexByName(const char *name) {
|
||||
expected<int> getSettingIndexByName(const char *name) {
|
||||
for (int i = 0;i<SCRIPT_SETTING_COUNT;i++) {
|
||||
if (strEqualCaseInsensitive(name, engineConfiguration->scriptSettingName[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return EFI_ERROR_CODE;
|
||||
|
||||
return unexpected;
|
||||
}
|
||||
|
||||
float getCurveValue(int index, float key) {
|
||||
|
|
|
@ -16,7 +16,7 @@ typedef Map3D<SCRIPT_TABLE_8, SCRIPT_TABLE_8, uint8_t, int16_t, int16_t> fsio8_M
|
|||
void initScriptImpl();
|
||||
|
||||
float getCurveValue(int index, float key);
|
||||
int getCurveIndexByName(const char *name);
|
||||
int getTableIndexByName(const char *name);
|
||||
int getSettingIndexByName(const char *name);
|
||||
expected<int> getCurveIndexByName(const char *name);
|
||||
expected<int> getTableIndexByName(const char *name);
|
||||
expected<int> getSettingIndexByName(const char *name);
|
||||
ValueProvider3D *getscriptTable(int index);
|
||||
|
|
|
@ -286,8 +286,7 @@ void TriggerWaveform::addEvent(angle_t angle, trigger_wheel_e const channelIndex
|
|||
return;
|
||||
}
|
||||
|
||||
int exactMatch = wave.findAngleMatch(angle);
|
||||
if (exactMatch != (int)EFI_ERROR_CODE) {
|
||||
if (wave.findAngleMatch(angle)) {
|
||||
warning(CUSTOM_ERR_SAME_ANGLE, "same angle: not supported");
|
||||
setShapeDefinitionError(true);
|
||||
return;
|
||||
|
|
|
@ -119,9 +119,9 @@ static void configureFordAspireTriggerWaveform(TriggerWaveform * s) {
|
|||
ASSERT_FLOAT_EQ(121.90 / 720, s->wave.getSwitchTime(1));
|
||||
ASSERT_FLOAT_EQ(657.03 / 720, s->wave.getSwitchTime(8));
|
||||
|
||||
ASSERT_EQ( 0, s->wave.findAngleMatch(53.747 / 720.0)) << "expecting 0";
|
||||
assertEqualsM("expecting not found", -1, s->wave.findAngleMatch(53 / 720.0));
|
||||
ASSERT_EQ(7, s->wave.findAngleMatch(588.045 / 720.0));
|
||||
ASSERT_EQ(0, s->wave.findAngleMatch(53.747 / 720.0).value_or(-1)) << "expecting 0";
|
||||
ASSERT_FALSE(s->wave.findAngleMatch(53 / 720.0).Valid) << "expecting not found";
|
||||
ASSERT_EQ(7, s->wave.findAngleMatch(588.045 / 720.0).value_or(-1));
|
||||
|
||||
ASSERT_EQ( 0, s->wave.findInsertionAngle(23.747 / 720.0)) << "expecting 0";
|
||||
ASSERT_EQ( 1, s->wave.findInsertionAngle(63.747 / 720.0)) << "expecting 1";
|
||||
|
|
|
@ -24,8 +24,8 @@ TEST(LuaHooks, TestCurve) {
|
|||
strcpy(engineConfiguration->scriptCurveName[3], "hello");
|
||||
setLinearCurve(config->scriptCurve4, 500, 600, 1);
|
||||
|
||||
int index = getCurveIndexByName("helLO");
|
||||
ASSERT_EQ(index, 3);
|
||||
auto index = getCurveIndexByName("helLO");
|
||||
ASSERT_EQ(index.value_or(-1), 3);
|
||||
|
||||
EXPECT_EQ(testLuaReturnsNumberOrNil(curveTestScript).value_or(0), 540);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue