From f2a7617b1b41bbcf9c1eee6d67edadf49d8229f1 Mon Sep 17 00:00:00 2001 From: Mark Thompson <129641948+NotherNgineer@users.noreply.github.com> Date: Tue, 6 Jun 2023 11:46:08 -0500 Subject: [PATCH] WFM bandwidth widget dial direction (clockwise==increasing) & OptionsField widget change (circular list) (#1109) * Put WFM bandwidth options in ascending order * Put WFM bandwidth options in ascending order * Put WFM bandwidth options in ascending order * Put WFM bandwidth options in ascending order * Put WFM bandwidth options in ascending order * Clang formatting attempt * OptionsField wrapping - for your consideration Perhaps if OptionsWidget supported wrapping, then it would be easier to dial through all available options without having to know which direction to turn the dial. --- firmware/application/apps/analog_audio_app.cpp | 12 ++++++------ firmware/application/apps/ui_level.cpp | 18 +++++++++--------- firmware/application/apps/ui_recon.cpp | 18 +++++++++--------- firmware/application/apps/ui_scanner.cpp | 18 +++++++++--------- firmware/application/freqman.cpp | 4 ++-- firmware/common/ui_widget.cpp | 8 +++++++- 6 files changed, 42 insertions(+), 36 deletions(-) diff --git a/firmware/application/apps/analog_audio_app.cpp b/firmware/application/apps/analog_audio_app.cpp index b8ebdc48..96d5dec0 100644 --- a/firmware/application/apps/analog_audio_app.cpp +++ b/firmware/application/apps/analog_audio_app.cpp @@ -54,8 +54,8 @@ AMOptionsView::AMOptionsView( }); freqman_set_bandwidth_option(AM_MODULATION, options_config); // adding the common message from freqman.cpp to the options_config - options_config.set_selected_index(receiver_model.am_configuration()); - options_config.on_change = [this](size_t n, OptionsField::value_t) { + options_config.set_by_value(receiver_model.am_configuration()); + options_config.on_change = [this](size_t, OptionsField::value_t n) { receiver_model.set_am_configuration(n); }; } @@ -74,8 +74,8 @@ NBFMOptionsView::NBFMOptionsView( &field_squelch}); freqman_set_bandwidth_option(NFM_MODULATION, options_config); // adding the common message from freqman.cpp to the options_config - options_config.set_selected_index(receiver_model.nbfm_configuration()); - options_config.on_change = [this](size_t n, OptionsField::value_t) { + options_config.set_by_value(receiver_model.nbfm_configuration()); + options_config.on_change = [this](size_t, OptionsField::value_t n) { receiver_model.set_nbfm_configuration(n); }; @@ -99,8 +99,8 @@ WFMOptionsView::WFMOptionsView( }); freqman_set_bandwidth_option(WFM_MODULATION, options_config); // adding the common message from freqman.cpp to the options_config - options_config.set_selected_index(receiver_model.wfm_configuration()); - options_config.on_change = [this](size_t n, OptionsField::value_t) { + options_config.set_by_value(receiver_model.wfm_configuration()); + options_config.on_change = [this](size_t, OptionsField::value_t n) { receiver_model.set_wfm_configuration(n); }; } diff --git a/firmware/application/apps/ui_level.cpp b/firmware/application/apps/ui_level.cpp index eba94a95..d009854c 100644 --- a/firmware/application/apps/ui_level.cpp +++ b/firmware/application/apps/ui_level.cpp @@ -191,11 +191,11 @@ size_t LevelView::change_mode(freqman_index_t new_mod) { case AM_MODULATION: freqman_set_bandwidth_option(new_mod, field_bw); // bw DSB (0) default - field_bw.set_selected_index(0); + field_bw.set_by_value(0); baseband::run_image(portapack::spi_flash::image_tag_am_audio); receiver_model.set_modulation(ReceiverModel::Mode::AMAudio); - receiver_model.set_am_configuration(field_bw.selected_index()); - field_bw.on_change = [this](size_t n, OptionsField::value_t) { receiver_model.set_am_configuration(n); }; + receiver_model.set_am_configuration(field_bw.selected_index_value()); + field_bw.on_change = [this](size_t, OptionsField::value_t n) { receiver_model.set_am_configuration(n); }; receiver_model.set_sampling_rate(3072000); receiver_model.set_baseband_bandwidth(1750000); text_ctcss.set(" "); @@ -203,22 +203,22 @@ size_t LevelView::change_mode(freqman_index_t new_mod) { case NFM_MODULATION: freqman_set_bandwidth_option(new_mod, field_bw); // bw 16k (2) default - field_bw.set_selected_index(2); + field_bw.set_by_value(2); baseband::run_image(portapack::spi_flash::image_tag_nfm_audio); receiver_model.set_modulation(ReceiverModel::Mode::NarrowbandFMAudio); - receiver_model.set_nbfm_configuration(field_bw.selected_index()); - field_bw.on_change = [this](size_t n, OptionsField::value_t) { receiver_model.set_nbfm_configuration(n); }; + receiver_model.set_nbfm_configuration(field_bw.selected_index_value()); + field_bw.on_change = [this](size_t, OptionsField::value_t n) { receiver_model.set_nbfm_configuration(n); }; receiver_model.set_sampling_rate(3072000); receiver_model.set_baseband_bandwidth(1750000); break; case WFM_MODULATION: freqman_set_bandwidth_option(new_mod, field_bw); // bw 200k (0) only/default - field_bw.set_selected_index(0); + field_bw.set_by_value(0); baseband::run_image(portapack::spi_flash::image_tag_wfm_audio); receiver_model.set_modulation(ReceiverModel::Mode::WidebandFMAudio); - receiver_model.set_wfm_configuration(field_bw.selected_index()); - field_bw.on_change = [this](size_t n, OptionsField::value_t) { receiver_model.set_wfm_configuration(n); }; + receiver_model.set_wfm_configuration(field_bw.selected_index_value()); + field_bw.on_change = [this](size_t, OptionsField::value_t n) { receiver_model.set_wfm_configuration(n); }; receiver_model.set_sampling_rate(3072000); receiver_model.set_baseband_bandwidth(1750000); text_ctcss.set(" "); diff --git a/firmware/application/apps/ui_recon.cpp b/firmware/application/apps/ui_recon.cpp index d450e5d4..8a531514 100644 --- a/firmware/application/apps/ui_recon.cpp +++ b/firmware/application/apps/ui_recon.cpp @@ -1298,11 +1298,11 @@ size_t ReconView::change_mode(freqman_index_t new_mod) { case AM_MODULATION: freqman_set_bandwidth_option(new_mod, field_bw); // bw DSB (0) default - field_bw.set_selected_index(0); + field_bw.set_by_value(0); baseband::run_image(portapack::spi_flash::image_tag_am_audio); receiver_model.set_modulation(ReceiverModel::Mode::AMAudio); - receiver_model.set_am_configuration(field_bw.selected_index()); - field_bw.on_change = [this](size_t n, OptionsField::value_t) { receiver_model.set_am_configuration(n); }; + receiver_model.set_am_configuration(field_bw.selected_index_value()); + field_bw.on_change = [this](size_t, OptionsField::value_t n) { receiver_model.set_am_configuration(n); }; receiver_model.set_sampling_rate(3072000); receiver_model.set_baseband_bandwidth(1750000); text_ctcss.set(" "); @@ -1310,22 +1310,22 @@ size_t ReconView::change_mode(freqman_index_t new_mod) { case NFM_MODULATION: freqman_set_bandwidth_option(new_mod, field_bw); // bw 16k (2) default - field_bw.set_selected_index(2); + field_bw.set_by_value(2); baseband::run_image(portapack::spi_flash::image_tag_nfm_audio); receiver_model.set_modulation(ReceiverModel::Mode::NarrowbandFMAudio); - receiver_model.set_nbfm_configuration(field_bw.selected_index()); - field_bw.on_change = [this](size_t n, OptionsField::value_t) { receiver_model.set_nbfm_configuration(n); }; + receiver_model.set_nbfm_configuration(field_bw.selected_index_value()); + field_bw.on_change = [this](size_t, OptionsField::value_t n) { receiver_model.set_nbfm_configuration(n); }; receiver_model.set_sampling_rate(3072000); receiver_model.set_baseband_bandwidth(1750000); break; case WFM_MODULATION: freqman_set_bandwidth_option(new_mod, field_bw); // bw 200k (0) default - field_bw.set_selected_index(0); + field_bw.set_by_value(0); baseband::run_image(portapack::spi_flash::image_tag_wfm_audio); receiver_model.set_modulation(ReceiverModel::Mode::WidebandFMAudio); - receiver_model.set_wfm_configuration(field_bw.selected_index()); - field_bw.on_change = [this](size_t n, OptionsField::value_t) { receiver_model.set_wfm_configuration(n); }; + receiver_model.set_wfm_configuration(field_bw.selected_index_value()); + field_bw.on_change = [this](size_t, OptionsField::value_t n) { receiver_model.set_wfm_configuration(n); }; receiver_model.set_sampling_rate(3072000); receiver_model.set_baseband_bandwidth(1750000); text_ctcss.set(" "); diff --git a/firmware/application/apps/ui_scanner.cpp b/firmware/application/apps/ui_scanner.cpp index de0b6c40..8c291c5e 100644 --- a/firmware/application/apps/ui_scanner.cpp +++ b/firmware/application/apps/ui_scanner.cpp @@ -759,9 +759,9 @@ void ScannerView::change_mode(freqman_index_t new_mod) { // Before this, do a s freqman_set_bandwidth_option(new_mod, field_bw); baseband::run_image(portapack::spi_flash::image_tag_am_audio); receiver_model.set_modulation(ReceiverModel::Mode::AMAudio); - field_bw.set_selected_index(0); - receiver_model.set_am_configuration(field_bw.selected_index()); - field_bw.on_change = [this](size_t n, OptionsField::value_t) { receiver_model.set_am_configuration(n); }; + field_bw.set_by_value(0); + receiver_model.set_am_configuration(field_bw.selected_index_value()); + field_bw.on_change = [this](size_t, OptionsField::value_t n) { receiver_model.set_am_configuration(n); }; receiver_model.set_sampling_rate(3072000); receiver_model.set_baseband_bandwidth(1750000); break; @@ -769,9 +769,9 @@ void ScannerView::change_mode(freqman_index_t new_mod) { // Before this, do a s freqman_set_bandwidth_option(new_mod, field_bw); baseband::run_image(portapack::spi_flash::image_tag_nfm_audio); receiver_model.set_modulation(ReceiverModel::Mode::NarrowbandFMAudio); - field_bw.set_selected_index(2); - receiver_model.set_nbfm_configuration(field_bw.selected_index()); - field_bw.on_change = [this](size_t n, OptionsField::value_t) { receiver_model.set_nbfm_configuration(n); }; + field_bw.set_by_value(2); + receiver_model.set_nbfm_configuration(field_bw.selected_index_value()); + field_bw.on_change = [this](size_t, OptionsField::value_t n) { receiver_model.set_nbfm_configuration(n); }; receiver_model.set_sampling_rate(3072000); receiver_model.set_baseband_bandwidth(1750000); break; @@ -779,9 +779,9 @@ void ScannerView::change_mode(freqman_index_t new_mod) { // Before this, do a s freqman_set_bandwidth_option(new_mod, field_bw); baseband::run_image(portapack::spi_flash::image_tag_wfm_audio); receiver_model.set_modulation(ReceiverModel::Mode::WidebandFMAudio); - field_bw.set_selected_index(0); - receiver_model.set_wfm_configuration(field_bw.selected_index()); - field_bw.on_change = [this](size_t n, OptionsField::value_t) { receiver_model.set_wfm_configuration(n); }; + field_bw.set_by_value(0); + receiver_model.set_wfm_configuration(field_bw.selected_index_value()); + field_bw.on_change = [this](size_t, OptionsField::value_t n) { receiver_model.set_wfm_configuration(n); }; receiver_model.set_sampling_rate(3072000); receiver_model.set_baseband_bandwidth(2000000); break; diff --git a/firmware/application/freqman.cpp b/firmware/application/freqman.cpp index 0c75a27f..99307470 100644 --- a/firmware/application/freqman.cpp +++ b/firmware/application/freqman.cpp @@ -45,9 +45,9 @@ options_t freqman_entry_bandwidths[4] = { {"16k", 2}}, { // WFM - {"200k", 0}, - {"180k", 1}, {"40k", 2}, + {"180k", 1}, + {"200k", 0}, }}; options_t freqman_entry_steps = { diff --git a/firmware/common/ui_widget.cpp b/firmware/common/ui_widget.cpp index b707daa9..8db0e4f8 100644 --- a/firmware/common/ui_widget.cpp +++ b/firmware/common/ui_widget.cpp @@ -1477,7 +1477,13 @@ void OptionsField::on_focus() { } bool OptionsField::on_encoder(const EncoderEvent delta) { - set_selected_index(selected_index() + delta); + int32_t new_value = selected_index() + delta; + if (new_value < 0) + new_value = options.size() - 1; + else if ((size_t)new_value >= options.size()) + new_value = 0; + + set_selected_index(new_value); return true; }