From bd781ce37b7dcaadb761fd687fc2e775fb6fc9a2 Mon Sep 17 00:00:00 2001 From: Richard Date: Fri, 2 May 2025 05:19:41 +0100 Subject: [PATCH] Fix for #2538 (#2635) * Fix for #2538 Fix for #2538 Added on_bandwidth_changed Callback to ui_transmitter.hpp Modified the field_bw.on_change lambda in the TransmitterView constructor to trigger the on_bandwidth_changed callback Connected the Callback in ui_siggen.cpp I am not a C++ programmer so this change was proposed by Gemini AI. I have built and tested the App and it works as expected and I don't think the change will have any unexpected side effects. * Fix clang issues Fix clang issues * Update ui_transmitter.cpp typo * Revised change The proposed change mirrors the way a change to the frequency (on_edit_frequency) is triggered in ui_siggen by the tx_view. The bw parameter is not passed because it is stored in _setting in the tx_view and will be read by update_config. A change to the bw is not checked against auto_update to keep its behaviour consistent with a change to the gain, amplitude or frequency. * Make changes to the channel_bandwidth dynamic whist playing Behaviour of channel bandwidth is now consistent with frequency, amp and gain. * comment edit * revert hackrf submodule checkpoint to the repo * comment --------- Co-authored-by: zxkmm --- firmware/application/apps/soundboard_app.cpp | 29 ++++++++++++++++---- firmware/application/apps/soundboard_app.hpp | 3 ++ firmware/application/apps/ui_siggen.cpp | 9 +++++- firmware/application/ui/ui_transmitter.cpp | 5 +++- firmware/application/ui/ui_transmitter.hpp | 6 +++- 5 files changed, 44 insertions(+), 8 deletions(-) diff --git a/firmware/application/apps/soundboard_app.cpp b/firmware/application/apps/soundboard_app.cpp index 4f813f9c8..e8159a4a0 100644 --- a/firmware/application/apps/soundboard_app.cpp +++ b/firmware/application/apps/soundboard_app.cpp @@ -91,10 +91,6 @@ void SoundBoardView::start_tx(const uint32_t id) { auto reader = std::make_unique(); - uint32_t tone_key_index = options_tone_key.selected_index(); - uint32_t sample_rate; - uint8_t bits_per_sample; - stop(); if (!reader->open(u"/WAV/" + file_list[id].native())) { @@ -108,7 +104,9 @@ void SoundBoardView::start_tx(const uint32_t id) { // button_play.set_bitmap(&bitmap_stop); - sample_rate = reader->sample_rate(); + uint32_t sample_rate = reader->sample_rate(); + + tone_key_index = options_tone_key.selected_index(); bits_per_sample = reader->bits_per_sample(); replay_thread = std::make_unique( @@ -155,6 +153,23 @@ void SoundBoardView::on_tx_progress(const uint32_t progress) { progressbar.set_value(progress); } +void SoundBoardView::update_config() { + // NB: this were called by the on_bandwidth_changed() callback, + // so other val would be updated too when bw changed. currently it's safe but be careful. + baseband::set_audiotx_config( + 1536000 / 20, // Update vu-meter at 20Hz + transmitter_model.channel_bandwidth(), + 0, // Gain is unused + 8, // shift_bits_s16, default 8 bits, but also unused + bits_per_sample, + TONES_F2D(tone_key_frequency(tone_key_index), TONES_SAMPLERATE), + false, // AM + false, // DSB + false, // USB + false // LSB + ); +} + void SoundBoardView::on_select_entry() { tx_view.focus(); } @@ -289,6 +304,10 @@ SoundBoardView::SoundBoardView( }; }; + tx_view.on_bandwidth_changed = [this]() { + update_config(); + }; + tx_view.on_start = [this]() { start_tx(menu_view.highlighted_index()); }; diff --git a/firmware/application/apps/soundboard_app.hpp b/firmware/application/apps/soundboard_app.hpp index 04aeb5405..44479ed38 100644 --- a/firmware/application/apps/soundboard_app.hpp +++ b/firmware/application/apps/soundboard_app.hpp @@ -70,6 +70,8 @@ class SoundBoardView : public View { uint32_t playing_id{}; uint32_t page = 1; uint32_t c_page = 1; + uint32_t tone_key_index = 1; + uint8_t bits_per_sample = 1; std::vector file_list{}; @@ -90,6 +92,7 @@ class SoundBoardView : public View { void on_tx_progress(const uint32_t progress); void refresh_list(); void on_select_entry(); + void update_config(); Labels labels{ {{24 * 8, 180}, "Vol:", Theme::getInstance()->fg_light->foreground}, diff --git a/firmware/application/apps/ui_siggen.cpp b/firmware/application/apps/ui_siggen.cpp index 428ddc9cf..032dbd56c 100644 --- a/firmware/application/apps/ui_siggen.cpp +++ b/firmware/application/apps/ui_siggen.cpp @@ -154,6 +154,13 @@ SigGenView::SigGenView( }; }; + tx_view.on_bandwidth_changed = [this]() { + // we don't protect here with auto_update because other field of tx_view obj isn't protected too + // to remains the design logic same + + update_config(); + }; + tx_view.on_start = [this]() { start_tx(); tx_view.set_transmitting(true); @@ -165,4 +172,4 @@ SigGenView::SigGenView( }; } -} /* namespace ui */ +} /* namespace ui */ \ No newline at end of file diff --git a/firmware/application/ui/ui_transmitter.cpp b/firmware/application/ui/ui_transmitter.cpp index 6ec24e7fb..4029ea15f 100644 --- a/firmware/application/ui/ui_transmitter.cpp +++ b/firmware/application/ui/ui_transmitter.cpp @@ -155,6 +155,9 @@ TransmitterView::TransmitterView( field_bw.on_change = [this](int32_t v) { on_channel_bandwidth_changed(v * 1000); + if (on_bandwidth_changed) { + on_bandwidth_changed(); + } }; field_bw.set_value(channel_bandwidth); } @@ -257,4 +260,4 @@ void TransmitterView2::update_gainlevel_styles() { field_amp.set_style(style); } -} /* namespace ui */ +} /* namespace ui */ \ No newline at end of file diff --git a/firmware/application/ui/ui_transmitter.hpp b/firmware/application/ui/ui_transmitter.hpp index d9b922cfc..dd7f796fe 100644 --- a/firmware/application/ui/ui_transmitter.hpp +++ b/firmware/application/ui/ui_transmitter.hpp @@ -50,6 +50,10 @@ class TransmitterView : public View { std::function on_edit_frequency{}; std::function on_start{}; std::function on_stop{}; + std::function on_bandwidth_changed{}; + // TODO: this is a workaround because in the message system, + // we change bw by different message for different m4 bb, so have to callback + // and change in the instance(for instance SigGen app) with calling the instance's bb opration func TransmitterView(const Coord y, const uint64_t frequency_step, const uint32_t channel_bandwidth, const bool lock); TransmitterView( @@ -156,4 +160,4 @@ class TransmitterView2 : public View { } /* namespace ui */ -#endif /*__UI_TRANSMITTER_H__*/ +#endif /*__UI_TRANSMITTER_H__*/ \ No newline at end of file