More trigger encapsulation (#4207)

* trigger decoder returns a result

* TriggerFormDetails

* s

* don't reach out and touch the engine
This commit is contained in:
Matthew Kennedy 2022-05-29 10:49:00 -07:00 committed by GitHub
parent 6ea78efbe7
commit cf51533f45
6 changed files with 17 additions and 16 deletions

View File

@ -443,7 +443,7 @@ void prepareOutputSignals() {
prepareIgnitionPinIndices(engineConfiguration->ignitionMode); prepareIgnitionPinIndices(engineConfiguration->ignitionMode);
TRIGGER_WAVEFORM(prepareShape(&engine->triggerCentral.triggerFormDetails)); TRIGGER_WAVEFORM(prepareShape(engine->triggerCentral.triggerFormDetails));
// Fuel schedule may now be completely wrong, force a reset // Fuel schedule may now be completely wrong, force a reset
engine->injectionEvents.invalidate(); engine->injectionEvents.invalidate();

View File

@ -417,14 +417,14 @@ void findTriggerPosition(TriggerWaveform *triggerShape,
} }
} }
void TriggerWaveform::prepareShape(TriggerFormDetails *details) { void TriggerWaveform::prepareShape(TriggerFormDetails& details) {
#if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT #if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT
if (shapeDefinitionError) { if (shapeDefinitionError) {
// Nothing to do here if there's a problem with the trigger shape // Nothing to do here if there's a problem with the trigger shape
return; return;
} }
prepareEventAngles(this, details); details.prepareEventAngles(this);
#endif #endif
} }

View File

