diff --git a/flight/Libraries/sanitycheck.c b/flight/Libraries/sanitycheck.c index b716259ff..87b1e8352 100644 --- a/flight/Libraries/sanitycheck.c +++ b/flight/Libraries/sanitycheck.c @@ -29,7 +29,6 @@ #include "openpilot.h" #include #include "sanitycheck.h" -#include "hwsettings.h" #include "taskinfo.h" #include "manualcontrolsettings.h" #include "systemalarms.h" diff --git a/flight/Modules/System/systemmod.c b/flight/Modules/System/systemmod.c index bd4382500..e85ce85c6 100644 --- a/flight/Modules/System/systemmod.c +++ b/flight/Modules/System/systemmod.c @@ -43,6 +43,7 @@ #include "sanitycheck.h" #include "objectpersistence.h" #include "flightstatus.h" +#include "manualcontrolsettings.h" #include "systemstats.h" #include "systemsettings.h" #include "i2cstats.h" @@ -88,6 +89,7 @@ static bool mallocFailed; // Private functions static void objectUpdatedCb(UAVObjEvent * ev); +static void configurationUpdatedCb(UAVObjEvent * ev); static void updateStats(); static void updateSystemAlarms(); static void systemTask(void *parameters); @@ -168,14 +170,19 @@ static void systemTask(void *parameters) // Listen for SettingPersistance object updates, connect a callback function ObjectPersistenceConnectQueue(objectPersistenceQueue); + // Whenever the configuration changes, make sure it is safe to fly + SystemSettingsConnectCallback(configurationUpdatedCb); + ManualControlSettingsConnectCallback(configurationUpdatedCb); + TaskInfoConnectCallback(configurationUpdatedCb); + + // Run this initially to make sure the configuration is checked + configuration_check(); + // Main system loop while (1) { // Update the system statistics updateStats(); - // TODO: Make this only be called when configuration settings change - configuration_check(); - // Update the system alarms updateSystemAlarms(); #if defined(I2C_WDG_STATS_DIAGNOSTICS) @@ -307,6 +314,14 @@ static void objectUpdatedCb(UAVObjEvent * ev) } } +/** + * Called whenever a critical configuration component changes + */ +static void configurationUpdatedCb(UAVObjEvent * ev) +{ + configuration_check(); +} + /** * Called periodically to update the I2C statistics */