maybe more working MAP sampling (#3689)

* what if we do this

* cleanup

* s

* test
This commit is contained in:
Matthew Kennedy 2021-12-10 23:01:28 -08:00 committed by GitHub
parent 8016da48b7
commit 6de8364895
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 20 deletions

View File

@ -668,6 +668,7 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta
engine->outputChannels.currentEnginePhase = toothAngle;
#endif // EFI_TUNER_STUDIO
#if WITH_TS_STATE
if (engineConfiguration->vvtMode[0] == VVT_MAP_V_TWIN_ANOTHER) {
// we are trying to figure out which 360 half of the total 720 degree cycle is which, so we compare those in 360 degree sense.
auto toothAngle360 = toothAngle;
@ -678,36 +679,30 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta
if (mapCamPrevToothAngle < engineConfiguration->mapCamDetectionAnglePosition && toothAngle360 > engineConfiguration->mapCamDetectionAnglePosition) {
// we are somewhere close to 'mapCamDetectionAnglePosition'
float map = Sensor::getOrZero(SensorType::Map);
// warning: hack hack hack
float map = engine->outputChannels.instantMAPValue;
if (map > mapCamPrevCycleValue) {
#if WITH_TS_STATE
// Compute diff against the last time we were here
float diff = map - mapCamPrevCycleValue;
mapCamPrevCycleValue = map;
if (diff > 0) {
engine->outputChannels.TEMPLOG_map_peak++;
int revolutionCounter = engine->triggerCentral.triggerState.getTotalRevolutionCounter();
engine->outputChannels.TEMPLOG_MAP_AT_CYCLE_COUNT = revolutionCounter - prevChangeAtCycle;
prevChangeAtCycle = revolutionCounter;
#endif // WITH_TS_STATE
efitick_t stamp = getTimeNowNt();
hwHandleVvtCamSignal(TV_RISE, stamp, /*index*/0);
hwHandleVvtCamSignal(TV_FALL, stamp, /*index*/0);
hwHandleVvtCamSignal(TV_RISE, timestamp, /*index*/0);
hwHandleVvtCamSignal(TV_FALL, timestamp, /*index*/0);
}
#if WITH_TS_STATE
engine->outputChannels.TEMPLOG_MAP_AT_SPECIAL_POINT = map;
engine->outputChannels.TEMPLOG_MAP_AT_DIFF = map - mapCamPrevCycleValue;
#endif // WITH_TS_STATE
mapCamPrevCycleValue = map;
engine->outputChannels.TEMPLOG_MAP_AT_DIFF = diff;
}
mapCamPrevToothAngle = toothAngle360;
}
#endif // WITH_TS_STATE
}
}

View File

@ -77,7 +77,7 @@ TEST(trigger, map_cam_by_magic_point) {
engineConfiguration->camInputs[0] = GPIOA_0;
engineConfiguration->vvtMode[0] = VVT_MAP_V_TWIN_ANOTHER;
Sensor::setMockValue(SensorType::Map, 100);
engine->outputChannels.instantMAPValue = 100;
engineConfiguration->mapCamDetectionAnglePosition = 90;
@ -88,7 +88,7 @@ TEST(trigger, map_cam_by_magic_point) {
ASSERT_EQ(0, engine->outputChannels.vvtSyncCounter);
Sensor::setMockValue(SensorType::Map, 120);
engine->outputChannels.instantMAPValue = 120;
eth.smartFireTriggerEvents2(/*count*/4, /*delayMs*/200);
ASSERT_EQ(2, engine->outputChannels.TEMPLOG_map_peak);