refactoring - magic constant bad

This commit is contained in:
rusefillc 2021-11-07 00:03:16 -04:00
parent 334bf249ec
commit 656b8c3429
3 changed files with 10 additions and 5 deletions

View File

@ -30,6 +30,9 @@ typedef unsigned int time_t;
#define DEFAULT_FUEL_LOAD_COUNT 16
#define DEFAULT_IGN_LOAD_COUNT 16
#define TWO_STROKE_CYCLE_DURATION 360
#define FOUR_STROKE_CYCLE_DURATION 720
// gasoline E0
#define STOICH_RATIO 14.7f

View File

@ -118,14 +118,14 @@ int TriggerWaveform::getTriggerWaveformSynchPointIndex() const {
angle_t TriggerWaveform::getCycleDuration() const {
switch (operationMode) {
case FOUR_STROKE_THREE_TIMES_CRANK_SENSOR:
return 720 / SYMMETRICAL_THREE_TIMES_CRANK_SENSOR_DIVIDER;
return FOUR_STROKE_CYCLE_DURATION / SYMMETRICAL_THREE_TIMES_CRANK_SENSOR_DIVIDER;
case FOUR_STROKE_SYMMETRICAL_CRANK_SENSOR:
return 720 / SYMMETRICAL_CRANK_SENSOR_DIVIDER;
return FOUR_STROKE_CYCLE_DURATION / SYMMETRICAL_CRANK_SENSOR_DIVIDER;
case FOUR_STROKE_CRANK_SENSOR:
case TWO_STROKE:
return 360;
return TWO_STROKE_CYCLE_DURATION;
default:
return 720;
return FOUR_STROKE_CYCLE_DURATION;
}
}

View File

@ -303,6 +303,8 @@ private:
operation_mode_e operationMode;
};
#define MAX(a,b) (((a)>(b))?(a):(b))
/**
* Misc values calculated from TriggerWaveform
*/
@ -318,7 +320,7 @@ public:
* this cache allows us to find a close-enough (with one degree precision) trigger wheel index by
* given angle with fast constant speed. That's a performance optimization for event scheduling.
*/
uint16_t triggerIndexByAngle[720];
uint16_t triggerIndexByAngle[MAX(TWO_STROKE_CYCLE_DURATION, FOUR_STROKE_CYCLE_DURATION)];
};
void findTriggerPosition(