From 9e96715176781d4e9de0258f3a07d4e2962b30df Mon Sep 17 00:00:00 2001 From: Alien <2142224+mythic-alien@users.noreply.github.com> Date: Thu, 5 Jun 2025 15:21:44 +1000 Subject: [PATCH] Added ability to enter custom tone values in Morse app (#2679) * Added ability to enter custom tone values in Morse app Added the ability to type in a custom tone value in the morse TX app (issue#2582) *Click on the tone field to open a keyboard for entering in a desired value between 100hz - 9999hz. *Maintains original step value of 20 when scrolling the rotary wheel. * Update ui_morse.cpp Replaced std::to_string with to_string_dec_uint * Moved tone_input_buffer init to in-class --- .../external/morse_tx/ui_morse.cpp | 23 +++++++++++++++++++ .../external/morse_tx/ui_morse.hpp | 2 ++ 2 files changed, 25 insertions(+) diff --git a/firmware/application/external/morse_tx/ui_morse.cpp b/firmware/application/external/morse_tx/ui_morse.cpp index df7576511..66197f804 100644 --- a/firmware/application/external/morse_tx/ui_morse.cpp +++ b/firmware/application/external/morse_tx/ui_morse.cpp @@ -98,6 +98,25 @@ static msg_t loopthread_fn(void* arg) { return 0; } +void MorseView::on_set_tone(NavigationView& nav) { + tone_input_buffer = to_string_dec_uint(tone); + + text_prompt(nav, tone_input_buffer, 4, ENTER_KEYBOARD_MODE_DIGITS, [this](std::string& buffer) { + if (!buffer.empty() && std::all_of(buffer.begin(), buffer.end(), ::isdigit)) { + int new_tone = std::stoi(buffer); + if (new_tone >= 100 && new_tone <= 9999) { + tone = new_tone; + field_tone.set_value(tone); + update_tx_duration(); + } else { + nav_.display_modal("Out of range", "Tone must be between 100 and 9999 Hz"); + } + } else { + nav_.display_modal("Invalid input", "Please enter digits only"); + } + }); +} + void MorseView::on_set_text(NavigationView& nav) { text_prompt(nav, buffer, 28, ENTER_KEYBOARD_MODE_ALPHA); } @@ -250,6 +269,10 @@ MorseView::MorseView( tone = value; }; + field_tone.on_select = [this, &nav](NumberField&) { + this->on_set_tone(nav); + }; + button_message.on_select = [this, &nav](Button&) { this->on_set_text(nav); }; diff --git a/firmware/application/external/morse_tx/ui_morse.hpp b/firmware/application/external/morse_tx/ui_morse.hpp index 57da2cad7..fb54fcd7a 100644 --- a/firmware/application/external/morse_tx/ui_morse.hpp +++ b/firmware/application/external/morse_tx/ui_morse.hpp @@ -72,6 +72,7 @@ class MorseView : public View { NavigationView& nav_; std::string message{}; uint32_t time_units{0}; + std::string tone_input_buffer{}; // Holds the tone value while the text prompt is open TxRadioState radio_state_{ 0 /* frequency */, @@ -100,6 +101,7 @@ class MorseView : public View { bool start_tx(); void update_tx_duration(); + void on_set_tone(NavigationView& nav); void on_set_text(NavigationView& nav); void set_foxhunt(size_t i);