reducing code duplication

This commit is contained in:
rusefi 2020-01-26 06:28:33 -05:00
parent 080e7e12db
commit 51ab9f5b57
4 changed files with 10 additions and 5 deletions

View File

@ -261,8 +261,8 @@ void Engine::OnTriggerStateDecodingError() {
TRIGGER_WAVEFORM(expectedEventCount[0]),
TRIGGER_WAVEFORM(expectedEventCount[1]),
TRIGGER_WAVEFORM(expectedEventCount[2]));
triggerCentral.triggerState.lastDecodingErrorTime = getTimeNowNt();
triggerCentral.triggerState.someSortOfTriggerError = true;
triggerCentral.triggerState.setTriggerErrorState();
triggerCentral.triggerState.totalTriggerErrorCounter++;
if (CONFIG(verboseTriggerSynchDetails) || (triggerCentral.triggerState.someSortOfTriggerError && !CONFIG(silentTriggerError))) {
@ -295,8 +295,7 @@ void Engine::OnTriggerInvalidIndex(int currentIndex) {
// let's not show a warning if we are just starting to spin
if (GET_RPM_VALUE != 0) {
warning(CUSTOM_SYNC_ERROR, "sync error: index #%d above total size %d", currentIndex, triggerCentral.triggerShape.getSize());
triggerCentral.triggerState.lastDecodingErrorTime = getTimeNowNt();
triggerCentral.triggerState.someSortOfTriggerError = true;
triggerCentral.triggerState.setTriggerErrorState();
}
}

View File

@ -82,6 +82,11 @@ void TriggerState::resetTriggerState() {
isFirstEvent = true;
}
void TriggerState::setTriggerErrorState() {
lastDecodingErrorTime = getTimeNowNt();
someSortOfTriggerError = true;
}
void TriggerState::resetCurrentCycleState() {
memset(currentCycle.eventCount, 0, sizeof(currentCycle.eventCount));
memset(currentCycle.timeOfPreviousEventNt, 0, sizeof(currentCycle.timeOfPreviousEventNt));

View File

@ -87,6 +87,8 @@ public:
bool shaft_is_synchronized;
efitick_t mostRecentSyncTime;
void setTriggerErrorState();
efitick_t lastDecodingErrorTime;
// the boolean flag is a performance optimization so that complex comparison is avoided if no error
bool someSortOfTriggerError;

View File

@ -21,7 +21,6 @@
#include "trigger_universal.h"
extern bool printTriggerDebug;
extern float actualSynchGap;
static void fireEvent(EngineTestHelper *eth, bool isRise) {
// mostly we fire only rise events (useOnlyRisingEdgeForTrigger=true).