refactoring - reducing code duplication

This commit is contained in:
rusefi 2017-07-10 22:08:55 -04:00
parent 80f3ee1d93
commit 86b0c4977e
5 changed files with 12 additions and 3 deletions

View File

@ -75,6 +75,13 @@ static efitimeus_t getNextSwitchTimeUs(PwmConfig *state) {
return NT2US(state->safe.startNt + timeToSwitchNt);
}
void PwmConfig::setFrequency(float frequency) {
/**
* see #handleCycleStart()
*/
periodNt = US2NT(frequency2periodUs(frequency));
}
void PwmConfig::handleCycleStart() {
if (safe.phaseIndex == 0) {
if (cycleCallback != NULL) {

View File

@ -50,6 +50,7 @@ public:
pwm_cycle_callback *cycleCallback,
pwm_gen_callback *callback);
void setFrequency(float frequency);
void handleCycleStart();

View File

@ -210,6 +210,7 @@ static ALWAYS_INLINE void handleSparkEvent(bool limitedSpark, uint32_t trgEventI
}
}
// todo: make this a class method?
#define assertPinAssigned(output) { \
if (!output->isInitialized()) { \
warning(CUSTOM_OBD_COIL_PIN_NOT_ASSIGNED, "no_pin_cl #%s", (output)->name); \

View File

@ -109,8 +109,8 @@ void setTriggerEmulatorRPM(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
triggerSignal.periodNt = NAN;
} else {
float rpmM = getRpmMultiplier(engineConfiguration->operationMode);
float gRpm = rpm * rpmM / 60.0; // per minute converted to per second
triggerSignal.periodNt = US2NT(frequency2periodUs(gRpm));
float rPerSecond = rpm * rpmM / 60.0; // per minute converted to per second
triggerSignal.setFrequency(rPerSecond);
}
#if EFI_ENGINE_SNIFFER
if (engine->isTestMode)

View File

@ -46,7 +46,7 @@ void startSimplePwm(PwmConfig *state, const char *msg, OutputPin *output, float
state->outputPins[0] = output;
state->periodNt = US2NT(frequency2periodUs(frequency));
state->setFrequency(frequency);
state->weComplexInit(msg, 2, switchTimes, 1, pinStates, NULL, stateChangeCallback);
}