Skip to content

Commit

Permalink
Stop trainers before changing model (#8075)
Browse files Browse the repository at this point in the history
Turn off SBUS trainer to allow model switch
  • Loading branch information
3djc authored and 3djc committed Nov 16, 2020
1 parent 377d253 commit 2a7aca9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 27 deletions.
3 changes: 2 additions & 1 deletion radio/src/storage/storage_common.cpp
Expand Up @@ -51,8 +51,9 @@ void preModelLoad()
if (pulsesStarted()) {
pausePulses();
}

pauseMixerCalculations();

stopTrainer();
}

void postRadioSettingsLoad()
Expand Down
66 changes: 40 additions & 26 deletions radio/src/trainer.cpp
Expand Up @@ -48,57 +48,71 @@ void checkTrainerSignalWarning()
}

#if defined(PCBSKY9X)
void stopTrainer()
{
stop_trainer_capture();
}

void checkTrainerSettings()
{
uint8_t requiredTrainerMode = SLAVE_MODE();

if (requiredTrainerMode != currentTrainerMode) {
currentTrainerMode = requiredTrainerMode;
if (requiredTrainerMode)
stop_trainer_capture();
stopTrainer();
else
init_trainer_capture();
}
}
#else
void checkTrainerSettings()
void stopTrainer()
{
uint8_t requiredTrainerMode = g_model.trainerData.mode;

if (requiredTrainerMode != currentTrainerMode) {
switch (currentTrainerMode) {
case TRAINER_MODE_MASTER_TRAINER_JACK:
stop_trainer_capture();
break;
switch (currentTrainerMode) {
case TRAINER_MODE_MASTER_TRAINER_JACK:
stop_trainer_capture();
break;

case TRAINER_MODE_SLAVE:
stop_trainer_ppm();
break;
case TRAINER_MODE_SLAVE:
stop_trainer_ppm();
break;

#if defined(TRAINER_MODULE_CPPM)
case TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE:
stop_trainer_module_cppm();
break;
case TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE:
stop_trainer_module_cppm();
break;
#endif

#if defined(TRAINER_MODULE_SBUS)
case TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE:
stop_trainer_module_sbus();
break;
case TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE:
stop_trainer_module_sbus();
break;
#endif

#if defined(HARDWARE_TRAINER_AUX_SERIAL)
case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT:
#if defined(TRAINER_BATTERY_COMPARTMENT)
case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT:
#if defined(AUX_SERIAL)
if (g_eeGeneral.auxSerialMode == UART_MODE_SBUS_TRAINER)
auxSerialStop();
if (g_eeGeneral.auxSerialMode == UART_MODE_SBUS_TRAINER)
auxSerialStop();
#endif
#if defined(AUX2_SERIAL)
if (g_eeGeneral.aux2SerialMode == UART_MODE_SBUS_TRAINER)
aux2SerialStop();
if (g_eeGeneral.aux2SerialMode == UART_MODE_SBUS_TRAINER)
aux2SerialStop();
#endif
break;
break;
#endif
}

currentTrainerMode = 0xFF;
}

void checkTrainerSettings()
{
uint8_t requiredTrainerMode = g_model.trainerData.mode;

if (requiredTrainerMode != currentTrainerMode) {
if (currentTrainerMode != 0xFF) {
stopTrainer();
}

currentTrainerMode = requiredTrainerMode;
Expand All @@ -120,7 +134,7 @@ void checkTrainerSettings()
break;
#endif

#if defined(HARDWARE_TRAINER_AUX_SERIAL)
#if defined(TRAINER_BATTERY_COMPARTMENT)
case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT:
#if defined(AUX_SERIAL)
if (g_eeGeneral.auxSerialMode == UART_MODE_SBUS_TRAINER)
Expand Down
1 change: 1 addition & 0 deletions radio/src/trainer.h
Expand Up @@ -35,6 +35,7 @@ extern uint8_t currentTrainerMode;

void checkTrainerSignalWarning();
void checkTrainerSettings();
void stopTrainer();
void forceResetTrainerSettings();

// Needs to be inlined to avoid slow function calls in ISR routines
Expand Down

0 comments on commit 2a7aca9

Please sign in to comment.