From a20a08c63052aa2098649acb06e61585a0c2f488 Mon Sep 17 00:00:00 2001 From: formtapez Date: Sat, 21 Jan 2023 11:36:06 +0100 Subject: [PATCH] save/recall all receiver settings --- firmware/application/app_settings.cpp | 11 +++++++++++ firmware/application/app_settings.hpp | 4 ++++ firmware/application/apps/analog_audio_app.cpp | 12 +++++++++++- firmware/application/receiver_model.cpp | 9 +++++++++ firmware/application/receiver_model.hpp | 2 ++ 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/firmware/application/app_settings.cpp b/firmware/application/app_settings.cpp index 72734a4d..638e8828 100644 --- a/firmware/application/app_settings.cpp +++ b/firmware/application/app_settings.cpp @@ -52,6 +52,12 @@ int app_settings::load(std::string application, AppSettings* settings) { settings->tx_frequency=std::app_settings::read_long_long(file_content, "tx_frequency="); settings->tx_gain=std::app_settings::read_long_long(file_content, "tx_gain="); settings->step=std::app_settings::read_long_long(file_content, "step="); + settings->modulation=std::app_settings::read_long_long(file_content, "modulation="); + settings->am_config_index=std::app_settings::read_long_long(file_content, "am_config_index="); + settings->nbfm_config_index=std::app_settings::read_long_long(file_content, "nbfm_config_index="); + settings->wfm_config_index=std::app_settings::read_long_long(file_content, "wfm_config_index="); + settings->squelch=std::app_settings::read_long_long(file_content, "squelch="); + rc = SETTINGS_OK; } else rc = SETTINGS_UNABLE_TO_LOAD; @@ -81,6 +87,11 @@ int app_settings::save(std::string application, AppSettings* settings) { settings_file.write_line("rx_frequency="+to_string_dec_uint(settings->rx_frequency)); settings_file.write_line("tx_frequency="+to_string_dec_uint(settings->tx_frequency)); settings_file.write_line("step="+to_string_dec_uint(settings->step)); + settings_file.write_line("modulation="+to_string_dec_uint(settings->modulation)); + settings_file.write_line("am_config_index="+to_string_dec_uint(settings->am_config_index)); + settings_file.write_line("nbfm_config_index="+to_string_dec_uint(settings->nbfm_config_index)); + settings_file.write_line("wfm_config_index="+to_string_dec_uint(settings->wfm_config_index)); + settings_file.write_line("squelch="+to_string_dec_uint(settings->squelch)); rc = SETTINGS_OK; } diff --git a/firmware/application/app_settings.hpp b/firmware/application/app_settings.hpp index 004f0673..8f6835ef 100644 --- a/firmware/application/app_settings.hpp +++ b/firmware/application/app_settings.hpp @@ -60,6 +60,10 @@ public: uint8_t tx_gain; uint8_t vga; uint32_t step; + uint8_t am_config_index; + uint8_t nbfm_config_index; + uint8_t wfm_config_index; + uint8_t squelch; }; int load(std::string application, AppSettings* settings); diff --git a/firmware/application/apps/analog_audio_app.cpp b/firmware/application/apps/analog_audio_app.cpp index 422633da..52ba96a3 100644 --- a/firmware/application/apps/analog_audio_app.cpp +++ b/firmware/application/apps/analog_audio_app.cpp @@ -136,6 +136,7 @@ AnalogAudioView::AnalogAudioView( field_vga.set_value(app_settings.vga); receiver_model.set_rf_amp(app_settings.rx_amp); field_frequency.set_value(app_settings.rx_frequency); + receiver_model.set_configuration_without_init(static_cast(app_settings.modulation), app_settings.step, app_settings.am_config_index, app_settings.nbfm_config_index, app_settings.wfm_config_index, app_settings.squelch); } else field_frequency.set_value(receiver_model.tuning_frequency()); @@ -193,7 +194,7 @@ AnalogAudioView::AnalogAudioView( audio::output::start(); update_modulation(static_cast(modulation)); - on_modulation_changed(static_cast(modulation)); + on_modulation_changed(static_cast(modulation)); } size_t AnalogAudioView::get_spec_bw_index() { @@ -223,6 +224,15 @@ AnalogAudioView::~AnalogAudioView() { // save app settings app_settings.rx_frequency = field_frequency.value(); + app_settings.lna = receiver_model.lna(); + app_settings.vga = receiver_model.vga(); + app_settings.rx_amp = receiver_model.rf_amp(); + app_settings.step = receiver_model.frequency_step(); + app_settings.modulation = (uint8_t)receiver_model.modulation(); + app_settings.am_config_index = receiver_model.am_configuration(); + app_settings.nbfm_config_index = receiver_model.nbfm_configuration(); + app_settings.wfm_config_index = receiver_model.wfm_configuration(); + app_settings.squelch = receiver_model.squelch_level(); settings.save("rx_audio", &app_settings); // TODO: Manipulating audio codec here, and in ui_receiver.cpp. Good to do diff --git a/firmware/application/receiver_model.cpp b/firmware/application/receiver_model.cpp index c62d56d2..c5c7f5ee 100644 --- a/firmware/application/receiver_model.cpp +++ b/firmware/application/receiver_model.cpp @@ -313,3 +313,12 @@ size_t ReceiverModel::wfm_configuration() const { void ReceiverModel::update_wfm_configuration() { wfm_configs[wfm_config_index].apply(); } + +void ReceiverModel::set_configuration_without_init(const Mode new_mode, const rf::Frequency new_frequency_step, const size_t new_am_config_index, const size_t new_nbfm_config_index, const size_t new_wfm_config_index, uint8_t new_squelch_level) { + mode_ = new_mode; + frequency_step_ = new_frequency_step; + am_config_index = new_am_config_index; + nbfm_config_index = new_nbfm_config_index; + wfm_config_index = new_wfm_config_index; + squelch_level_ = new_squelch_level; +} diff --git a/firmware/application/receiver_model.hpp b/firmware/application/receiver_model.hpp index 5b2a82f3..ce960ace 100644 --- a/firmware/application/receiver_model.hpp +++ b/firmware/application/receiver_model.hpp @@ -87,6 +87,8 @@ public: size_t wfm_configuration() const; void set_wfm_configuration(const size_t n); + void set_configuration_without_init(const Mode new_mode, const rf::Frequency new_frequency_step, const size_t new_am_config_index, const size_t new_nbfm_config_index, const size_t new_wfm_config_index, uint8_t new_squelch_level); + private: rf::Frequency frequency_step_ { 25000 }; bool enabled_ { false };