Save Morse app settings (#1602)

This commit is contained in:
Mark Thompson 2023-11-26 05:17:23 -06:00 committed by GitHub
parent 609bf3219f
commit 7bc27038be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 44 deletions

View File

@ -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.set_baseband_bandwidth(1'750'000); // Min TX LPF .already tested in FM morse max tone 9,999k , max dev 150khz
transmitter_model.enable(); transmitter_model.enable();
if (modulation == CW) { if (mode_cw) {
ookthread = chThdCreateStatic(ookthread_wa, sizeof(ookthread_wa), NORMALPRIO + 10, ookthread_fn, this); 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); 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() { void MorseView::update_tx_duration() {
uint32_t duration_ms; uint32_t duration_ms;
time_unit_ms = 1200 / field_speed.value(); time_unit_ms = 1200 / speed;
symbol_count = morse_encode(message, time_unit_ms, field_tone.value(), &time_units); symbol_count = morse_encode(message, time_unit_ms, tone, &time_units);
if (symbol_count) { if (symbol_count) {
duration_ms = time_units * time_unit_ms; 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) { void MorseView::set_foxhunt(size_t i) {
message = foxhunt_codes[i]; message = foxhunt_codes[i - 1];
buffer = message.c_str(); buffer = message.c_str();
text_message.set(message); text_message.set(message);
update_tx_duration(); update_tx_duration();
@ -198,7 +198,7 @@ MorseView::MorseView(
add_children({&labels, add_children({&labels,
&checkbox_foxhunt, &checkbox_foxhunt,
&options_foxhunt, &field_foxhunt,
&field_speed, &field_speed,
&field_tone, &field_tone,
&options_modulation, &options_modulation,
@ -210,36 +210,46 @@ MorseView::MorseView(
&tx_view}); &tx_view});
// Default settings // Default settings
field_speed.set_value(15); // 15wps field_speed.set_value(speed);
field_tone.set_value(700); // 700Hz FM tone field_tone.set_value(tone);
options_modulation.set_selected_index(0); // CW mode options_modulation.set_by_value(mode_cw);
options_loop.set_selected_index(0); // Off 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) { checkbox_foxhunt.on_select = [this](Checkbox&, bool value) {
foxhunt_mode = value; foxhunt_mode = value;
if (foxhunt_mode) 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) if (foxhunt_mode)
set_foxhunt(i); set_foxhunt(foxhunt_code);
}; };
options_modulation.on_change = [this](size_t i, int32_t) { options_modulation.on_change = [this](size_t i, int32_t value) {
modulation = (modulation_t)i;
};
options_loop.on_change = [this](size_t i, uint32_t n) {
(void)i; // avoid unused warning (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(); update_tx_duration();
}; };
field_tone.on_change = [this](int32_t value) {
tone = value;
};
button_message.on_select = [this, &nav](Button&) { button_message.on_select = [this, &nav](Button&) {
this->on_set_text(nav); this->on_set_text(nav);
}; };

View File

@ -65,7 +65,6 @@ class MorseView : public View {
private: private:
NavigationView& nav_; NavigationView& nav_;
std::string buffer{"PORTAPACK"};
std::string message{}; std::string message{};
uint32_t time_units{0}; uint32_t time_units{0};
@ -74,14 +73,25 @@ class MorseView : public View {
1750000 /* bandwidth */, 1750000 /* bandwidth */,
1536000 /* sampling rate */ 1536000 /* sampling rate */
}; };
app_settings::SettingsManager settings_{
"tx_morse", app_settings::Mode::TX};
enum modulation_t { std::string buffer{"PORTAPACK"};
CW = 0, bool mode_cw{true};
FM = 1 bool foxhunt_mode{false};
}; uint32_t foxhunt_code{1};
modulation_t modulation{CW}; 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(); bool start_tx();
void update_tx_duration(); void update_tx_duration();
@ -90,7 +100,6 @@ class MorseView : public View {
Thread* ookthread{nullptr}; Thread* ookthread{nullptr};
Thread* loopthread{nullptr}; Thread* loopthread{nullptr};
bool foxhunt_mode{false};
bool run{false}; bool run{false};
Labels labels{ Labels labels{
@ -104,20 +113,12 @@ class MorseView : public View {
{4 * 8, 16}, {4 * 8, 16},
8, 8,
"Foxhunt:"}; "Foxhunt:"};
OptionsField options_foxhunt{ NumberField field_foxhunt{
{17 * 8, 16 + 4}, {17 * 8, 16 + 4},
7, 2,
{{"1 (MOE)", 0}, {1, 11},
{"2 (MOI)", 1}, 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}}};
NumberField field_speed{ NumberField field_speed{
{10 * 8, 6 * 8}, {10 * 8, 6 * 8},
@ -136,8 +137,8 @@ class MorseView : public View {
OptionsField options_modulation{ OptionsField options_modulation{
{15 * 8, 10 * 8}, {15 * 8, 10 * 8},
2, 2,
{{"CW", 0}, {{"CW", true},
{"FM", 1}}}; {"FM", false}}};
OptionsField options_loop{ OptionsField options_loop{
{9 * 8, 12 * 8}, {9 * 8, 12 * 8},