only: trigger refactoring reducing code duplication

This commit is contained in:
Andrey 2024-01-15 17:28:47 -05:00 committed by rusefillc
parent a27a5e91e6
commit c15aa75922
3 changed files with 7 additions and 4 deletions

View File

@ -96,7 +96,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;

View File

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

View File

@ -78,9 +78,9 @@ static int atTriggerVersions[NUM_EMULATOR_CHANNELS] = { 0 };
static float getRpmMultiplier(operation_mode_e mode) {
switch (mode) {
case FOUR_STROKE_SYMMETRICAL_CRANK_SENSOR:
return SYMMETRICAL_CRANK_SENSOR_DIVIDER / 2;
return getCrankDivider(mode) / 2;
case FOUR_STROKE_THREE_TIMES_CRANK_SENSOR:
return SYMMETRICAL_THREE_TIMES_CRANK_SENSOR_DIVIDER / 2;
return getCrankDivider(mode) / 2;
case FOUR_STROKE_SIX_TIMES_CRANK_SENSOR:
// todo: c'mon too much code duplication! at least reuse getCrankDivider when it works?!
return SYMMETRICAL_SIX_TIMES_CRANK_SENSOR_DIVIDER / 2;
@ -89,10 +89,12 @@ static float getRpmMultiplier(operation_mode_e mode) {
case FOUR_STROKE_CAM_SENSOR:
return 0.5;
case OM_NONE:
return 1;
case TWO_STROKE:
case FOUR_STROKE_CRANK_SENSOR:
// unit test coverage still runs if the value below is changed to '2' not a great sign!
return 1;
case FOUR_STROKE_CRANK_SENSOR:
return getCrankDivider(mode) / 2;
};
criticalError("We should not have reach this line");
return 1;