deduplicate getCrankDivider logic

This commit is contained in:
Matthew Kennedy 2024-01-16 22:59:45 -08:00
parent d7e356cebf
commit 6767a755bd
3 changed files with 18 additions and 12 deletions

View File

@ -88,7 +88,7 @@ expected<float> TriggerCentral::getCurrentEnginePhase(efitick_t nowNt) const {
/**
* todo: why is this method NOT reciprocal to getRpmMultiplier?!
*/
static int getCrankDivider(operation_mode_e operationMode) {
int getCrankDivider(operation_mode_e operationMode) {
switch (operationMode) {
case FOUR_STROKE_CRANK_SENSOR:
return 2;
@ -98,12 +98,16 @@ static int getCrankDivider(operation_mode_e operationMode) {
return SYMMETRICAL_THREE_TIMES_CRANK_SENSOR_DIVIDER;
case FOUR_STROKE_TWELVE_TIMES_CRANK_SENSOR:
return SYMMETRICAL_TWELVE_TIMES_CRANK_SENSOR_DIVIDER;
default:
case OM_NONE:
case FOUR_STROKE_CAM_SENSOR:
case TWO_STROKE:
// That's easy - trigger cycle matches engine cycle
return 1;
}
firmwareError(ObdCode::OBD_PCM_Processor_Fault, "unexpected operationMode in getCrankDivider");
return 1;
}
static bool vvtWithRealDecoder(vvt_mode_e vvtMode) {

View File

@ -215,3 +215,4 @@ void onConfigurationChangeTriggerCallback();
#define SYMMETRICAL_TWELVE_TIMES_CRANK_SENSOR_DIVIDER 24
TriggerCentral * getTriggerCentral();
int getCrankDivider(operation_mode_e operationMode);

View File

@ -66,18 +66,19 @@ static int atTriggerVersion = 0;
* todo: oh this method has only one usage? there must me another very similar method!
*/
static float getRpmMultiplier(operation_mode_e mode) {
if (mode == FOUR_STROKE_THREE_TIMES_CRANK_SENSOR) {
return SYMMETRICAL_THREE_TIMES_CRANK_SENSOR_DIVIDER / 2;
} else if (mode == FOUR_STROKE_SYMMETRICAL_CRANK_SENSOR) {
return SYMMETRICAL_CRANK_SENSOR_DIVIDER / 2;
} else if (mode == FOUR_STROKE_TWELVE_TIMES_CRANK_SENSOR) {
return SYMMETRICAL_TWELVE_TIMES_CRANK_SENSOR_DIVIDER / 2;
} else if (mode == FOUR_STROKE_CAM_SENSOR) {
return 0.5;
} else if (mode == FOUR_STROKE_CRANK_SENSOR) {
switch (mode) {
case FOUR_STROKE_SYMMETRICAL_CRANK_SENSOR:
case FOUR_STROKE_THREE_TIMES_CRANK_SENSOR:
case FOUR_STROKE_TWELVE_TIMES_CRANK_SENSOR:
case FOUR_STROKE_CRANK_SENSOR:
case FOUR_STROKE_CAM_SENSOR:
case OM_NONE:
return getCrankDivider(mode) / 2.0;
case TWO_STROKE:
// unit test coverage still runs if the value below is changed to '2' not a great sign!
// but HW CI insists that we have '1' here
return 1;
}
};
return 1;
}