refactoring - reducing code duplication
This commit is contained in:
parent
968fcd7e74
commit
fe69c7ae4e
|
@ -75,6 +75,13 @@ static efitimeus_t getNextSwitchTimeUs(PwmConfig *state) {
|
||||||
return NT2US(state->safe.startNt + timeToSwitchNt);
|
return NT2US(state->safe.startNt + timeToSwitchNt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PwmConfig::setFrequency(float frequency) {
|
||||||
|
/**
|
||||||
|
* see #handleCycleStart()
|
||||||
|
*/
|
||||||
|
periodNt = US2NT(frequency2periodUs(frequency));
|
||||||
|
}
|
||||||
|
|
||||||
void PwmConfig::handleCycleStart() {
|
void PwmConfig::handleCycleStart() {
|
||||||
if (safe.phaseIndex == 0) {
|
if (safe.phaseIndex == 0) {
|
||||||
if (cycleCallback != NULL) {
|
if (cycleCallback != NULL) {
|
||||||
|
|
|
@ -50,6 +50,7 @@ public:
|
||||||
pwm_cycle_callback *cycleCallback,
|
pwm_cycle_callback *cycleCallback,
|
||||||
pwm_gen_callback *callback);
|
pwm_gen_callback *callback);
|
||||||
|
|
||||||
|
void setFrequency(float frequency);
|
||||||
|
|
||||||
void handleCycleStart();
|
void handleCycleStart();
|
||||||
|
|
||||||
|
|
|
@ -210,6 +210,7 @@ static ALWAYS_INLINE void handleSparkEvent(bool limitedSpark, uint32_t trgEventI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo: make this a class method?
|
||||||
#define assertPinAssigned(output) { \
|
#define assertPinAssigned(output) { \
|
||||||
if (!output->isInitialized()) { \
|
if (!output->isInitialized()) { \
|
||||||
warning(CUSTOM_OBD_COIL_PIN_NOT_ASSIGNED, "no_pin_cl #%s", (output)->name); \
|
warning(CUSTOM_OBD_COIL_PIN_NOT_ASSIGNED, "no_pin_cl #%s", (output)->name); \
|
||||||
|
|
|
@ -109,8 +109,8 @@ void setTriggerEmulatorRPM(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
triggerSignal.periodNt = NAN;
|
triggerSignal.periodNt = NAN;
|
||||||
} else {
|
} else {
|
||||||
float rpmM = getRpmMultiplier(engineConfiguration->operationMode);
|
float rpmM = getRpmMultiplier(engineConfiguration->operationMode);
|
||||||
float gRpm = rpm * rpmM / 60.0; // per minute converted to per second
|
float rPerSecond = rpm * rpmM / 60.0; // per minute converted to per second
|
||||||
triggerSignal.periodNt = US2NT(frequency2periodUs(gRpm));
|
triggerSignal.setFrequency(rPerSecond);
|
||||||
}
|
}
|
||||||
#if EFI_ENGINE_SNIFFER
|
#if EFI_ENGINE_SNIFFER
|
||||||
if (engine->isTestMode)
|
if (engine->isTestMode)
|
||||||
|
|
|
@ -46,7 +46,7 @@ void startSimplePwm(PwmConfig *state, const char *msg, OutputPin *output, float
|
||||||
|
|
||||||
state->outputPins[0] = output;
|
state->outputPins[0] = output;
|
||||||
|
|
||||||
state->periodNt = US2NT(frequency2periodUs(frequency));
|
state->setFrequency(frequency);
|
||||||
state->weComplexInit(msg, 2, switchTimes, 1, pinStates, NULL, stateChangeCallback);
|
state->weComplexInit(msg, 2, switchTimes, 1, pinStates, NULL, stateChangeCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue