From 7bc27038bea05b85f2c4581818a3e2ec42fa5197 Mon Sep 17 00:00:00 2001 From: Mark Thompson <129641948+NotherNgineer@users.noreply.github.com> Date: Sun, 26 Nov 2023 05:17:23 -0600 Subject: [PATCH] Save Morse app settings (#1602) --- firmware/application/apps/ui_morse.cpp | 50 +++++++++++++++----------- firmware/application/apps/ui_morse.hpp | 49 ++++++++++++------------- 2 files changed, 55 insertions(+), 44 deletions(-) diff --git a/firmware/application/apps/ui_morse.cpp b/firmware/application/apps/ui_morse.cpp index b53e502e..de6a7fe1 100644 --- a/firmware/application/apps/ui_morse.cpp +++ b/firmware/application/apps/ui_morse.cpp @@ -131,9 +131,9 @@ bool MorseView::start_tx() { transmitter_model.set_baseband_bandwidth(1'750'000); // Min TX LPF .already tested in FM morse max tone 9,999k , max dev 150khz transmitter_model.enable(); - if (modulation == CW) { + if (mode_cw) { ookthread = chThdCreateStatic(ookthread_wa, sizeof(ookthread_wa), NORMALPRIO + 10, ookthread_fn, this); - } else if (modulation == FM) { + } else { baseband::set_tones_config(transmitter_model.channel_bandwidth(), 0, symbol_count, false, false); } @@ -143,8 +143,8 @@ bool MorseView::start_tx() { void MorseView::update_tx_duration() { uint32_t duration_ms; - time_unit_ms = 1200 / field_speed.value(); - symbol_count = morse_encode(message, time_unit_ms, field_tone.value(), &time_units); + time_unit_ms = 1200 / speed; + symbol_count = morse_encode(message, time_unit_ms, tone, &time_units); if (symbol_count) { duration_ms = time_units * time_unit_ms; @@ -185,7 +185,7 @@ void MorseView::on_loop_progress(const uint32_t progress, const bool done) { } void MorseView::set_foxhunt(size_t i) { - message = foxhunt_codes[i]; + message = foxhunt_codes[i - 1]; buffer = message.c_str(); text_message.set(message); update_tx_duration(); @@ -198,7 +198,7 @@ MorseView::MorseView( add_children({&labels, &checkbox_foxhunt, - &options_foxhunt, + &field_foxhunt, &field_speed, &field_tone, &options_modulation, @@ -210,36 +210,46 @@ MorseView::MorseView( &tx_view}); // Default settings - field_speed.set_value(15); // 15wps - field_tone.set_value(700); // 700Hz FM tone - options_modulation.set_selected_index(0); // CW mode - options_loop.set_selected_index(0); // Off + field_speed.set_value(speed); + field_tone.set_value(tone); + options_modulation.set_by_value(mode_cw); + options_loop.set_by_value(loop); + checkbox_foxhunt.set_value(foxhunt_mode); + field_foxhunt.set_value(foxhunt_code); checkbox_foxhunt.on_select = [this](Checkbox&, bool value) { foxhunt_mode = value; if (foxhunt_mode) - set_foxhunt(options_foxhunt.selected_index_value()); + set_foxhunt(foxhunt_code); }; - options_foxhunt.on_change = [this](size_t i, int32_t) { + field_foxhunt.on_change = [this](int32_t value) { + foxhunt_code = value; + if (foxhunt_mode) - set_foxhunt(i); + set_foxhunt(foxhunt_code); }; - options_modulation.on_change = [this](size_t i, int32_t) { - modulation = (modulation_t)i; - }; - - options_loop.on_change = [this](size_t i, uint32_t n) { + options_modulation.on_change = [this](size_t i, int32_t value) { (void)i; // avoid unused warning - loop = n; + mode_cw = (bool)value; }; - field_speed.on_change = [this](int32_t) { + options_loop.on_change = [this](size_t i, uint32_t value) { + (void)i; // avoid unused warning + loop = value; + }; + + field_speed.on_change = [this](int32_t value) { + speed = value; update_tx_duration(); }; + field_tone.on_change = [this](int32_t value) { + tone = value; + }; + button_message.on_select = [this, &nav](Button&) { this->on_set_text(nav); }; diff --git a/firmware/application/apps/ui_morse.hpp b/firmware/application/apps/ui_morse.hpp index c9fdcd98..9f9d4d02 100644 --- a/firmware/application/apps/ui_morse.hpp +++ b/firmware/application/apps/ui_morse.hpp @@ -65,7 +65,6 @@ class MorseView : public View { private: NavigationView& nav_; - std::string buffer{"PORTAPACK"}; std::string message{}; uint32_t time_units{0}; @@ -74,14 +73,25 @@ class MorseView : public View { 1750000 /* bandwidth */, 1536000 /* sampling rate */ }; - app_settings::SettingsManager settings_{ - "tx_morse", app_settings::Mode::TX}; - enum modulation_t { - CW = 0, - FM = 1 - }; - modulation_t modulation{CW}; + std::string buffer{"PORTAPACK"}; + bool mode_cw{true}; + bool foxhunt_mode{false}; + uint32_t foxhunt_code{1}; + uint32_t speed{15}; + uint32_t tone{700}; + app_settings::SettingsManager settings_{ + "tx_morse", + app_settings::Mode::TX, + { + {"message"sv, &buffer}, + {"foxhunt"sv, &foxhunt_mode}, + {"foxhunt_code"sv, &foxhunt_code}, + {"speed"sv, &speed}, + {"tone"sv, &tone}, + {"mode_cw"sv, &mode_cw}, + {"loop"sv, &loop}, + }}; bool start_tx(); void update_tx_duration(); @@ -90,7 +100,6 @@ class MorseView : public View { Thread* ookthread{nullptr}; Thread* loopthread{nullptr}; - bool foxhunt_mode{false}; bool run{false}; Labels labels{ @@ -104,20 +113,12 @@ class MorseView : public View { {4 * 8, 16}, 8, "Foxhunt:"}; - OptionsField options_foxhunt{ + NumberField field_foxhunt{ {17 * 8, 16 + 4}, - 7, - {{"1 (MOE)", 0}, - {"2 (MOI)", 1}, - {"3 (MOS)", 2}, - {"4 (MOH)", 3}, - {"5 (MO5)", 4}, - {"6 (MON)", 5}, - {"7 (MOD)", 6}, - {"8 (MOB)", 7}, - {"9 (MO6)", 8}, - {"X (MO) ", 9}, - {"T (S) ", 10}}}; + 2, + {1, 11}, + 1, + ' '}; NumberField field_speed{ {10 * 8, 6 * 8}, @@ -136,8 +137,8 @@ class MorseView : public View { OptionsField options_modulation{ {15 * 8, 10 * 8}, 2, - {{"CW", 0}, - {"FM", 1}}}; + {{"CW", true}, + {"FM", false}}}; OptionsField options_loop{ {9 * 8, 12 * 8},