@ -194,7 +194,7 @@ public:
* TODO this should be migrated to CRANKshaft revolution, this would go together * TODO this should be migrated to CRANKshaft revolution, this would go together
* this variable is public for performance reasons (I want to avoid costs of method if it's not inlined) * this variable is public for performance reasons (I want to avoid costs of method if it's not inlined)
* but name is supposed to hint at the fact that decoders should not be assigning to it * but name is supposed to hint at the fact that decoders should not be assigning to it
* Please use "getTriggerSize()" macro or "getSize()" method to read this value * Please use "getSize()" function to read this value
*/ */
MultiChannelStateSequenceWithData<PWM_PHASE_MAX_COUNT> wave; MultiChannelStateSequenceWithData<PWM_PHASE_MAX_COUNT> wave;
@ -247,7 +247,7 @@ public:
size_t getSize() const; size_t getSize() const;
int getTriggerWaveformSynchPointIndex() const; int getTriggerWaveformSynchPointIndex() const;
void prepareShape(TriggerFormDetails *details); void prepareShape(TriggerFormDetails& details);
/** /**
* This private method should only be used to prepare the array of pre-calculated values * This private method should only be used to prepare the array of pre-calculated values
@ -297,6 +297,8 @@ private:
*/ */
class TriggerFormDetails { class TriggerFormDetails {
public: public:
void prepareEventAngles(TriggerWaveform *shape);
/** /**
* These angles are in event coordinates - with synchronization point located at angle zero. * These angles are in event coordinates - with synchronization point located at angle zero.
* These values are pre-calculated for performance reasons. * These values are pre-calculated for performance reasons.

View File

@ -690,9 +690,9 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta
* If we only have a crank position sensor with four stroke, here we are extending crank revolutions with a 360 degree * If we only have a crank position sensor with four stroke, here we are extending crank revolutions with a 360 degree
* cycle into a four stroke, 720 degrees cycle. * cycle into a four stroke, 720 degrees cycle.
*/ */
int crankDivider = getCrankDivider(engine->getOperationMode()); int crankDivider = getCrankDivider(triggerShape.getOperationMode());
int crankInternalIndex = triggerState.getTotalRevolutionCounter() % crankDivider; int crankInternalIndex = triggerState.getTotalRevolutionCounter() % crankDivider;
int triggerIndexForListeners = decodeResult.Value.CurrentIndex + (crankInternalIndex * getTriggerSize()); int triggerIndexForListeners = decodeResult.Value.CurrentIndex + (crankInternalIndex * triggerShape.getSize());
if (triggerIndexForListeners == 0) { if (triggerIndexForListeners == 0) {
m_syncPointTimer.reset(timestamp); m_syncPointTimer.reset(timestamp);
} }

View File

@ -147,8 +147,7 @@ void calculateTriggerSynchPoint(
} }
} }
void prepareEventAngles(TriggerWaveform *shape, void TriggerFormDetails::prepareEventAngles(TriggerWaveform *shape) {
TriggerFormDetails *details) {
int triggerShapeSynchPointIndex = shape->triggerShapeSynchPointIndex; int triggerShapeSynchPointIndex = shape->triggerShapeSynchPointIndex;
if (triggerShapeSynchPointIndex == EFI_ERROR_CODE) { if (triggerShapeSynchPointIndex == EFI_ERROR_CODE) {
return; return;
@ -160,7 +159,7 @@ void prepareEventAngles(TriggerWaveform *shape,
size_t length = shape->getLength(); size_t length = shape->getLength();
memset(details->eventAngles, 0, sizeof(details->eventAngles)); memset(eventAngles, 0, sizeof(eventAngles));
// this may be <length for some triggers like symmetrical crank Miata NB // this may be <length for some triggers like symmetrical crank Miata NB
size_t triggerShapeLength = shape->getSize(); size_t triggerShapeLength = shape->getSize();
@ -171,9 +170,9 @@ void prepareEventAngles(TriggerWaveform *shape,
for (size_t eventIndex = 0; eventIndex < length; eventIndex++) { for (size_t eventIndex = 0; eventIndex < length; eventIndex++) {
if (eventIndex == 0) { if (eventIndex == 0) {
// explicit check for zero to avoid issues where logical zero is not exactly zero due to float nature // explicit check for zero to avoid issues where logical zero is not exactly zero due to float nature
details->eventAngles[0] = 0; eventAngles[0] = 0;
// this value would be used in case of front-only // this value would be used in case of front-only
details->eventAngles[1] = 0; eventAngles[1] = 0;
} else { } else {
// Rotate the trigger around so that the sync point is at position 0 // Rotate the trigger around so that the sync point is at position 0
auto wrappedIndex = (shape->triggerShapeSynchPointIndex + eventIndex) % length; auto wrappedIndex = (shape->triggerShapeSynchPointIndex + eventIndex) % length;
@ -196,11 +195,11 @@ void prepareEventAngles(TriggerWaveform *shape,
// In case this is a rising event, replace the following fall event with the rising as well // In case this is a rising event, replace the following fall event with the rising as well
if (shape->isRiseEvent[triggerDefinitionIndex]) { if (shape->isRiseEvent[triggerDefinitionIndex]) {
riseOnlyIndex += 2; riseOnlyIndex += 2;
details->eventAngles[riseOnlyIndex] = angle; eventAngles[riseOnlyIndex] = angle;
details->eventAngles[riseOnlyIndex + 1] = angle; eventAngles[riseOnlyIndex + 1] = angle;
} }
} else { } else {
details->eventAngles[eventIndex] = angle; eventAngles[eventIndex] = angle;
} }
} }
} }

View File

@ -390,8 +390,8 @@ void EngineTestHelper::executeUntil(int timeUs) {
} }
void setupSimpleTestEngineWithMafAndTT_ONE_trigger(EngineTestHelper *eth, injection_mode_e injectionMode) { void setupSimpleTestEngineWithMafAndTT_ONE_trigger(EngineTestHelper *eth, injection_mode_e injectionMode) {
setupSimpleTestEngineWithMaf(eth, injectionMode, TT_ONE);
setCamOperationMode(); setCamOperationMode();
setupSimpleTestEngineWithMaf(eth, injectionMode, TT_ONE);
} }
void setVerboseTrigger(bool isEnabled) { void setVerboseTrigger(bool isEnabled) {