From 4e427f69dba7bd84507cb55e6ddb567fbeb74039 Mon Sep 17 00:00:00 2001 From: Vladimir Zidar Date: Tue, 6 Sep 2016 11:54:06 +0200 Subject: [PATCH] LP-401 Add sanity check for FlightModeSettings to bring up reboot-required alarm if flightmode has autotune, but no autotune modules started. --- flight/modules/AutoTune/autotune.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/flight/modules/AutoTune/autotune.c b/flight/modules/AutoTune/autotune.c index df93d4a81..d3f7d0760 100644 --- a/flight/modules/AutoTune/autotune.c +++ b/flight/modules/AutoTune/autotune.c @@ -159,6 +159,19 @@ static void UpdateSystemIdentState(const float *X, const float *noise, float dT_ static void UpdateStabilizationDesired(bool doingIdent); +static void flightModeSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev) +{ + FlightModeSettingsFlightModePositionOptions fms[FLIGHTMODESETTINGS_FLIGHTMODEPOSITION_NUMELEM]; + + FlightModeSettingsFlightModePositionGet(fms); + for (uint8_t i = 0; i < FLIGHTMODESETTINGS_FLIGHTMODEPOSITION_NUMELEM; ++i) { + if (fms[i] == FLIGHTMODESETTINGS_FLIGHTMODEPOSITION_AUTOTUNE) { + ExtendedAlarmsSet(SYSTEMALARMS_ALARM_BOOTFAULT, SYSTEMALARMS_ALARM_CRITICAL, SYSTEMALARMS_EXTENDEDALARMSTATUS_REBOOTREQUIRED, 0); + break; + } + } +} + /** * Initialise the module, called on startup * \returns 0 on success or -1 if initialisation failed @@ -202,6 +215,10 @@ int32_t AutoTuneInitialize(void) } } + if (!moduleEnabled) { + FlightModeSettingsConnectCallback(flightModeSettingsUpdatedCb); + } + return 0; }