Spectrum Width and Speed Settings

This commit is contained in:
Белоусов Олег 2020-07-31 13:47:40 +03:00
parent f21e26eaa3
commit 6f58c7929a
2 changed files with 106 additions and 5 deletions

View File

@ -36,6 +36,8 @@ using namespace tonekey;
#include "string_format.hpp" #include "string_format.hpp"
#define SPEC 2000000
namespace ui { namespace ui {
/* AMOptionsView *********************************************************/ /* AMOptionsView *********************************************************/
@ -83,6 +85,32 @@ NBFMOptionsView::NBFMOptionsView(
}; };
} }
/* SPECOptionsView *******************************************************/
SPECOptionsView::SPECOptionsView(
AnalogAudioView* view, const Rect parent_rect, const Style* const style
) : View { parent_rect }
{
set_style(style);
add_children({
&label_config,
&options_config,
&text_speed,
&field_speed
});
options_config.set_selected_index(view->get_spec_bw_index());
options_config.on_change = [this, view](size_t n, OptionsField::value_t bw) {
view->set_spec_bw(n, bw);
};
field_speed.set_value(view->get_spec_trigger());
field_speed.on_change = [this, view](int32_t v) {
view->set_spec_trigger(v);
};
}
/* AnalogAudioView *******************************************************/ /* AnalogAudioView *******************************************************/
AnalogAudioView::AnalogAudioView( AnalogAudioView::AnalogAudioView(
@ -157,6 +185,29 @@ AnalogAudioView::AnalogAudioView(
on_modulation_changed(static_cast<ReceiverModel::Mode>(modulation)); on_modulation_changed(static_cast<ReceiverModel::Mode>(modulation));
} }
size_t AnalogAudioView::get_spec_bw_index() {
return spec_bw_index;
}
void AnalogAudioView::set_spec_bw(size_t index, uint32_t bw) {
spec_bw_index = index;
spec_bw = bw;
baseband::set_spectrum(bw, spec_trigger);
receiver_model.set_sampling_rate(bw);
receiver_model.set_baseband_bandwidth(bw/2);
}
uint16_t AnalogAudioView::get_spec_trigger() {
return spec_trigger;
}
void AnalogAudioView::set_spec_trigger(uint16_t trigger) {
spec_trigger = trigger;
baseband::set_spectrum(spec_bw, spec_trigger);
}
AnalogAudioView::~AnalogAudioView() { AnalogAudioView::~AnalogAudioView() {
// TODO: Manipulating audio codec here, and in ui_receiver.cpp. Good to do // TODO: Manipulating audio codec here, and in ui_receiver.cpp. Good to do
// both? // both?
@ -272,6 +323,7 @@ void AnalogAudioView::on_show_options_modulation() {
break; break;
case ReceiverModel::Mode::SpectrumAnalysis: case ReceiverModel::Mode::SpectrumAnalysis:
widget = std::make_unique<SPECOptionsView>(this, nbfm_view_rect, &style_options_group);
waterfall.show_audio_spectrum_view(false); waterfall.show_audio_spectrum_view(false);
text_ctcss.hidden(true); text_ctcss.hidden(true);
break; break;
@ -317,13 +369,15 @@ void AnalogAudioView::update_modulation(const ReceiverModel::Mode modulation) {
baseband::run_image(image_tag); baseband::run_image(image_tag);
if (modulation == ReceiverModel::Mode::SpectrumAnalysis) { if (modulation == ReceiverModel::Mode::SpectrumAnalysis) {
baseband::set_spectrum(20000000, 127); baseband::set_spectrum(spec_bw, spec_trigger);
} }
const auto is_wideband_spectrum_mode = (modulation == ReceiverModel::Mode::SpectrumAnalysis); const auto is_wideband_spectrum_mode = (modulation == ReceiverModel::Mode::SpectrumAnalysis);
receiver_model.set_modulation(modulation); receiver_model.set_modulation(modulation);
receiver_model.set_sampling_rate(is_wideband_spectrum_mode ? 20000000 : 3072000);
receiver_model.set_baseband_bandwidth(is_wideband_spectrum_mode ? 12000000 : 1750000); receiver_model.set_sampling_rate(is_wideband_spectrum_mode ? spec_bw : 3072000);
receiver_model.set_baseband_bandwidth(is_wideband_spectrum_mode ? spec_bw/2 : 1750000);
receiver_model.enable(); receiver_model.enable();
// TODO: This doesn't belong here! There's a better way. // TODO: This doesn't belong here! There's a better way.

View File

@ -94,6 +94,43 @@ private:
}; };
}; };
class AnalogAudioView;
class SPECOptionsView : public View {
public:
SPECOptionsView(AnalogAudioView* view, const Rect parent_rect, const Style* const style);
private:
Text label_config {
{ 0 * 8, 0 * 16, 2 * 8, 1 * 16 },
"BW",
};
OptionsField options_config {
{ 3 * 8, 0 * 16 },
4,
{
{ "20m ", 20000000 },
{ "10m ", 10000000 },
{ " 5m ", 5000000 },
{ " 2m ", 2000000 },
{ " 1m ", 1000000 },
{ "500k", 500000 },
}
};
Text text_speed {
{ 9 * 8, 0 * 16, 8 * 8, 1 * 16 },
"SP /63"
};
NumberField field_speed {
{ 12 * 8, 0 * 16 },
2,
{ 0, 63 },
1,
' ',
};
};
class AnalogAudioView : public View { class AnalogAudioView : public View {
public: public:
AnalogAudioView(NavigationView& nav); AnalogAudioView(NavigationView& nav);
@ -107,12 +144,22 @@ public:
std::string title() const override { return "Analog audio"; }; std::string title() const override { return "Analog audio"; };
size_t get_spec_bw_index();
void set_spec_bw(size_t index, uint32_t bw);
uint16_t get_spec_trigger();
void set_spec_trigger(uint16_t trigger);
private: private:
static constexpr ui::Dim header_height = 3 * 16; static constexpr ui::Dim header_height = 3 * 16;
const Rect options_view_rect { 0 * 8, 1 * 16, 30 * 8, 1 * 16 }; const Rect options_view_rect { 0 * 8, 1 * 16, 30 * 8, 1 * 16 };
const Rect nbfm_view_rect { 0 * 8, 1 * 16, 18 * 8, 1 * 16 }; const Rect nbfm_view_rect { 0 * 8, 1 * 16, 18 * 8, 1 * 16 };
size_t spec_bw_index = 0;
uint32_t spec_bw = 20000000;
uint16_t spec_trigger = 63;
NavigationView& nav_; NavigationView& nav_;
//bool exit_on_squelch { false }; //bool exit_on_squelch { false };