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
This commit is contained in:
Alien
2025-06-05 15:21:44 +10:00
committed by GitHub
parent fecfe8b8fc
commit 9e96715176
2 changed files with 25 additions and 0 deletions

View File

@@ -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);
};

View File

@@ -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);