deep rabbit holes are the best ones!

refactoring: encapsulation
This commit is contained in:
Andrey 2022-09-14 02:35:55 -04:00
parent 663c39afdc
commit 0e91914266
7 changed files with 24 additions and 21 deletions

View File

@ -147,10 +147,11 @@ void Engine::updateTriggerWaveform() {
* 'initState' instance of TriggerDecoderBase is used only to initialize 'this' TriggerWaveform instance
* #192 BUG real hardware trigger events could be coming even while we are initializing trigger
*/
calculateTriggerSynchPoint(engine->triggerCentral.triggerShape,
calculateTriggerSynchPoint(&engine->triggerCentral,
engine->triggerCentral.triggerShape,
initState);
engine->engineCycleEventCount = TRIGGER_WAVEFORM(getLength());
engine->triggerCentral.engineCycleEventCount = engine->triggerCentral.triggerShape.getLength();
}
for (int camIndex = 0; camIndex < CAMS_PER_BANK; camIndex++) {
@ -400,7 +401,7 @@ void Engine::OnTriggerSyncronization(bool wasSynchronized, bool isDecodingError)
#endif /* EFI_PROD_CODE */
}
engine->triggerErrorDetection.add(isDecodingError);
engine->triggerCentral.triggerErrorDetection.add(isDecodingError);
}
}

View File

@ -156,8 +156,6 @@ public:
return engineModules.get<get_t>();
}
cyclic_buffer<int> triggerErrorDetection;
#if EFI_TCU
GearControllerBase *gearController;
#endif
@ -296,11 +294,6 @@ public:
SensorsState sensors;
efitick_t mainRelayBenchStartNt = 0;
/**
* value of 'triggerShape.getLength()'
* pre-calculating this value is a performance optimization
*/
uint32_t engineCycleEventCount = 0;
void preCalculate();

View File

@ -223,7 +223,7 @@ static void handleFuel(uint32_t trgEventIndex, int rpm, efitick_t nowNt, float c
ScopePerf perf(PE::HandleFuel);
efiAssertVoid(CUSTOM_STACK_6627, getCurrentRemainingStack() > 128, "lowstck#3");
efiAssertVoid(CUSTOM_ERR_6628, trgEventIndex < engine->engineCycleEventCount, "handleFuel/event index");
efiAssertVoid(CUSTOM_ERR_6628, trgEventIndex < getTriggerCentral()->engineCycleEventCount, "handleFuel/event index");
if (trgEventIndex == 0) {
engine->tpsAccelEnrichment.onEngineCycleTps();

View File

@ -740,7 +740,7 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta
do {
// I don't love this.
nextToothIndex = (nextToothIndex + 1) % engine->engineCycleEventCount;
nextToothIndex = (nextToothIndex + 1) % engineCycleEventCount;
nextPhase = getTriggerCentral()->triggerFormDetails.eventAngles[nextToothIndex] - tdcPosition();
wrapAngle(nextPhase, "nextEnginePhase", CUSTOM_ERR_6555);
} while (nextPhase == currentPhase);
@ -983,7 +983,7 @@ void initTriggerCentral() {
* @return TRUE is something is wrong with trigger decoding
*/
bool TriggerCentral::isTriggerDecoderError() {
return engine->triggerErrorDetection.sum(6) > 4;
return triggerErrorDetection.sum(6) > 4;
}
#endif // EFI_SHAFT_POSITION_INPUT

View File

@ -56,6 +56,8 @@ public:
// GND input pins instead of leaving them floating
bool hwTriggerInputEnabled = true;
cyclic_buffer<int> triggerErrorDetection;
/**
* See also triggerSimulatorFrequency
*/
@ -86,6 +88,11 @@ public:
float mapCamPrevCycleValue = 0;
int prevChangeAtCycle = 0;
/**
* value of 'triggerShape.getLength()'
* pre-calculating this value is a performance optimization
*/
uint32_t engineCycleEventCount = 0;
/**
* true if a recent configuration change has changed any of the trigger settings which
* we have not adjusted for yet
@ -196,4 +203,9 @@ void onConfigurationChangeTriggerCallback();
#define SYMMETRICAL_THREE_TIMES_CRANK_SENSOR_DIVIDER 6
#define SYMMETRICAL_TWELVE_TIMES_CRANK_SENSOR_DIVIDER 24
void calculateTriggerSynchPoint(
TriggerCentral *triggerCentral,
TriggerWaveform& shape,
TriggerDecoderBase& state);
TriggerCentral * getTriggerCentral();

View File

@ -117,6 +117,7 @@ void TriggerWaveform::initializeSyncPoint(TriggerDecoderBase& state,
* Calculate 'shape.triggerShapeSynchPointIndex' value using 'TriggerDecoderBase *state'
*/
void calculateTriggerSynchPoint(
TriggerCentral *triggerCentral,
TriggerWaveform& shape,
TriggerDecoderBase& state) {
state.resetTriggerState();
@ -124,11 +125,11 @@ void calculateTriggerSynchPoint(
#if EFI_PROD_CODE
efiAssertVoid(CUSTOM_TRIGGER_STACK, getCurrentRemainingStack() > EXPECTED_REMAINING_STACK, "calc s");
#endif
engine->triggerErrorDetection.clear();
shape.initializeSyncPoint(state, engine->triggerCentral.primaryTriggerConfiguration);
triggerCentral->triggerErrorDetection.clear();
shape.initializeSyncPoint(state, triggerCentral->primaryTriggerConfiguration);
int length = shape.getLength();
engine->engineCycleEventCount = length;
triggerCentral->engineCycleEventCount = length;
efiAssertVoid(CUSTOM_SHAPE_LEN_ZERO, length > 0, "shapeLength=0");
if (shape.getSize() >= PWM_PHASE_MAX_COUNT) {
@ -161,7 +162,7 @@ void TriggerFormDetails::prepareEventAngles(TriggerWaveform *shape) {
size_t triggerShapeLength = shape->getSize();
assertAngleRange(shape->triggerShapeSynchPointIndex, "triggerShapeSynchPointIndex", CUSTOM_TRIGGER_SYNC_ANGLE2);
efiAssertVoid(CUSTOM_TRIGGER_CYCLE, engine->engineCycleEventCount != 0, "zero engineCycleEventCount");
efiAssertVoid(CUSTOM_TRIGGER_CYCLE, getTriggerCentral()->engineCycleEventCount != 0, "zero engineCycleEventCount");
for (size_t eventIndex = 0; eventIndex < length; eventIndex++) {
if (eventIndex == 0) {

View File

@ -277,8 +277,4 @@ public:
angle_t getEngineCycle(operation_mode_e operationMode);
void calculateTriggerSynchPoint(
TriggerWaveform& shape,
TriggerDecoderBase& state);
void prepareEventAngles(TriggerWaveform *shape, TriggerFormDetails *details);