From 6782e12a1531f3266d4730421adcde506b0177eb Mon Sep 17 00:00:00 2001 From: Totoo Date: Fri, 17 Oct 2025 17:03:34 +0200 Subject: [PATCH] Fix morse tx cw+loop (#2827) --- .../external/morse_tx/ui_morse.cpp | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/firmware/application/external/morse_tx/ui_morse.cpp b/firmware/application/external/morse_tx/ui_morse.cpp index 054eee695..4b43d202a 100644 --- a/firmware/application/external/morse_tx/ui_morse.cpp +++ b/firmware/application/external/morse_tx/ui_morse.cpp @@ -45,12 +45,9 @@ static msg_t ookthread_fn(void* arg) { uint8_t* message_symbols = shared_memory.bb_data.tones_data.message; uint8_t symbol; MorseView* arg_c = (MorseView*)arg; - chRegSetThreadName("ookthread"); - for (uint32_t i = 0; i < arg_c->symbol_count; i++) { if (chThdShouldTerminate()) break; - symbol = message_symbols[i]; v = (symbol < 2) ? 1 : 0; // TX on for dot or dash, off for pause @@ -61,9 +58,7 @@ static msg_t ookthread_fn(void* arg) { } else { gpio_og_tx.write(v); // in hackrf <=r6, "1" means tx , "0" no tx. } - arg_c->on_tx_progress(i, false); - chThdSleepMilliseconds(delay * arg_c->time_unit_ms); } @@ -82,19 +77,14 @@ static msg_t ookthread_fn(void* arg) { static msg_t loopthread_fn(void* arg) { MorseView* arg_c = (MorseView*)arg; uint32_t wait = arg_c->loop; - chRegSetThreadName("loopthread"); - for (uint32_t i = 0; i < wait; i++) { if (chThdShouldTerminate()) break; - arg_c->on_loop_progress(i, false); chThdSleepMilliseconds(1000); } - - arg_c->on_loop_progress(0, true); + if (!chThdShouldTerminate()) arg_c->on_loop_progress(0, true); chThdExit(0); - return 0; } @@ -132,6 +122,15 @@ void MorseView::focus() { } MorseView::~MorseView() { + if (ookthread) { + chThdTerminate(ookthread); + ookthread = nullptr; + } + if (loopthread) { + chThdTerminate(loopthread); + chThdWait(loopthread); + loopthread = nullptr; + } transmitter_model.disable(); baseband::shutdown(); } @@ -181,6 +180,9 @@ void MorseView::update_tx_duration() { void MorseView::on_tx_progress(const uint32_t progress, const bool done) { if (done) { + if (ookthread) { + ookthread = nullptr; + } transmitter_model.disable(); progressbar.set_value(0); @@ -190,10 +192,10 @@ void MorseView::on_tx_progress(const uint32_t progress, const bool done) { progressbar.set_value(0); if (loopthread) { - chThdRelease(loopthread); + chThdTerminate(loopthread); + chThdWait(loopthread); loopthread = nullptr; } - loopthread = chThdCreateFromHeap(NULL, 1024, NORMALPRIO, loopthread_fn, this); } else { tx_view.set_transmitting(false); @@ -219,7 +221,6 @@ void MorseView::set_foxhunt(size_t i) { MorseView::MorseView( NavigationView& nav) : nav_(nav) { - // baseband::run_image(portapack::spi_flash::image_tag_tones); baseband::run_prepared_image(portapack::memory::map::m4_code.base()); add_children({&labels,