From 3d59de55f85e98bd0fb06d3e576ab515bcb9f91d Mon Sep 17 00:00:00 2001 From: Kyle Reed <3761006+kallanreed@users.noreply.github.com> Date: Wed, 28 Jun 2023 10:14:30 -0700 Subject: [PATCH] Remove raw new/delete from Recon (#1203) --- firmware/application/apps/ui_recon.cpp | 34 +++++++++++++------------- firmware/application/apps/ui_recon.hpp | 2 ++ 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/firmware/application/apps/ui_recon.cpp b/firmware/application/apps/ui_recon.cpp index ccd1f70d..8d2eba13 100644 --- a/firmware/application/apps/ui_recon.cpp +++ b/firmware/application/apps/ui_recon.cpp @@ -30,8 +30,6 @@ using portapack::memory::map::backup_ram; namespace ui { -static RecordView* record_view = NULL; - void ReconView::set_loop_config(bool v) { continuous = v; button_loop_config.set_style(v ? &Styles::green : &Styles::white); @@ -365,7 +363,6 @@ void ReconView::focus() { ReconView::~ReconView() { recon_stop_recording(); - delete record_view; recon_save_config_to_sd(); if (field_mode.selected_index_value() != SPEC_MODULATION) audio::output::stop(); @@ -377,7 +374,9 @@ ReconView::~ReconView() { ReconView::ReconView(NavigationView& nav) : nav_{nav} { chrono_start = chTimeNow(); - record_view = new RecordView({0, 0, 30 * 8, 1 * 16}, u"AUTO_AUDIO_", u"AUDIO", RecordView::FileType::WAV, 4096, 4); + record_view = std::make_unique(Rect{0, 0, 30 * 8, 1 * 16}, + u"AUTO_AUDIO_", u"AUDIO", + RecordView::FileType::WAV, 4096, 4); add_children({&labels, &field_lna, &field_vga, @@ -414,7 +413,7 @@ ReconView::ReconView(NavigationView& nav) &button_restart, &button_mic_app, &button_remove, - record_view}); + record_view.get()}); record_view->hidden(true); record_view->set_filename_date_frequency(true); @@ -1339,25 +1338,26 @@ size_t ReconView::change_mode(freqman_index_t new_mod) { field_mode.on_change = [this](size_t, OptionsField::value_t) {}; field_bw.on_change = [this](size_t, OptionsField::value_t) {}; recon_stop_recording(); - if (new_mod != SPEC_MODULATION) { - remove_children({record_view}); - delete record_view; - record_view = new RecordView({0, 0, 30 * 8, 1 * 16}, u"AUTO_AUDIO_", u"AUDIO", RecordView::FileType::WAV, 4096, 4); - record_view->set_filename_date_frequency(true); - add_children({record_view}); - } + remove_child(record_view.get()); + if (new_mod == SPEC_MODULATION) { audio::output::stop(); - remove_children({record_view}); - delete record_view; - record_view = new RecordView({0, 0, 30 * 8, 1 * 16}, u"AUTO_RAW_", u"CAPTURES", RecordView::FileType::RawS16, 16384, 3); - record_view->set_filename_date_frequency(true); - add_children({record_view}); + record_view = std::make_unique(Rect{0, 0, 30 * 8, 1 * 16}, + u"AUTO_RAW_", u"CAPTURES", + RecordView::FileType::RawS16, 16384, 3); + } else { + record_view = std::make_unique(Rect{0, 0, 30 * 8, 1 * 16}, + u"AUTO_AUDIO_", u"AUDIO", + RecordView::FileType::WAV, 4096, 4); } + record_view->hidden(true); + record_view->set_filename_date_frequency(true); record_view->on_error = [this](std::string message) { nav_.display_modal("Error", message); }; + add_child(record_view.get()); + receiver_model.disable(); baseband::shutdown(); size_t recording_sampling_rate = 0; diff --git a/firmware/application/apps/ui_recon.hpp b/firmware/application/apps/ui_recon.hpp index f90fa2ca..7bc3d27c 100644 --- a/firmware/application/apps/ui_recon.hpp +++ b/firmware/application/apps/ui_recon.hpp @@ -145,6 +145,8 @@ class ReconView : public View { systime_t chrono_start{}; systime_t chrono_end{}; + std::unique_ptr record_view{}; + Labels labels{ {{0 * 8, 0 * 16}, "LNA: VGA: AMP: VOL: ", Color::light_grey()}, {{3 * 8, 8 * 16}, "START END", Color::light_grey()},