encapsulate stuff properly (#4154)

This commit is contained in:
Matthew Kennedy 2022-05-09 12:46:36 -07:00 committed by GitHub
parent 2161751187
commit 55fdd3f3c7
3 changed files with 18 additions and 18 deletions

View File

@ -113,11 +113,7 @@ static bool vvtWithRealDecoder(vvt_mode_e vvtMode) {
static angle_t syncAndReport(TriggerCentral *tc, int divider, int remainder) { static angle_t syncAndReport(TriggerCentral *tc, int divider, int remainder) {
angle_t engineCycle = getEngineCycle(engine->getOperationMode()); angle_t engineCycle = getEngineCycle(engine->getOperationMode());
angle_t offset = tc->triggerState.syncEnginePhase(divider, remainder, engineCycle); return tc->triggerState.syncEnginePhase(divider, remainder, engineCycle);
if (offset > 0) {
tc->triggerState.vvtSyncCounter++;
}
return offset;
} }
static void turnOffAllDebugFields(void *arg) { static void turnOffAllDebugFields(void *arg) {

View File

@ -80,8 +80,6 @@ void TriggerState::resetTriggerState() {
totalEventCountBase = 0; totalEventCountBase = 0;
isFirstEvent = true; isFirstEvent = true;
synchronizedPhase.init();
} }
void TriggerState::setTriggerErrorState() { void TriggerState::setTriggerErrorState() {
@ -227,6 +225,8 @@ void TriggerStateWithRunningStatistics::resetTriggerState() {
spinningEventIndex = 0; spinningEventIndex = 0;
prevInstantRpmValue = 0; prevInstantRpmValue = 0;
m_instantRpm = 0; m_instantRpm = 0;
synchronizedPhase.init();
} }
void TriggerStateWithRunningStatistics::movePreSynchTimestamps() { void TriggerStateWithRunningStatistics::movePreSynchTimestamps() {
@ -394,7 +394,7 @@ void TriggerCentral::validateCamVvtCounters() {
} }
} }
angle_t TriggerState::syncEnginePhase(int divider, int remainder, angle_t engineCycle) { angle_t TriggerStateWithRunningStatistics::syncEnginePhase(int divider, int remainder, angle_t engineCycle) {
efiAssert(OBD_PCM_Processor_Fault, remainder < divider, "syncEnginePhase", false); efiAssert(OBD_PCM_Processor_Fault, remainder < divider, "syncEnginePhase", false);
angle_t totalShift = 0; angle_t totalShift = 0;
while (getTotalRevolutionCounter() % divider != remainder) { while (getTotalRevolutionCounter() % divider != remainder) {
@ -410,6 +410,10 @@ angle_t TriggerState::syncEnginePhase(int divider, int remainder, angle_t engine
// Allow injection/ignition to happen, we've now fully sync'd the crank based on new cam information // Allow injection/ignition to happen, we've now fully sync'd the crank based on new cam information
synchronizedPhase.reset(); synchronizedPhase.reset();
if (totalShift > 0) {
vvtSyncCounter++;
}
return totalShift; return totalShift;
} }

View File

@ -86,7 +86,6 @@ public:
* this is important for crank-based virtual trigger and VVT magic * this is important for crank-based virtual trigger and VVT magic
*/ */
void incrementTotalEventCounter(); void incrementTotalEventCounter();
angle_t syncEnginePhase(int divider, int remainder, angle_t engineCycle);
efitime_t getTotalEventCounter() const; efitime_t getTotalEventCounter() const;
@ -156,13 +155,6 @@ public:
const trigger_config_s& triggerConfig const trigger_config_s& triggerConfig
); );
// Returns true if syncEnginePhase has been called,
// i.e. if we have enough VVT information to have full sync on
// an indeterminite crank pattern
bool hasSynchronizedPhase() const {
return !synchronizedPhase.hasElapsedSec(3);
}
private: private:
void resetCurrentCycleState(); void resetCurrentCycleState();
bool isSyncPoint(const TriggerWaveform& triggerShape, trigger_type_e triggerType) const; bool isSyncPoint(const TriggerWaveform& triggerShape, trigger_type_e triggerType) const;
@ -172,8 +164,6 @@ private:
int64_t totalEventCountBase; int64_t totalEventCountBase;
bool isFirstEvent; bool isFirstEvent;
Timer synchronizedPhase;
}; };
// we only need 90 degrees of events so /4 or maybe even /8 should work? // we only need 90 degrees of events so /4 or maybe even /8 should work?
@ -188,6 +178,8 @@ public:
TriggerStateWithRunningStatistics(); TriggerStateWithRunningStatistics();
void resetTriggerState() override; void resetTriggerState() override;
angle_t syncEnginePhase(int divider, int remainder, angle_t engineCycle);
float getInstantRpm() const { float getInstantRpm() const {
return m_instantRpm; return m_instantRpm;
} }
@ -221,6 +213,13 @@ public:
*/ */
void setLastEventTimeForInstantRpm(efitick_t nowNt); void setLastEventTimeForInstantRpm(efitick_t nowNt);
// Returns true if syncEnginePhase has been called,
// i.e. if we have enough VVT information to have full sync on
// an indeterminite crank pattern
bool hasSynchronizedPhase() const {
return !synchronizedPhase.hasElapsedSec(3);
}
private: private:
float calculateInstantRpm( float calculateInstantRpm(
TriggerWaveform const & triggerShape, TriggerFormDetails *triggerFormDetails, TriggerWaveform const & triggerShape, TriggerFormDetails *triggerFormDetails,
@ -229,6 +228,7 @@ private:
float m_instantRpm = 0; float m_instantRpm = 0;
float m_instantRpmRatio = 0; float m_instantRpmRatio = 0;
Timer synchronizedPhase;
}; };
angle_t getEngineCycle(operation_mode_e operationMode); angle_t getEngineCycle(operation_mode_e operationMode);