From 9ed21afd593f5b89a26e80852f33fe61ac81cb44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Tue, 11 Apr 2017 16:07:54 +0200 Subject: [PATCH] vmount: simplify initialization --- src/drivers/vmount/vmount.cpp | 46 +++++++++-------------------------- 1 file changed, 12 insertions(+), 34 deletions(-) diff --git a/src/drivers/vmount/vmount.cpp b/src/drivers/vmount/vmount.cpp index 3af560444f..8dc19caa6b 100644 --- a/src/drivers/vmount/vmount.cpp +++ b/src/drivers/vmount/vmount.cpp @@ -220,55 +220,27 @@ static int vmount_thread_main(int argc, char *argv[]) case 0: // Automatic - if (!thread_data.input_objs[0]) { - thread_data.input_objs[0] = new InputMavlinkCmdMount(); - - if (!thread_data.input_objs[0]) { alloc_failed = true; } - } - - if (!thread_data.input_objs[1]) { - thread_data.input_objs[1] = new InputMavlinkROI(); - - if (!thread_data.input_objs[1]) { alloc_failed = true; } - } + thread_data.input_objs[0] = new InputMavlinkCmdMount(); + thread_data.input_objs[1] = new InputMavlinkROI(); // RC is on purpose last here so that if there are any mavlink // messages, they will take precedence over RC. // This logic is done further below while update() is called. - if (!thread_data.input_objs[2]) { - thread_data.input_objs[2] = new InputRC(params.mnt_man_roll, params.mnt_man_pitch, params.mnt_man_yaw); - - if (!thread_data.input_objs[2]) { alloc_failed = true; } - } + thread_data.input_objs[2] = new InputRC(params.mnt_man_roll, params.mnt_man_pitch, params.mnt_man_yaw); thread_data.input_objs_len = 3; break; case 1: //RC - if (!thread_data.input_objs[0]) { - thread_data.input_objs[0] = new InputRC(params.mnt_man_roll, params.mnt_man_pitch, params.mnt_man_yaw); - - if (!thread_data.input_objs[0]) { alloc_failed = true; } - } - + thread_data.input_objs[0] = new InputRC(params.mnt_man_roll, params.mnt_man_pitch, params.mnt_man_yaw); break; case 2: //MAVLINK_ROI - if (!thread_data.input_objs[0]) { - thread_data.input_objs[0] = new InputMavlinkROI(); - - if (!thread_data.input_objs[0]) { alloc_failed = true; } - } - + thread_data.input_objs[0] = new InputMavlinkROI(); break; case 3: //MAVLINK_DO_MOUNT - if (!thread_data.input_objs[0]) { - thread_data.input_objs[0] = new InputMavlinkCmdMount(); - - if (!thread_data.input_objs[0]) { alloc_failed = true; } - } - + thread_data.input_objs[0] = new InputMavlinkCmdMount(); break; default: @@ -277,6 +249,12 @@ static int vmount_thread_main(int argc, char *argv[]) } } + for (int i = 0; i < thread_data.input_objs_len; ++i) { + if (!thread_data.input_objs[i]) { + alloc_failed = true; + } + } + switch (params.mnt_mode_out) { case 0: //AUX thread_data.output_obj = new OutputRC(output_config);