From 9dd41ed48d83169b7a2cb98881a7e94ddbcf4cc0 Mon Sep 17 00:00:00 2001 From: Clayton Smith Date: Sun, 26 Jul 2015 10:45:24 -0400 Subject: [PATCH] Add frequency correction (WIP). --- firmware/application/radio.cpp | 3 ++- firmware/application/ui_setup.cpp | 44 ++++++++++++++++++++++++++++++- firmware/application/ui_setup.hpp | 44 +++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 2 deletions(-) diff --git a/firmware/application/radio.cpp b/firmware/application/radio.cpp index d102f9fe..d85cab2d 100644 --- a/firmware/application/radio.cpp +++ b/firmware/application/radio.cpp @@ -117,7 +117,8 @@ void set_direction(const rf::Direction new_direction) { } bool set_tuning_frequency(const rf::Frequency frequency) { - const auto tuning_config = tuning::config::create(frequency); + rf::Frequency corrected_frequency = frequency * (1000000 - 10) / 1000000; + const auto tuning_config = tuning::config::create(corrected_frequency); if( tuning_config.is_valid() ) { first_if.disable(); diff --git a/firmware/application/ui_setup.cpp b/firmware/application/ui_setup.cpp index b62bb0cc..f9757822 100644 --- a/firmware/application/ui_setup.cpp +++ b/firmware/application/ui_setup.cpp @@ -98,6 +98,47 @@ SetDateTimeModel SetDateTimeView::form_collect() { }; } +SetFrequencyCorrectionView::SetFrequencyCorrectionView( + NavigationView& nav +) { + button_ok.on_select = [&nav, this](Button&){ + const auto model = this->form_collect(); + nav.pop(); + }, + + button_cancel.on_select = [&nav](Button&){ + nav.pop(); + }, + + add_children({ { + &text_title, + &field_ppm, + &text_ppm, + &button_ok, + &button_cancel, + } }); + + SetFrequencyCorrectionModel model { + 0 + }; + + form_init(model); +} + +void SetFrequencyCorrectionView::focus() { + button_cancel.focus(); +} + +void SetFrequencyCorrectionView::form_init(const SetFrequencyCorrectionModel model) { + field_ppm.set_value(model.ppm); +} + +SetFrequencyCorrectionModel SetFrequencyCorrectionView::form_collect() { + return { + .ppm = static_cast(field_ppm.value()), + }; +} + AboutView::AboutView(NavigationView& nav) { add_children({ { &text_title, @@ -115,8 +156,9 @@ void AboutView::focus() { } SetupMenuView::SetupMenuView(NavigationView& nav) { - add_items<2>({ { + add_items<3>({ { { "Date/Time", [&nav](){ nav.push(new SetDateTimeView { nav }); } }, + { "Frequency Correction", [&nav](){ nav.push(new SetFrequencyCorrectionView { nav }); } }, { "Touch", [&nav](){ nav.push(new NotImplementedView { nav }); } }, } }); on_left = [&nav](){ nav.pop(); }; diff --git a/firmware/application/ui_setup.hpp b/firmware/application/ui_setup.hpp index f7351490..b2f975bd 100644 --- a/firmware/application/ui_setup.hpp +++ b/firmware/application/ui_setup.hpp @@ -132,6 +132,50 @@ private: SetDateTimeModel form_collect(); }; +struct SetFrequencyCorrectionModel { + int8_t ppm; +}; + +class SetFrequencyCorrectionView : public View { +public: + std::function on_ok; + std::function on_cancel; + + SetFrequencyCorrectionView(NavigationView& nav); + + void focus() override; + +private: + Text text_title { + { 5 * 8, 7 * 16, 20 * 8, 16 }, + "Frequency Correction" + }; + + NumberField field_ppm { + { 11 * 8, 9 * 16 }, + 3, + { -50, 50 }, + 1, + '0', + }; + Text text_ppm { + { 15 * 8, 9 * 16, 3 * 8, 16 }, + "PPM", + }; + + Button button_ok { + { 4 * 8, 13 * 16, 8 * 8, 24 }, + "OK", + }; + Button button_cancel { + { 18 * 8, 13 * 16, 8 * 8, 24 }, + "Cancel", + }; + + void form_init(const SetFrequencyCorrectionModel model); + SetFrequencyCorrectionModel form_collect(); +}; + class AboutView : public View { public: AboutView(NavigationView& nav);