diff --git a/radio/src/functions.cpp b/radio/src/functions.cpp index 9380c1d8d..adb8134d4 100644 --- a/radio/src/functions.cpp +++ b/radio/src/functions.cpp @@ -340,7 +340,11 @@ void evalFunctions() timerReset(CFN_PARAM(cfn)); break; case FUNC_RESET_FLIGHT: +#if defined(CPUARM) + mainRequestFlags |= (1 << REQUEST_FLIGHT_RESET); // on systems with threads flightReset() must not be called from the mixers thread! +#else flightReset(); +#endif // defined(CPUARM) break; #if defined(TELEMETRY_FRSKY) case FUNC_RESET_TELEMETRY: @@ -573,7 +577,7 @@ void evalFunctions() #if defined(PCBTARANIS) case FUNC_SCREENSHOT: if (!(functionsContext.activeSwitches & switch_mask)) { - requestScreenshot = true; + mainRequestFlags |= (1 << REQUEST_SCREENSHOT); } break; #endif diff --git a/radio/src/main_arm.cpp b/radio/src/main_arm.cpp index 1508f0538..c902d4dd1 100644 --- a/radio/src/main_arm.cpp +++ b/radio/src/main_arm.cpp @@ -22,7 +22,7 @@ uint8_t currentSpeakerVolume = 255; uint8_t requiredSpeakerVolume = 255; -uint8_t requestScreenshot = false; +uint8_t mainRequestFlags = 0; void handleUsbConnection() { @@ -399,6 +399,12 @@ void perMain() periodicTick(); DEBUG_TIMER_STOP(debugTimerPerMain1); + if (mainRequestFlags & (1 << REQUEST_FLIGHT_RESET)) { + TRACE("Executing requested Flight Reset"); + flightReset(); + mainRequestFlags &= ~(1 << REQUEST_FLIGHT_RESET); + } + event_t evt = getEvent(false); if (evt && (g_eeGeneral.backlightMode & e_backlight_mode_keys)) { // on keypress turn the light on @@ -455,9 +461,9 @@ void perMain() #endif #if defined(PCBTARANIS) - if (requestScreenshot) { - requestScreenshot = false; + if (mainRequestFlags & (1 << REQUEST_SCREENSHOT)) { writeScreenshot(); + mainRequestFlags &= ~(1 << REQUEST_SCREENSHOT); } #endif diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 0d53b7ea3..5093f868a 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -1347,8 +1347,13 @@ void clearMFP(); extern uint8_t requiredSpeakerVolume; #endif -#if defined(PCBTARANIS) -extern uint8_t requestScreenshot; +#if defined(CPUARM) +enum MainRequest { + REQUEST_SCREENSHOT, + REQUEST_FLIGHT_RESET, +}; + +extern uint8_t mainRequestFlags; #endif void checkBattery(); diff --git a/radio/src/tests/functions.cpp b/radio/src/tests/functions.cpp index 1c059a433..f10d16da9 100644 --- a/radio/src/tests/functions.cpp +++ b/radio/src/tests/functions.cpp @@ -42,23 +42,21 @@ TEST(SpecialFunctions, FlightReset) g_model.customFn[0].all.val = FUNC_RESET_FLIGHT; g_model.customFn[0].active = true; - // we (mis)use s_mixer_first_run_done for the flight reset detection - s_mixer_first_run_done = true; + mainRequestFlags = 0; evalFunctions(g_model.customFn, modelFunctionsContext); - EXPECT_EQ(s_mixer_first_run_done, true); + EXPECT_EQ((bool)(mainRequestFlags & (1 << REQUEST_FLIGHT_RESET)), false); // now trigger SA0 simuSetSwitch(0, -1); // flightReset() should be called evalFunctions(g_model.customFn, modelFunctionsContext); - EXPECT_EQ(s_mixer_first_run_done, false); + EXPECT_EQ((bool)(mainRequestFlags & (1 << REQUEST_FLIGHT_RESET)), true); - // now set s_mixer_first_run_done to true, and it should stay true (flightReset() should not be called again) - s_mixer_first_run_done = true; + // now reset mainRequestFlags, and it should stay reset (flightReset() should not be called again) + mainRequestFlags = 0; evalFunctions(g_model.customFn, modelFunctionsContext); - EXPECT_EQ(s_mixer_first_run_done, true) << "Flight Reset repeats!"; - + EXPECT_EQ((bool)(mainRequestFlags & (1 << REQUEST_FLIGHT_RESET)), false); } #if defined(GVARS)