rusefi-1/firmware/controllers/core/state_sequence.cpp

50 lines
1.4 KiB
C++
Raw Normal View History

2015-07-10 06:01:56 -07:00
/**
* @file state_sequence.cpp
2015-07-10 06:01:56 -07:00
*
* @date May 18, 2014
2020-01-13 18:57:43 -08:00
* @author Andrey Belomutskiy, (c) 2012-2020
2015-07-10 06:01:56 -07:00
*/
#include "pch.h"
#include "state_sequence.h"
2015-07-10 06:01:56 -07:00
#include "trigger_structure.h"
void MultiChannelStateSequence::checkSwitchTimes(const float scale) const {
efiAssertVoid(CUSTOM_ERR_WAVE_1, phaseCount > 0, "StateSequence cannot be empty");
if (getSwitchTime(phaseCount - 1) != 1) {
2022-04-13 18:51:15 -07:00
#if EFI_UNIT_TEST
for (int index = 0;index < phaseCount;index ++) {
printf("switch time index=%d angle=%f\n", index, getSwitchTime(index));
}
2022-04-13 18:51:15 -07:00
#endif // EFI_UNIT_TEST
firmwareError(CUSTOM_ERR_WAVE_1, "[count=%d] last switch time has to be 1/%f not %.2f/%f",
phaseCount,
scale, getSwitchTime(phaseCount - 1),
scale * getSwitchTime(phaseCount - 1));
2015-07-10 06:01:56 -07:00
return;
}
for (int i = 0; i < phaseCount - 1; i++) {
if (getSwitchTime(i) >= getSwitchTime(i + 1)) {
firmwareError(CUSTOM_ERR_WAVE_2, "invalid switchTimes @%d: %.2f/%.2f",
i, getSwitchTime(i), getSwitchTime(i + 1));
2015-07-10 06:01:56 -07:00
}
}
}
2018-12-08 13:38:44 -08:00
int MultiChannelStateSequence::findInsertionAngle(const float angle) const {
for (int i = phaseCount - 1; i >= 0; i--) {
if (angle > getSwitchTime(i))
2018-12-08 13:38:44 -08:00
return i + 1;
}
return 0;
}
int MultiChannelStateSequence::findAngleMatch(const float angle) const {
for (int i = 0; i < phaseCount; i++) {
if (isSameF(getSwitchTime(i), angle))
2018-12-08 13:38:44 -08:00
return i;
}
return EFI_ERROR_CODE;
}