fix audio/mod/settings and cleaned unneeded parts

This commit is contained in:
gullradriel 2025-04-03 22:36:00 +02:00
parent 0cd534ade0
commit c43bfed0af
2 changed files with 44 additions and 151 deletions

View File

@ -22,40 +22,52 @@ namespace ui::external_app::gfxeq {
gfxEQView::gfxEQView(NavigationView& nav)
: nav_{nav}, bar_heights(NUM_BARS, 0), prev_bar_heights(NUM_BARS, 0) {
baseband::run_image(spi_flash::image_tag_wfm_audio);
add_children({&button_frequency, &field_rf_amp, &field_lna, &field_vga,
&button_mood, &field_volume});
add_children({&field_frequency, &field_rf_amp, &field_lna, &field_vga,
&button_mood, &field_volume, &text_ctcss});
audio::output::stop();
receiver_model.disable();
baseband::shutdown();
field_frequency.set_step(25000);
field_frequency.set_value(frequency_value);
field_rf_amp.set_value(rf_amp_value);
field_lna.set_value(lna_gain_value);
field_vga.set_value(vga_gain_value);
field_volume.set_value(volume_value);
baseband::run_image(portapack::spi_flash::image_tag_wfm_audio);
receiver_model.set_rf_amp(rf_amp_value);
receiver_model.set_lna(lna_gain_value);
receiver_model.set_vga(vga_gain_value);
receiver_model.set_modulation(ReceiverModel::Mode::WidebandFMAudio);
receiver_model.set_wfm_configuration(1); // 200k => 0 , 180k => 1 , 40k => 2. Set to 1 or 2 for better reception
receiver_model.set_sampling_rate(3072000);
receiver_model.set_target_frequency(frequency_value);
receiver_model.set_baseband_bandwidth(1750000);
audio::set_rate(audio::Rate::Hz_48000);
audio::output::start();
receiver_model.set_headphone_volume(receiver_model.headphone_volume()); // WM8731 hack
//
receiver_model.enable();
audio::output::start();
receiver_model.set_target_frequency(frequency_value); // Retune to actual freq
button_frequency.set_text("<" + to_string_short_freq(frequency_value) + ">");
field_rf_amp.on_change = [this](bool v) {
rf_amp_value = v;
receiver_model.set_rf_amp(v);
button_frequency.on_select = [this, &nav](ButtonWithEncoder& button) {
auto new_view = nav_.push<FrequencyKeypadView>(frequency_value);
new_view->on_changed = [this, &button](rf::Frequency f) {
frequency_value = f;
receiver_model.set_target_frequency(f); // Retune to actual freq
button_frequency.set_text("<" + to_string_short_freq(frequency_value) + ">");
};
};
field_lna.on_change = [this](int32_t v) {
lna_gain_value = v;
receiver_model.set_lna(v);
};
field_vga.on_change = [this](int32_t v) {
vga_gain_value = v;
receiver_model.set_vga(v);
button_frequency.on_change = [this]() {
int64_t def_step = 25000;
frequency_value = frequency_value + (button_frequency.get_encoder_delta() * def_step);
if (frequency_value < 1) {
frequency_value = 1;
}
if (frequency_value > (MAX_UFREQ - def_step)) {
frequency_value = MAX_UFREQ;
}
button_frequency.set_encoder_delta(0);
receiver_model.set_target_frequency(frequency_value); // Retune to actual freq
button_frequency.set_text("<" + to_string_short_freq(frequency_value) + ">");
};
button_mood.on_select = [this](Button&) { this->cycle_theme(); };
}
@ -66,30 +78,17 @@ gfxEQView::~gfxEQView() {
}
void gfxEQView::focus() {
field_frequency.focus();
button_frequency.focus();
}
void gfxEQView::on_show() {
needs_background_redraw = true;
set_dirty();
}
void gfxEQView::on_hide() {
needs_background_redraw = true;
}
void gfxEQView::start() {
if (!running) {
running = true;
}
}
void gfxEQView::stop() {
if (running) {
running = false;
}
}
void gfxEQView::update_audio_spectrum(const AudioSpectrum& spectrum) {
const int bins_per_bar = 128 / NUM_BARS;
for (int bar = 0; bar < NUM_BARS; bar++) {
@ -133,91 +132,15 @@ void gfxEQView::render_equalizer(Painter& painter) {
}
void gfxEQView::paint(Painter& painter) {
if (!initialized) {
initialized = true;
start();
painter.fill_rectangle({0, header_height, SCREEN_WIDTH, RENDER_HEIGHT}, Color(0, 0, 0));
} else if (needs_background_redraw) {
if (needs_background_redraw) {
painter.fill_rectangle({0, header_height, SCREEN_WIDTH, RENDER_HEIGHT}, Color(0, 0, 0));
needs_background_redraw = false;
}
render_equalizer(painter);
}
void gfxEQView::on_frequency_step_changed(rf::Frequency f) {
receiver_model.set_frequency_step(f);
field_frequency.set_step(f);
}
void gfxEQView::on_reference_ppm_correction_changed(int32_t v) {
persistent_memory::set_correction_ppb(v * 1000);
}
void gfxEQView::remove_options_widget() {
if (options_widget) {
remove_child(options_widget.get());
options_widget.reset();
}
field_rf_amp.set_style(nullptr);
field_lna.set_style(nullptr);
field_vga.set_style(nullptr);
field_frequency.set_style(nullptr);
}
void gfxEQView::set_options_widget(std::unique_ptr<Widget> new_widget) {
remove_options_widget();
if (new_widget) {
options_widget = std::move(new_widget);
} else {
options_widget = std::make_unique<Rectangle>(options_view_rect, Theme::getInstance()->option_active->background);
}
add_child(options_widget.get());
}
void gfxEQView::update_modulation(ReceiverModel::Mode modulation) {
audio::output::mute();
baseband::shutdown();
spi_flash::image_tag_t image_tag;
switch (modulation) {
case ReceiverModel::Mode::AMAudio:
image_tag = spi_flash::image_tag_am_audio;
break;
case ReceiverModel::Mode::NarrowbandFMAudio:
image_tag = spi_flash::image_tag_nfm_audio;
break;
case ReceiverModel::Mode::WidebandFMAudio:
image_tag = spi_flash::image_tag_wfm_audio;
break;
case ReceiverModel::Mode::SpectrumAnalysis:
image_tag = spi_flash::image_tag_wideband_spectrum;
break;
default:
image_tag = spi_flash::image_tag_wfm_audio;
break;
}
baseband::run_image(image_tag);
if (modulation == ReceiverModel::Mode::SpectrumAnalysis) {
baseband::set_spectrum(receiver_model.sampling_rate(), 40);
}
receiver_model.set_modulation(modulation);
receiver_model.set_sampling_rate(3072000);
receiver_model.enable();
if (modulation != ReceiverModel::Mode::SpectrumAnalysis) {
audio::output::unmute();
}
}
void gfxEQView::handle_coded_squelch(uint32_t value) {
text_ctcss.set(tonekey::tone_key_string_by_value(value, text_ctcss.parent_rect().width() / 8));
}
void gfxEQView::cycle_theme() {
current_theme = (current_theme + 1) % themes.size();
set_dirty();
}
} // namespace ui::external_app::gfxeq
} // namespace ui::external_app::gfxeq

View File

@ -53,11 +53,9 @@ class gfxEQView : public View {
};
NavigationView& nav_;
bool initialized{false};
bool needs_background_redraw{false};
std::vector<int> bar_heights;
std::vector<int> prev_bar_heights;
bool running{false};
uint32_t current_theme{0};
const std::array<ColorTheme, 20> themes{
ColorTheme{Color(255, 0, 255), Color(255, 255, 255)},
@ -81,49 +79,27 @@ class gfxEQView : public View {
ColorTheme{Color(64, 64, 64), Color(255, 0, 0)},
ColorTheme{Color(255, 192, 0), Color(0, 64, 128)}};
RxFrequencyField field_frequency{{0 * 8, 0 * 16}, nav_};
ButtonWithEncoder button_frequency{{0 * 8, 0 * 16 + 4, 11 * 8, 1 * 8}, ""};
RFAmpField field_rf_amp{{13 * 8, 0 * 16}};
LNAGainField field_lna{{15 * 8, 0 * 16}};
VGAGainField field_vga{{18 * 8, 0 * 16}};
Button button_mood{{21 * 8, 0, 6 * 8, 16}, "MOOD"};
AudioVolumeField field_volume{{28 * 8, 0 * 16}};
Text text_ctcss{{16 * 8, 1 * 16, 14 * 8, 1 * 16}, ""};
const Rect options_view_rect{0 * 8, 1 * 16, 30 * 8, 1 * 16};
std::unique_ptr<Widget> options_widget{};
rf::Frequency frequency_value{93100000};
RxRadioState rx_radio_state_{};
bool rf_amp_value{false};
int32_t lna_gain_value{0};
int32_t vga_gain_value{0};
rf::Frequency frequency_value{93100000};
int32_t volume_value{50};
app_settings::SettingsManager settings_{
"rx_gfx_eq",
app_settings::Mode::RX,
{{"theme", &current_theme},
{"rf_amp", &rf_amp_value},
{"lna_gain", &lna_gain_value},
{"vga_gain", &vga_gain_value},
{"frequency", &frequency_value},
{"volume", &volume_value}}};
{"frequency", &frequency_value}}};
void start();
void stop();
void update_audio_spectrum(const AudioSpectrum& spectrum);
void render_equalizer(Painter& painter);
void on_frequency_step_changed(rf::Frequency f);
void on_reference_ppm_correction_changed(int32_t v);
void remove_options_widget();
void set_options_widget(std::unique_ptr<Widget> new_widget);
void update_modulation(ReceiverModel::Mode modulation);
void handle_coded_squelch(uint32_t value);
void cycle_theme();
MessageHandlerRegistration message_handler_frame_sync{
Message::ID::DisplayFrameSync,
[this](const Message* const) {}};
MessageHandlerRegistration message_handler_audio_spectrum{
Message::ID::AudioSpectrum,
[this](const Message* const p) {
@ -131,14 +107,8 @@ class gfxEQView : public View {
this->update_audio_spectrum(*message.data);
this->set_dirty();
}};
MessageHandlerRegistration message_handler_coded_squelch{
Message::ID::CodedSquelch,
[this](const Message* const p) {
const auto message = *reinterpret_cast<const CodedSquelchMessage*>(p);
this->handle_coded_squelch(message.value);
}};
};
} // namespace ui::external_app::gfxeq
#endif
#endif