From 495a8f28360ad190c1f293d01cef304f5bd8893f Mon Sep 17 00:00:00 2001 From: Oleg Semyonov Date: Sat, 24 Dec 2011 15:37:14 +0200 Subject: [PATCH] TxPID: initialize the AccessoryDesired object before use its handle Also save few bytes of static RAM and add PIOS_Assert(0) for unhandled cases. --- flight/Modules/TxPID/txpid.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/flight/Modules/TxPID/txpid.c b/flight/Modules/TxPID/txpid.c index 28898208d..b3e8377a2 100644 --- a/flight/Modules/TxPID/txpid.c +++ b/flight/Modules/TxPID/txpid.c @@ -87,8 +87,6 @@ static float scale(float val, float inMin, float inMax, float outMin, float outM */ int32_t TxPIDInitialize(void) { - static UAVObjEvent ev; - bool txPIDEnabled; uint8_t optionalModules[HWSETTINGS_OPTIONALMODULES_NUMELEM]; @@ -101,12 +99,16 @@ int32_t TxPIDInitialize(void) txPIDEnabled = false; if (txPIDEnabled) { - ev.obj = AccessoryDesiredHandle(); - ev.instId = 0; - ev.event = 0; - // Initialize settings object TxPIDSettingsInitialize(); + AccessoryDesiredInitialize(); + + UAVObjEvent ev = { + .obj = AccessoryDesiredHandle(), + .instId = 0, + .event = 0, + }; + EventPeriodicCallbackCreate(&ev, updatePIDs, SAMPLE_PERIOD_MS / portTICK_RATE_MS); #if (TELEMETRY_UPDATE_PERIOD_MS != 0) // Change StabilizationSettings update rate from OnChange to periodic @@ -116,6 +118,7 @@ int32_t TxPIDInitialize(void) // StabilizationSettings update rate permanently. Use Metadata via // browser to reset to defaults (telemetryAcked=true, OnChange). UAVObjMetadata metadata; + StabilizationSettingsInitialize(); StabilizationSettingsGetMetadata(&metadata); metadata.telemetryAcked = 0; metadata.telemetryUpdateMode = UPDATEMODE_PERIODIC; @@ -123,9 +126,6 @@ int32_t TxPIDInitialize(void) StabilizationSettingsSetMetadata(&metadata); #endif - // Setup the callback function - EventPeriodicCallbackCreate(&ev, updatePIDs, SAMPLE_PERIOD_MS / portTICK_RATE_MS); - return 0; } @@ -249,6 +249,8 @@ static void updatePIDs(UAVObjEvent* ev) case TXPIDSETTINGS_PIDS_YAWATTITUDEKI: needsUpdate |= update(&stab.YawPI[STABILIZATIONSETTINGS_YAWPI_KI], value); break; + default: + PIOS_Assert(0); } } }