Fix options bar layout and SettingsManager

This commit is contained in:
RocketGod 2025-04-03 09:25:10 -07:00
parent 934ef0fefc
commit 89da85dc2b
3 changed files with 72 additions and 104 deletions

View File

@ -1,3 +1,11 @@
/*
* ------------------------------------------------------------
* | Made by RocketGod |
* | Find me at https://betaskynet.com |
* | Argh matey! |
* ------------------------------------------------------------
*/
#include "ui_gfxeq.hpp"
#include "ui_navigation.hpp"
#include "external_app.hpp"

View File

@ -1,3 +1,11 @@
/*
* ------------------------------------------------------------
* | Made by RocketGod |
* | Find me at https://betaskynet.com |
* | Argh matey! |
* ------------------------------------------------------------
*/
#include "ui_gfxeq.hpp"
#include "ui.hpp"
#include "ui_freqman.hpp"
@ -14,33 +22,40 @@ namespace ui::external_app::gfxeq {
gfxEQView::gfxEQView(NavigationView& nav)
: nav_{nav}, bar_heights(NUM_BARS, 0), prev_bar_heights(NUM_BARS, 0) {
std::vector<BoundSetting> bindings;
bindings.push_back(BoundSetting{"current_theme"sv, &current_theme});
ui_settings = SettingsStore{"gfx_eq"sv, bindings};
baseband::run_image(spi_flash::image_tag_wfm_audio);
add_children({&field_frequency, &field_lna, &field_vga, &options_modulation,
&field_volume, &text_ctcss, &button_mood, &dummy});
add_children({&field_frequency, &field_rf_amp, &field_lna, &field_vga,
&button_mood, &field_volume, &text_ctcss});
field_lna.on_show_options = [this]() { this->on_show_options_rf_gain(); };
field_vga.on_show_options = [this]() { this->on_show_options_rf_gain(); };
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);
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_sampling_rate(3072000);
receiver_model.set_target_frequency(93100000);
receiver_model.set_target_frequency(frequency_value);
receiver_model.enable();
options_modulation.set_by_value(toUType(ReceiverModel::Mode::WidebandFMAudio));
options_modulation.on_change = [this](size_t, OptionsField::value_t v) {
this->on_modulation_changed(static_cast<ReceiverModel::Mode>(v));
};
options_modulation.on_show_options = [this]() { this->on_show_options_modulation(); };
field_frequency.set_value(93100000);
audio::output::start();
field_rf_amp.on_change = [this](bool v) {
rf_amp_value = v;
receiver_model.set_rf_amp(v);
};
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_mood.on_select = [this](Button&) { this->cycle_theme(); };
}
@ -117,46 +132,6 @@ void gfxEQView::paint(Painter& painter) {
render_equalizer(painter);
}
void gfxEQView::on_modulation_changed(ReceiverModel::Mode modulation) {
stop();
update_modulation(modulation);
on_show_options_modulation();
start();
}
void gfxEQView::on_show_options_rf_gain() {
auto widget = std::make_unique<RadioGainOptionsView>(options_view_rect, Theme::getInstance()->option_active);
set_options_widget(std::move(widget));
field_lna.set_style(Theme::getInstance()->option_active);
}
void gfxEQView::on_show_options_modulation() {
std::unique_ptr<Widget> widget;
const auto modulation = receiver_model.modulation();
switch (modulation) {
case ReceiverModel::Mode::AMAudio:
widget = std::make_unique<ui::AMOptionsView>(nullptr, options_view_rect, Theme::getInstance()->option_active);
text_ctcss.hidden(true);
break;
case ReceiverModel::Mode::NarrowbandFMAudio:
widget = std::make_unique<ui::NBFMOptionsView>(options_view_rect, Theme::getInstance()->option_active);
text_ctcss.hidden(false);
break;
case ReceiverModel::Mode::WidebandFMAudio:
widget = std::make_unique<ui::WFMOptionsView>(options_view_rect, Theme::getInstance()->option_active);
text_ctcss.hidden(true);
break;
case ReceiverModel::Mode::SpectrumAnalysis:
widget = std::make_unique<ui::SPECOptionsView>(nullptr, options_view_rect, Theme::getInstance()->option_active);
text_ctcss.hidden(true);
break;
default:
break;
}
set_options_widget(std::move(widget));
options_modulation.set_style(Theme::getInstance()->option_active);
}
void gfxEQView::on_frequency_step_changed(rf::Frequency f) {
receiver_model.set_frequency_step(f);
field_frequency.set_step(f);
@ -171,8 +146,9 @@ void gfxEQView::remove_options_widget() {
remove_child(options_widget.get());
options_widget.reset();
}
field_rf_amp.set_style(nullptr);
field_lna.set_style(nullptr);
options_modulation.set_style(nullptr);
field_vga.set_style(nullptr);
field_frequency.set_style(nullptr);
}
@ -188,7 +164,6 @@ void gfxEQView::set_options_widget(std::unique_ptr<Widget> new_widget) {
void gfxEQView::update_modulation(ReceiverModel::Mode modulation) {
audio::output::mute();
record_view.stop();
baseband::shutdown();
spi_flash::image_tag_t image_tag;
@ -219,22 +194,6 @@ void gfxEQView::update_modulation(ReceiverModel::Mode modulation) {
receiver_model.set_sampling_rate(3072000);
receiver_model.enable();
size_t record_sampling_rate = 0;
switch (modulation) {
case ReceiverModel::Mode::AMAudio:
record_sampling_rate = 12000;
break;
case ReceiverModel::Mode::NarrowbandFMAudio:
record_sampling_rate = 24000;
break;
case ReceiverModel::Mode::WidebandFMAudio:
record_sampling_rate = 48000;
break;
default:
break;
}
record_view.set_sampling_rate(record_sampling_rate);
if (modulation != ReceiverModel::Mode::SpectrumAnalysis) {
audio::output::unmute();
}

View File

@ -1,3 +1,11 @@
/*
* ------------------------------------------------------------
* | Made by RocketGod |
* | Find me at https://betaskynet.com |
* | Argh matey! |
* ------------------------------------------------------------
*/
#ifndef __UI_GFXEQ_HPP__
#define __UI_GFXEQ_HPP__
@ -7,7 +15,6 @@
#include "message.hpp"
#include "baseband_api.hpp"
#include "portapack.hpp"
#include "ui_record_view.hpp"
#include "ui_spectrum.hpp"
#include "ui_freq_field.hpp"
#include "app_settings.hpp"
@ -29,10 +36,10 @@ class gfxEQView : public View {
void paint(Painter& painter) override;
private:
static constexpr ui::Dim header_height = 3 * 16;
static constexpr ui::Dim header_height = 2 * 16;
static constexpr int SCREEN_WIDTH = 240;
static constexpr int SCREEN_HEIGHT = 320;
static constexpr int RENDER_HEIGHT = 280;
static constexpr int RENDER_HEIGHT = 288;
static constexpr int NUM_BARS = 16;
static constexpr int BAR_WIDTH = SCREEN_WIDTH / NUM_BARS;
static constexpr int BAR_SPACING = 2;
@ -71,44 +78,38 @@ 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{{5 * 8, 0 * 16}, nav_};
LNAGainField field_lna{Point{15 * 8, 0 * 16}};
VGAGainField field_vga{Point{18 * 8, 0 * 16}};
OptionsField options_modulation{
{0 * 8, 0 * 16},
4,
{{"AM ", toUType(ReceiverModel::Mode::AMAudio)},
{"NFM ", toUType(ReceiverModel::Mode::NarrowbandFMAudio)},
{"WFM ", toUType(ReceiverModel::Mode::WidebandFMAudio)},
{"SPEC", toUType(ReceiverModel::Mode::SpectrumAnalysis)}}};
AudioVolumeField field_volume{Point{28 * 8, 0 * 16}};
RxFrequencyField field_frequency{{0 * 8, 0 * 16}, nav_};
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}, ""};
RecordView record_view{
{0 * 8, 2 * 16, 30 * 8, 1 * 16},
u"AUD",
u"AUDIO",
RecordView::FileType::WAV,
4096,
4};
const Rect options_view_rect{0 * 8, 1 * 16, 30 * 8, 1 * 16};
std::unique_ptr<Widget> options_widget{};
Button button_mood{{21 * 8, 0, 6 * 8, 16}, "MOOD"};
Button dummy{{240, 0, 0, 0}, ""};
RxRadioState rx_radio_state_{};
app_settings::SettingsManager settings_{
"rx_gfx_eq"sv, app_settings::Mode::RX};
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};
SettingsStore ui_settings{"gfx_eq"sv, {}};
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}}};
void start();
void stop();
void update_audio_spectrum(const AudioSpectrum& spectrum);
void render_equalizer(Painter& painter);
void on_modulation_changed(ReceiverModel::Mode modulation);
void on_show_options_rf_gain();
void on_show_options_modulation();
void on_frequency_step_changed(rf::Frequency f);
void on_reference_ppm_correction_changed(int32_t v);
void remove_options_widget();