refactoring: reducing code duplication
This commit is contained in:
parent
02eed1c82c
commit
0fc9da6cfb
|
@ -34,11 +34,6 @@ TriggerEmulatorHelper::TriggerEmulatorHelper() {
|
||||||
EXTERN_ENGINE
|
EXTERN_ENGINE
|
||||||
;
|
;
|
||||||
|
|
||||||
static void fireShaftSignal(trigger_event_e signal) {
|
|
||||||
if (isUsefulSignal(signal, engineConfiguration))
|
|
||||||
hwHandleShaftSignal(signal);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TriggerEmulatorHelper::handleEmulatorCallback(PwmConfig *state, int stateIndex) {
|
void TriggerEmulatorHelper::handleEmulatorCallback(PwmConfig *state, int stateIndex) {
|
||||||
int prevIndex = (stateIndex + state->phaseCount - 1) % state->phaseCount;
|
int prevIndex = (stateIndex + state->phaseCount - 1) % state->phaseCount;
|
||||||
|
|
||||||
|
@ -55,17 +50,17 @@ void TriggerEmulatorHelper::handleEmulatorCallback(PwmConfig *state, int stateIn
|
||||||
|
|
||||||
if (primaryWheelState != newPrimaryWheelState) {
|
if (primaryWheelState != newPrimaryWheelState) {
|
||||||
primaryWheelState = newPrimaryWheelState;
|
primaryWheelState = newPrimaryWheelState;
|
||||||
fireShaftSignal(primaryWheelState ? SHAFT_PRIMARY_RISING : SHAFT_PRIMARY_FALLING);
|
hwHandleShaftSignal(primaryWheelState ? SHAFT_PRIMARY_RISING : SHAFT_PRIMARY_FALLING);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (secondaryWheelState != newSecondaryWheelState) {
|
if (secondaryWheelState != newSecondaryWheelState) {
|
||||||
secondaryWheelState = newSecondaryWheelState;
|
secondaryWheelState = newSecondaryWheelState;
|
||||||
fireShaftSignal(secondaryWheelState ? SHAFT_SECONDARY_RISING : SHAFT_SECONDARY_FALLING);
|
hwHandleShaftSignal(secondaryWheelState ? SHAFT_SECONDARY_RISING : SHAFT_SECONDARY_FALLING);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (thirdWheelState != new3rdWheelState) {
|
if (thirdWheelState != new3rdWheelState) {
|
||||||
thirdWheelState = new3rdWheelState;
|
thirdWheelState = new3rdWheelState;
|
||||||
fireShaftSignal(thirdWheelState ? SHAFT_3RD_RISING : SHAFT_3RD_FALLING);
|
hwHandleShaftSignal(thirdWheelState ? SHAFT_3RD_RISING : SHAFT_3RD_FALLING);
|
||||||
}
|
}
|
||||||
|
|
||||||
// print("hello %d\r\n", chTimeNow());
|
// print("hello %d\r\n", chTimeNow());
|
||||||
|
|
|
@ -74,8 +74,6 @@ static void shaft_icu_period_callback(ICUDriver *icup) {
|
||||||
// icucnt_t last_period = icuGetPeriod(icup); so far we are fine with system time
|
// icucnt_t last_period = icuGetPeriod(icup); so far we are fine with system time
|
||||||
trigger_event_e signal =
|
trigger_event_e signal =
|
||||||
isPrimary ? SHAFT_PRIMARY_FALLING : SHAFT_SECONDARY_FALLING;
|
isPrimary ? SHAFT_PRIMARY_FALLING : SHAFT_SECONDARY_FALLING;
|
||||||
if (CONFIG(useOnlyRisingEdgeForTrigger))
|
|
||||||
return;
|
|
||||||
hwHandleShaftSignal(signal);
|
hwHandleShaftSignal(signal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue