instant RPM for idle control #925

refactoring
This commit is contained in:
rusefi 2019-09-09 14:41:26 -04:00
parent 7ed0bb53c9
commit ba9de596d6
1 changed files with 9 additions and 6 deletions

View File

@ -192,7 +192,7 @@ void TriggerStateWithRunningStatistics::movePreSynchTimestamps(DECLARE_ENGINE_PA
} }
} }
float TriggerStateWithRunningStatistics::calculateInstantRpm(int *prevIndex, efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) { float TriggerStateWithRunningStatistics::calculateInstantRpm(int *prevIndexOut, efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
int current_index = currentCycle.current_index; // local copy so that noone changes the value on us int current_index = currentCycle.current_index; // local copy so that noone changes the value on us
timeOfLastEvent[current_index] = nowNt; timeOfLastEvent[current_index] = nowNt;
/** /**
@ -206,11 +206,15 @@ float TriggerStateWithRunningStatistics::calculateInstantRpm(int *prevIndex, efi
angle_t previousAngle = currentAngle - 90; angle_t previousAngle = currentAngle - 90;
fixAngle(previousAngle, "prevAngle", CUSTOM_ERR_6560); fixAngle(previousAngle, "prevAngle", CUSTOM_ERR_6560);
// todo: prevIndex should be pre-calculated // todo: prevIndex should be pre-calculated
*prevIndex = TRIGGER_SHAPE(triggerIndexByAngle[(int)previousAngle]); int prevIndex = TRIGGER_SHAPE(triggerIndexByAngle[(int)previousAngle]);
if (prevIndexOut != NULL) {
*prevIndexOut = prevIndex;
}
// now let's get precise angle for that event // now let's get precise angle for that event
angle_t prevIndexAngle = TRIGGER_SHAPE(eventAngles[*prevIndex]); angle_t prevIndexAngle = TRIGGER_SHAPE(eventAngles[prevIndex]);
efitick_t time90ago = timeOfLastEvent[*prevIndex]; efitick_t time90ago = timeOfLastEvent[prevIndex];
if (time90ago == 0) { if (time90ago == 0) {
return prevInstantRpmValue; return prevInstantRpmValue;
} }
@ -252,8 +256,7 @@ void TriggerStateWithRunningStatistics::setLastEventTimeForInstantRpm(efitime_t
void TriggerStateWithRunningStatistics::runtimeStatistics(efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) { void TriggerStateWithRunningStatistics::runtimeStatistics(efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
if (engineConfiguration->debugMode == DBG_INSTANT_RPM) { if (engineConfiguration->debugMode == DBG_INSTANT_RPM) {
int prevIndex; instantRpm = calculateInstantRpm(NULL, nowNt PASS_ENGINE_PARAMETER_SUFFIX);
instantRpm = calculateInstantRpm(&prevIndex, nowNt PASS_ENGINE_PARAMETER_SUFFIX);
} }
if (ENGINE(sensorChartMode) == SC_RPM_ACCEL || ENGINE(sensorChartMode) == SC_DETAILED_RPM) { if (ENGINE(sensorChartMode) == SC_RPM_ACCEL || ENGINE(sensorChartMode) == SC_DETAILED_RPM) {
int prevIndex; int prevIndex;